AWS::Logs::MetricFilter - Amazon CloudFormation
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

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 Amazon CloudFormation template, use the following syntax:

JSON

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

YAML

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

Properties

FilterName

The name of the metric filter.

Required: No

Type: String

Pattern: ^[^:*]{1,512}

Minimum: 1

Maximum: 512

Update requires: Replacement

FilterPattern

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

Required: Yes

Type: String

Maximum: 1024

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

Pattern: ^[.\-_/#A-Za-z0-9]{1,512}

Minimum: 1

Maximum: 512

Update requires: Replacement

MetricTransformations

The metric transformations.

Required: Yes

Type: Array of MetricTransformation

Minimum: 1

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"