AWS::Logs::MetricFilter - AWS CloudFormation


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.


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


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


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



A filter pattern for extracting metric data out of ingested log events. For more information, see Filter and Pattern Syntax.

Required: Yes

Type: String

Update requires: No interruption


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


The metric transformations.

Required: Yes

Type: List of MetricTransformation

Maximum: 1

Update requires: No interruption


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.


"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" } ] } }


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"