Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LambdaAction fails if same Lambda added to multiple alarms #30264

Open
dfserrano opened this issue May 17, 2024 · 6 comments
Open

LambdaAction fails if same Lambda added to multiple alarms #30264

dfserrano opened this issue May 17, 2024 · 6 comments
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. guidance Question that needs advice or information.

Comments

@dfserrano
Copy link

Describe the bug

Adding the same lambda as the action for multiple alarms causes an error because of logical id conflicts. The error says There is already a Construct with name 'AlarmPermission' in Function

Expected Behavior

One Lambda function can be configured as action for multiple alarms without the need to use the context @aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction

Current Behavior

There is already a Construct with name 'AlarmPermission' in Function

Reproduction Steps

alarm1.addAlarmAction(new actions.LambdaAction(lambda));
alarm2.addAlarmAction(new actions.LambdaAction(lambda));

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.140.0

Framework Version

No response

Node.js Version

18

OS

Mac

Language

TypeScript

Language Version

No response

Other information

No response

@dfserrano dfserrano added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels May 17, 2024
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label May 17, 2024
@khushail khushail added investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels May 17, 2024
@khushail khushail self-assigned this May 21, 2024
@khushail
Copy link
Contributor

khushail commented May 21, 2024

@dfserrano , I see this issue was reported here and fixed by this PR. As per the expectation and the intention of keeping the flag enabled is described here - Ref

With the feature flag disabled it will throw if the same lambda is added to multiple alarms because it will try to add multiple permissions with the same 'AlarmPermission' logical ID. If the same lambda is added to different actions for one alarm it will not throw.

Please feel free to reach out if this is not helpful or anything is misunderstood.
Thanks.

@khushail khushail added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels May 21, 2024
@dfserrano
Copy link
Author

Does it mean that the intention of Lambda actions is that users create one Lambda function per Alarm?
So, if I want to act on my alarms, and I have 100 alarms, I will need 100 Lambda functions?

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label May 22, 2024
@jfener
Copy link

jfener commented May 31, 2024

Ran into this as well.

@khushail
Copy link
Contributor

@dfserrano ,the Alarm requires a Lambda ARN to invoke. If there are 100 Alarms, same Lambda ARN could be used -

alarmActionArn: this.lambdaFunction.functionArn,

@khushail khushail added the guidance Question that needs advice or information. label May 31, 2024
@khushail khushail removed their assignment May 31, 2024
@dfserrano
Copy link
Author

The problem is that without that flag, then the permissionId in

this.lambdaFunction.addPermission(permissionId, {

will have a collision when trying to add the second permission.

By default, the flag that enables the desired functionality is not set. My question is whether having that flag off by default is the intended behavior or if it should be on by default.

Additionally, using the same example I used before, attempting to add a lambda action to 100 alarms results in 100 new resources being created, one for each alarm-lambda permission. This may reach the CloudFormation stack resource limit per stack (if I end up with more than 500). As a workaround, I created a composite alarm containing all the child alarms I wanted to trigger the lambda. Then I updated my lambda function to extract extra information from those child alarms. This avoids hitting the stack resource limit but requires additional logic in the lambda.

@khushail
Copy link
Contributor

@dfserrano, by default, the flag is not set. As mentioned in this readme , here is a snippet for the flag value mentioned -

Screenshot 2024-05-31 at 2 40 49 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

3 participants