AWS CloudFormation
User Guide (Version )

AWS::Logs::MetricFilter

The AWS::Logs::MetricFilter resource specifies a metric filter that describes how CloudWatch Logs extracts information from logs and transforms it into Amazon CloudWatch metrics. If you have multiple metric filters that are associated with a log group, all the filters are applied to the log streams in that group.

The maximum number of metric filters that can be associated with a log group is 100.

Syntax

To declare this entity in your AWS CloudFormation template, use the following syntax:

JSON

{ "Type" : "AWS::Logs::MetricFilter", "Properties" : { "FilterPattern" : String, "LogGroupName" : String, "MetricTransformations" : [ MetricTransformation, ... ] } }

YAML

Type: AWS::Logs::MetricFilter Properties: FilterPattern: String LogGroupName: String MetricTransformations: - MetricTransformation

Properties

FilterPattern

A filter pattern for extracting metric data out of ingested log events.

Required: Yes

Type: String

Update requires: No interruption

LogGroupName

The name of an existing log group that you want to associate with this metric filter.

Required: Yes

Type: String

Minimum: 1

Maximum: 512

Pattern: [\.\-_/#A-Za-z0-9]+

Update requires: Replacement

MetricTransformations

The metric transformations.

Required: Yes

Type: List of MetricTransformation

Maximum: 1

Update requires: No interruption

Examples

Create a Metric Filter

The following example sends a value of 1 to the 404Count metric whenever the status code field includes a 404 value.

JSON

"404MetricFilter": { "Type": "AWS::Logs::MetricFilter", "Properties": { "LogGroupName": { "Ref": "myLogGroup" }, "FilterPattern": "[ip, identity, user_id, timestamp, request, status_code = 404, size]", "MetricTransformations": [ { "MetricValue": "1", "MetricNamespace": "WebServer/404s", "MetricName": "404Count" } ] } }

YAML

404MetricFilter: Type: AWS::Logs::MetricFilter Properties: LogGroupName: Ref: "myLogGroup" FilterPattern: "[ip, identity, user_id, timestamp, request, status_code = 404, size]" MetricTransformations: - MetricValue: "1" MetricNamespace: "WebServer/404s" MetricName: "404Count"

On this page: