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

(lambda-event-sources): Lambda event source is not removed when deploying CDK application #18706

Closed
dbadami opened this issue Jan 28, 2022 · 4 comments
Assignees
Labels
@aws-cdk/aws-lambda-event-sources bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. p2

Comments

@dbadami
Copy link

dbadami commented Jan 28, 2022

What is the problem?

I've recently upgrade to CDK 1.140.0 from 1.119.0 and decided to take advantage of the native support for adding an SQS event source to a Lambda function. To do so I deleted the existing EventSourceMapping in code in favor of the native solution but when deploying the application I encountered the following the error:

***Stack: creating CloudFormation changeset... 4:50:32 AM | CREATE_FAILED | AWS::Lambda::EventSourceMapping | ..ry69C3A26D4B0792A0 Resource handler returned message: "An event source mapping with SQS arn (" arn:aws:sqs: ") and function (" ***V21AE54-asmVruavSRPT ") already exists. Please update or delete the existing mapping with UUID 2e1ba402-c92c-4d6f-97b8-c 0acfdc4bc3f

Resources names and ARNs have been redacted.

Reproduction Steps

Output of git diff:

-    // Until reportBatchItemFailures is supported natively
-    new lambda.EventSourceMapping(this, "SourceMapping", {
-      target: lambdaFunction,
-      eventSourceArn: this.queue.queueArn,
-      reportBatchItemFailures: true,
-    });
+    lambdaFunction.addEventSource(
+      new lambdaSources.SqsEventSource(this.queue, {
+        reportBatchItemFailures: true,
       })
     );

What did you expect to happen?

For the application to successfully deploy.

What actually happened?

The deployment failed because there was already an existing event source mapping for the same queue ARN and Lambda function name/ARN/identifier.

CDK CLI Version

1.140.0

Framework Version

No response

Node.js Version

v.14.18.3

OS

Amazon Linux 2

Language

Typescript

Language Version

TypesScript(3.9.7)

Other information

Potentially related issue:
aws/serverless-application-model#1320

@dbadami dbadami added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 28, 2022
@ryparker
Copy link
Contributor

You'll likely need to deploy your stack without the old resources to properly delete them from AWS. Then you should be able to deploy the updated/new CDK resources.

The updated CDK code must not be 1 for 1 with what you had before. Try running cdk diff to see the proposed CloudFormation changes. This might bring clarity as to why you'll need to destroy the old resource beforehand.

@ryparker ryparker added the p2 label Jan 31, 2022
@dbadami
Copy link
Author

dbadami commented Feb 2, 2022

Output of cdk diff:

Resources
[-] AWS::Lambda::EventSourceMapping ***317457A9 destroy // old mapping
[+] AWS::Lambda::EventSourceMapping ***/***/SqsEventSource:***69C3A26D ***V2SqsEventSource***Stack***69C3A26D4B0792A0 // new mapping

I'd expect this not to be in the diff because there isn't anything changing but the fact that CF treats these as two different resources, however unexpected, this behaviour makes sense to me.

@kaizencc
Copy link
Contributor

This looks like something that the CDK cannot do anything about, as it is CloudFormation behavior at work here, so we should follow what @ryparker suggested in this instance. Feel free to reopen if you don't think that's the case.

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda-event-sources bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. p2
Projects
None yet
Development

No branches or pull requests

3 participants