Context
I have created a AWS Logs SubscriptionFilter using CDK. I am now trying to create a metric/alarm for some of the metrics for this resource.
Problem
- All the metrics I am interested in (see
ForwardedLogEvents,DeliveryErrors,DeliveryThrottlingin the Monitoring AWS Logs with CloudWatch Metrics docs) requires these dimensions to be specified:LogGroupNameDestinationTypeFilterName
The first two are easy to specify since the LogGroupName is also required while creating the construct and DestinationType in my case is just Lambda. However, I see no way to get FilterName using CDK.
- Using CloudWatch, I see that the
FilterNameis likeMyStackName-MyLogicalID29669D87-GCMA0Q4KKALH. So I can't directly specify it using aFn.ref(since I don't know the logical id). Using CloudFormation, I could have directly doneRef: LogicalId. - I also don't see any properties on the SubscriptionFilter object that will return this (unlike most other CDK constructs this one seems pretty bare and returns absolutely no information about the resource).
- There are also no
metric*methods onSubscriptionFilterobject (unlike other standard constructs like Lambda functions, S3 buckets etc.), so I have to manually specify theMetricobject. See for example: CDK metric objects docs. - The CDK construct (and the underlying CloudFormation resource: AWS::Logs::SubscriptionFilter) does not let me specify the
FilterName- so I can't use a variable to specify it also and the name is dynamically generated.
Example code that is very close to what I need:
const metric = new Metric({
namespace: 'AWS/Logs',
metricName: 'ForwardedLogEvents',
dimensions: {
DestinationType: 'Lambda',
// I know this value since I specified it while creating the SubscriptionFilter
LogGroupName: 'MyLogGroupName',
FilterName: Fn.ref('logical-id-wont-work-since-it-is-dynamic-in-CDK')
}
})
Question
- How can I figure out how to acquire the
FilterNameproperty to construct theMetricobject? - Or otherwise, is there another way to go about this?