1. Packages
  2. AWS
  3. API Docs
  4. cloudwatch
  5. LogMetricFilter
AWS v6.77.0 published on Wednesday, Apr 9, 2025 by Pulumi

aws.cloudwatch.LogMetricFilter

Explore with Pulumi AI

Provides a CloudWatch Log Metric Filter resource.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const dada = new aws.cloudwatch.LogGroup("dada", {name: "MyApp/access.log"});
const yada = new aws.cloudwatch.LogMetricFilter("yada", {
    name: "MyAppAccessCount",
    pattern: "",
    logGroupName: dada.name,
    metricTransformation: {
        name: "EventCount",
        namespace: "YourNamespace",
        value: "1",
    },
});
Copy
import pulumi
import pulumi_aws as aws

dada = aws.cloudwatch.LogGroup("dada", name="MyApp/access.log")
yada = aws.cloudwatch.LogMetricFilter("yada",
    name="MyAppAccessCount",
    pattern="",
    log_group_name=dada.name,
    metric_transformation={
        "name": "EventCount",
        "namespace": "YourNamespace",
        "value": "1",
    })
Copy
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/cloudwatch"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		dada, err := cloudwatch.NewLogGroup(ctx, "dada", &cloudwatch.LogGroupArgs{
			Name: pulumi.String("MyApp/access.log"),
		})
		if err != nil {
			return err
		}
		_, err = cloudwatch.NewLogMetricFilter(ctx, "yada", &cloudwatch.LogMetricFilterArgs{
			Name:         pulumi.String("MyAppAccessCount"),
			Pattern:      pulumi.String(""),
			LogGroupName: dada.Name,
			MetricTransformation: &cloudwatch.LogMetricFilterMetricTransformationArgs{
				Name:      pulumi.String("EventCount"),
				Namespace: pulumi.String("YourNamespace"),
				Value:     pulumi.String("1"),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() => 
{
    var dada = new Aws.CloudWatch.LogGroup("dada", new()
    {
        Name = "MyApp/access.log",
    });

    var yada = new Aws.CloudWatch.LogMetricFilter("yada", new()
    {
        Name = "MyAppAccessCount",
        Pattern = "",
        LogGroupName = dada.Name,
        MetricTransformation = new Aws.CloudWatch.Inputs.LogMetricFilterMetricTransformationArgs
        {
            Name = "EventCount",
            Namespace = "YourNamespace",
            Value = "1",
        },
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.cloudwatch.LogGroup;
import com.pulumi.aws.cloudwatch.LogGroupArgs;
import com.pulumi.aws.cloudwatch.LogMetricFilter;
import com.pulumi.aws.cloudwatch.LogMetricFilterArgs;
import com.pulumi.aws.cloudwatch.inputs.LogMetricFilterMetricTransformationArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var dada = new LogGroup("dada", LogGroupArgs.builder()
            .name("MyApp/access.log")
            .build());

        var yada = new LogMetricFilter("yada", LogMetricFilterArgs.builder()
            .name("MyAppAccessCount")
            .pattern("")
            .logGroupName(dada.name())
            .metricTransformation(LogMetricFilterMetricTransformationArgs.builder()
                .name("EventCount")
                .namespace("YourNamespace")
                .value("1")
                .build())
            .build());

    }
}
Copy
resources:
  yada:
    type: aws:cloudwatch:LogMetricFilter
    properties:
      name: MyAppAccessCount
      pattern: ""
      logGroupName: ${dada.name}
      metricTransformation:
        name: EventCount
        namespace: YourNamespace
        value: '1'
  dada:
    type: aws:cloudwatch:LogGroup
    properties:
      name: MyApp/access.log
Copy

Create LogMetricFilter Resource

Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

Constructor syntax

new LogMetricFilter(name: string, args: LogMetricFilterArgs, opts?: CustomResourceOptions);
@overload
def LogMetricFilter(resource_name: str,
                    args: LogMetricFilterArgs,
                    opts: Optional[ResourceOptions] = None)

@overload
def LogMetricFilter(resource_name: str,
                    opts: Optional[ResourceOptions] = None,
                    log_group_name: Optional[str] = None,
                    metric_transformation: Optional[LogMetricFilterMetricTransformationArgs] = None,
                    pattern: Optional[str] = None,
                    name: Optional[str] = None)
func NewLogMetricFilter(ctx *Context, name string, args LogMetricFilterArgs, opts ...ResourceOption) (*LogMetricFilter, error)
public LogMetricFilter(string name, LogMetricFilterArgs args, CustomResourceOptions? opts = null)
public LogMetricFilter(String name, LogMetricFilterArgs args)
public LogMetricFilter(String name, LogMetricFilterArgs args, CustomResourceOptions options)
type: aws:cloudwatch:LogMetricFilter
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. LogMetricFilterArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. LogMetricFilterArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args This property is required. LogMetricFilterArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. LogMetricFilterArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. LogMetricFilterArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

Constructor example

The following reference example uses placeholder values for all input properties.

var logMetricFilterResource = new Aws.CloudWatch.LogMetricFilter("logMetricFilterResource", new()
{
    LogGroupName = "string",
    MetricTransformation = new Aws.CloudWatch.Inputs.LogMetricFilterMetricTransformationArgs
    {
        Name = "string",
        Namespace = "string",
        Value = "string",
        DefaultValue = "string",
        Dimensions = 
        {
            { "string", "string" },
        },
        Unit = "string",
    },
    Pattern = "string",
    Name = "string",
});
Copy
example, err := cloudwatch.NewLogMetricFilter(ctx, "logMetricFilterResource", &cloudwatch.LogMetricFilterArgs{
	LogGroupName: pulumi.String("string"),
	MetricTransformation: &cloudwatch.LogMetricFilterMetricTransformationArgs{
		Name:         pulumi.String("string"),
		Namespace:    pulumi.String("string"),
		Value:        pulumi.String("string"),
		DefaultValue: pulumi.String("string"),
		Dimensions: pulumi.StringMap{
			"string": pulumi.String("string"),
		},
		Unit: pulumi.String("string"),
	},
	Pattern: pulumi.String("string"),
	Name:    pulumi.String("string"),
})
Copy
var logMetricFilterResource = new LogMetricFilter("logMetricFilterResource", LogMetricFilterArgs.builder()
    .logGroupName("string")
    .metricTransformation(LogMetricFilterMetricTransformationArgs.builder()
        .name("string")
        .namespace("string")
        .value("string")
        .defaultValue("string")
        .dimensions(Map.of("string", "string"))
        .unit("string")
        .build())
    .pattern("string")
    .name("string")
    .build());
Copy
log_metric_filter_resource = aws.cloudwatch.LogMetricFilter("logMetricFilterResource",
    log_group_name="string",
    metric_transformation={
        "name": "string",
        "namespace": "string",
        "value": "string",
        "default_value": "string",
        "dimensions": {
            "string": "string",
        },
        "unit": "string",
    },
    pattern="string",
    name="string")
Copy
const logMetricFilterResource = new aws.cloudwatch.LogMetricFilter("logMetricFilterResource", {
    logGroupName: "string",
    metricTransformation: {
        name: "string",
        namespace: "string",
        value: "string",
        defaultValue: "string",
        dimensions: {
            string: "string",
        },
        unit: "string",
    },
    pattern: "string",
    name: "string",
});
Copy
type: aws:cloudwatch:LogMetricFilter
properties:
    logGroupName: string
    metricTransformation:
        defaultValue: string
        dimensions:
            string: string
        name: string
        namespace: string
        unit: string
        value: string
    name: string
    pattern: string
Copy

LogMetricFilter Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

The LogMetricFilter resource accepts the following input properties:

LogGroupName
This property is required.
Changes to this property will trigger replacement.
string
The name of the log group to associate the metric filter with.
MetricTransformation This property is required. LogMetricFilterMetricTransformation
A block defining collection of information needed to define how metric data gets emitted. See below.
Pattern This property is required. string
A valid CloudWatch Logs filter pattern for extracting metric data out of ingested log events.
Name Changes to this property will trigger replacement. string
A name for the metric filter.
LogGroupName
This property is required.
Changes to this property will trigger replacement.
string
The name of the log group to associate the metric filter with.
MetricTransformation This property is required. LogMetricFilterMetricTransformationArgs
A block defining collection of information needed to define how metric data gets emitted. See below.
Pattern This property is required. string
A valid CloudWatch Logs filter pattern for extracting metric data out of ingested log events.
Name Changes to this property will trigger replacement. string
A name for the metric filter.
logGroupName
This property is required.
Changes to this property will trigger replacement.
String
The name of the log group to associate the metric filter with.
metricTransformation This property is required. LogMetricFilterMetricTransformation
A block defining collection of information needed to define how metric data gets emitted. See below.
pattern This property is required. String
A valid CloudWatch Logs filter pattern for extracting metric data out of ingested log events.
name Changes to this property will trigger replacement. String
A name for the metric filter.
logGroupName
This property is required.
Changes to this property will trigger replacement.
string
The name of the log group to associate the metric filter with.
metricTransformation This property is required. LogMetricFilterMetricTransformation
A block defining collection of information needed to define how metric data gets emitted. See below.
pattern This property is required. string
A valid CloudWatch Logs filter pattern for extracting metric data out of ingested log events.
name Changes to this property will trigger replacement. string
A name for the metric filter.
log_group_name
This property is required.
Changes to this property will trigger replacement.
str
The name of the log group to associate the metric filter with.
metric_transformation This property is required. LogMetricFilterMetricTransformationArgs
A block defining collection of information needed to define how metric data gets emitted. See below.
pattern This property is required. str
A valid CloudWatch Logs filter pattern for extracting metric data out of ingested log events.
name Changes to this property will trigger replacement. str
A name for the metric filter.
logGroupName
This property is required.
Changes to this property will trigger replacement.
String
The name of the log group to associate the metric filter with.
metricTransformation This property is required. Property Map
A block defining collection of information needed to define how metric data gets emitted. See below.
pattern This property is required. String
A valid CloudWatch Logs filter pattern for extracting metric data out of ingested log events.
name Changes to this property will trigger replacement. String
A name for the metric filter.

Outputs

All input properties are implicitly available as output properties. Additionally, the LogMetricFilter resource produces the following output properties:

Id string
The provider-assigned unique ID for this managed resource.
Id string
The provider-assigned unique ID for this managed resource.
id String
The provider-assigned unique ID for this managed resource.
id string
The provider-assigned unique ID for this managed resource.
id str
The provider-assigned unique ID for this managed resource.
id String
The provider-assigned unique ID for this managed resource.

Look up Existing LogMetricFilter Resource

Get an existing LogMetricFilter resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: LogMetricFilterState, opts?: CustomResourceOptions): LogMetricFilter
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        log_group_name: Optional[str] = None,
        metric_transformation: Optional[LogMetricFilterMetricTransformationArgs] = None,
        name: Optional[str] = None,
        pattern: Optional[str] = None) -> LogMetricFilter
func GetLogMetricFilter(ctx *Context, name string, id IDInput, state *LogMetricFilterState, opts ...ResourceOption) (*LogMetricFilter, error)
public static LogMetricFilter Get(string name, Input<string> id, LogMetricFilterState? state, CustomResourceOptions? opts = null)
public static LogMetricFilter get(String name, Output<String> id, LogMetricFilterState state, CustomResourceOptions options)
resources:  _:    type: aws:cloudwatch:LogMetricFilter    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
LogGroupName Changes to this property will trigger replacement. string
The name of the log group to associate the metric filter with.
MetricTransformation LogMetricFilterMetricTransformation
A block defining collection of information needed to define how metric data gets emitted. See below.
Name Changes to this property will trigger replacement. string
A name for the metric filter.
Pattern string
A valid CloudWatch Logs filter pattern for extracting metric data out of ingested log events.
LogGroupName Changes to this property will trigger replacement. string
The name of the log group to associate the metric filter with.
MetricTransformation LogMetricFilterMetricTransformationArgs
A block defining collection of information needed to define how metric data gets emitted. See below.
Name Changes to this property will trigger replacement. string
A name for the metric filter.
Pattern string
A valid CloudWatch Logs filter pattern for extracting metric data out of ingested log events.
logGroupName Changes to this property will trigger replacement. String
The name of the log group to associate the metric filter with.
metricTransformation LogMetricFilterMetricTransformation
A block defining collection of information needed to define how metric data gets emitted. See below.
name Changes to this property will trigger replacement. String
A name for the metric filter.
pattern String
A valid CloudWatch Logs filter pattern for extracting metric data out of ingested log events.
logGroupName Changes to this property will trigger replacement. string
The name of the log group to associate the metric filter with.
metricTransformation LogMetricFilterMetricTransformation
A block defining collection of information needed to define how metric data gets emitted. See below.
name Changes to this property will trigger replacement. string
A name for the metric filter.
pattern string
A valid CloudWatch Logs filter pattern for extracting metric data out of ingested log events.
log_group_name Changes to this property will trigger replacement. str
The name of the log group to associate the metric filter with.
metric_transformation LogMetricFilterMetricTransformationArgs
A block defining collection of information needed to define how metric data gets emitted. See below.
name Changes to this property will trigger replacement. str
A name for the metric filter.
pattern str
A valid CloudWatch Logs filter pattern for extracting metric data out of ingested log events.
logGroupName Changes to this property will trigger replacement. String
The name of the log group to associate the metric filter with.
metricTransformation Property Map
A block defining collection of information needed to define how metric data gets emitted. See below.
name Changes to this property will trigger replacement. String
A name for the metric filter.
pattern String
A valid CloudWatch Logs filter pattern for extracting metric data out of ingested log events.

Supporting Types

LogMetricFilterMetricTransformation
, LogMetricFilterMetricTransformationArgs

Name This property is required. string
The name of the CloudWatch metric to which the monitored log information should be published (e.g., ErrorCount)
Namespace This property is required. string
The destination namespace of the CloudWatch metric.
Value This property is required. string
What to publish to the metric. For example, if you're counting the occurrences of a particular term like "Error", the value will be "1" for each occurrence. If you're counting the bytes transferred the published value will be the value in the log event.
DefaultValue string
The value to emit when a filter pattern does not match a log event. Conflicts with dimensions.
Dimensions Dictionary<string, string>
Map of fields to use as dimensions for the metric. Up to 3 dimensions are allowed. Conflicts with default_value.
Unit string
The unit to assign to the metric. If you omit this, the unit is set as None.
Name This property is required. string
The name of the CloudWatch metric to which the monitored log information should be published (e.g., ErrorCount)
Namespace This property is required. string
The destination namespace of the CloudWatch metric.
Value This property is required. string
What to publish to the metric. For example, if you're counting the occurrences of a particular term like "Error", the value will be "1" for each occurrence. If you're counting the bytes transferred the published value will be the value in the log event.
DefaultValue string
The value to emit when a filter pattern does not match a log event. Conflicts with dimensions.
Dimensions map[string]string
Map of fields to use as dimensions for the metric. Up to 3 dimensions are allowed. Conflicts with default_value.
Unit string
The unit to assign to the metric. If you omit this, the unit is set as None.
name This property is required. String
The name of the CloudWatch metric to which the monitored log information should be published (e.g., ErrorCount)
namespace This property is required. String
The destination namespace of the CloudWatch metric.
value This property is required. String
What to publish to the metric. For example, if you're counting the occurrences of a particular term like "Error", the value will be "1" for each occurrence. If you're counting the bytes transferred the published value will be the value in the log event.
defaultValue String
The value to emit when a filter pattern does not match a log event. Conflicts with dimensions.
dimensions Map<String,String>
Map of fields to use as dimensions for the metric. Up to 3 dimensions are allowed. Conflicts with default_value.
unit String
The unit to assign to the metric. If you omit this, the unit is set as None.
name This property is required. string
The name of the CloudWatch metric to which the monitored log information should be published (e.g., ErrorCount)
namespace This property is required. string
The destination namespace of the CloudWatch metric.
value This property is required. string
What to publish to the metric. For example, if you're counting the occurrences of a particular term like "Error", the value will be "1" for each occurrence. If you're counting the bytes transferred the published value will be the value in the log event.
defaultValue string
The value to emit when a filter pattern does not match a log event. Conflicts with dimensions.
dimensions {[key: string]: string}
Map of fields to use as dimensions for the metric. Up to 3 dimensions are allowed. Conflicts with default_value.
unit string
The unit to assign to the metric. If you omit this, the unit is set as None.
name This property is required. str
The name of the CloudWatch metric to which the monitored log information should be published (e.g., ErrorCount)
namespace This property is required. str
The destination namespace of the CloudWatch metric.
value This property is required. str
What to publish to the metric. For example, if you're counting the occurrences of a particular term like "Error", the value will be "1" for each occurrence. If you're counting the bytes transferred the published value will be the value in the log event.
default_value str
The value to emit when a filter pattern does not match a log event. Conflicts with dimensions.
dimensions Mapping[str, str]
Map of fields to use as dimensions for the metric. Up to 3 dimensions are allowed. Conflicts with default_value.
unit str
The unit to assign to the metric. If you omit this, the unit is set as None.
name This property is required. String
The name of the CloudWatch metric to which the monitored log information should be published (e.g., ErrorCount)
namespace This property is required. String
The destination namespace of the CloudWatch metric.
value This property is required. String
What to publish to the metric. For example, if you're counting the occurrences of a particular term like "Error", the value will be "1" for each occurrence. If you're counting the bytes transferred the published value will be the value in the log event.
defaultValue String
The value to emit when a filter pattern does not match a log event. Conflicts with dimensions.
dimensions Map<String>
Map of fields to use as dimensions for the metric. Up to 3 dimensions are allowed. Conflicts with default_value.
unit String
The unit to assign to the metric. If you omit this, the unit is set as None.

Import

Using pulumi import, import CloudWatch Log Metric Filter using the log_group_name:name. For example:

$ pulumi import aws:cloudwatch/logMetricFilter:LogMetricFilter test /aws/lambda/function:test
Copy

To learn more about importing existing cloud resources, see Importing resources.

Package Details

Repository
AWS Classic pulumi/pulumi-aws
License
Apache-2.0
Notes
This Pulumi package is based on the aws Terraform Provider.