cloudwatch-actions: cannot add LambdaActions to alarms with the same id but different addresses #30754
Labels
@aws-cdk/aws-cloudwatch-actions
bug
This issue is a bug.
effort/small
Small work item – less than a day of effort
p2
Describe the bug
See the reproduction code below. When we try to add
LambdaAction
to a differentAlarm
with the same id, synthesize fails. This pattern often appears when we defineAlarm
constructs as chidren of various constructs and use the same Lambda function to notify them.This behavior forces users to set the id of the alarms unique across the entire stack, making it difficult to reuse a construct with alarms.
Expected Behavior
Synthesize successes.
Current Behavior
Synthesize fails.
Reproduction Steps
Synthesize the below code:
Possible Solution
The problem derives from here:
aws-cdk/packages/aws-cdk-lib/aws-cloudwatch-actions/lib/lambda.ts
Lines 25 to 26 in 358cead
I think the
permissionId
should really beAlarmPermission${alarm.node.addr}
.node.addr
is a globally unique id across a stack, so safe to use here.Also, because lambda permission is stateless and changes to logical ids will not cause any disruption, we should not need a feature flag to introduce this change.
Additional Information/Context
No response
CDK CLI Version
2.147.3
Framework Version
2.147.3
Node.js Version
v20.10.0
OS
macOS
Language
TypeScript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: