I'm trying to create a custom metric using CloudFormation. I've followed the example from https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-logs-metricfilter.html. My existing lambda logs to a CloudWatch log group that shows up in CloudWatch as /aws/lambda/my-function-name
. Here's my CloudFormation YAML for the metric:
ErrorsLogMetric:
Type: AWS::Logs::MetricFilter
Properties:
LogGroupName: !Sub "/aws/lambda/${AWS::StackName}"
FilterPattern: "[ERROR]"
MetricTransformations:
- MetricValue: "1"
MetricNamespace: "LogMetrics"
MetricName: "MyCustomMetric"
${AWS::StackName} resolves to "my-function-name" when it runs. The CloudFormation script runs successfully and says the metric was created, but when I go to CloudWatch the log group for my lambda, it shows zero filters. What do I need to do differently to cause this custom metric to show up as a filter for my lambda log group when it is created via CloudFormation?
If I hard code the property as LogGroupName: "/aws/lambda/my-function-name"
then it works. But I don't want to hard code it since the value of ${AWS::StackName} is dynamic in different use cases.
LogGroupName
to be!Ref LogGroupLogicalId
. – Jason Wadsworth