serverless-application-model: The event source and function provided mapping already exists. Please update or delete the existing mapping with UUID
Description: I am trying to implement Dynamodb streams and a trigger for lambda
myFunction:
Type: AWS::Serverless::Function
Properties:
Policies:
- AWSLambdaBasicExecutionRole
- DynamoDBCrudPolicy:
TableName: !Ref TableName
- DynamoDBStreamReadPolicy:
TableName: !Ref TableName
StreamName:
!Select
- 2
- !Split
- "/"
- Fn::ImportValue:
!Sub ${TableName}-streams-arn
CodeUri: bin/
Handler: myFunctions
Events:
dynamodb:
Type: DynamoDB
Properties:
Stream:
Fn::ImportValue: !Sub ${TableName}-streams-arn
StartingPosition: LATEST
BatchSize: 10
The first deployment was successful, however after adding the DynamoDBStreamReadPolicy and changed StartingPosition from TRIM_HORIZON to LATEST I got the following error:
The event source arn (" arn:aws:dynamodb:.../stream/... ") and function (" myFunction-...") provided mapping already exists. Please update or delete the existing mapping with UUID xxxx-xxxx-xxx-xxx (Service: AWSLambda; Status Code: 409; Error Code: ResourceConflictException; Request ID: xxxx-xxxxxxx-xxxx-xxx)
Observed result: Error
Expected result: Probably error, but at this point I did not find any explanation
PS: as my understanding once the event mapping is created must be replaced or deleted? If yes why it says “Please update or delete”? If now I want to change the mapping configuration do I need to remove it, deploy, add it again and redeploy?
Thanks
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 51
- Comments: 29 (3 by maintainers)
I also ran into and fixed this by calling
aws lambda list-event-source-mappingsto find the orphaned mapping thenaws lambda delete-event-source-mapping --uuid {uuid}to remove itFor future Googlers: I had this issue, and it was because there was a manually-created trigger hanging around that wasn’t deleted with my stack. Using the CLI to delete by UUID, or going to SQS -> the queue -> Lambda triggers should have let me find it.
2 and half years later and still running into that problem. With a Lambda with an event source mapping in a SAM template. simply adding a layer to the lambda triggered this error. I am sure doing a lot of ClickOps today for something that is supposedly IAC.
I was able to execute the following manually, then the corresponding CloudFormation template succeeded:
However, I would advocate that the bug be resolved internally with AWS engineers. That way we don’t have to do one-off scripts/commands to ensure something expected to work correctly, actually works.
Thanks all for the input, very informative.
I’m able to reproduce this with a pure CloudFormation template:
That template will deploy fine.
But as @MatteoGioioso mentioned, if you change
StartingPositionfromTRIM_HORIZONtoLATESTand deploy again, you’ll get the error:Please fix, same issue here!
Ok, this is a long standing bug with Cloudformation. Similar happening with Kinesis and it was already spotted in 2018 on the serverless framework. This is a minimal reproducible case with kinesis: https://github.com/MatteoGioioso/sls-event-source-mapping-bug You just need to change
startingPositionfromTRIM_HORIZONtoLATESTto trigger the bug.Use the aws cli as: aws lambda delete-event-source-mapping to delete the uuid that is “broken” then re-apply the cloud formation stack See: https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/delete-event-source-mapping.html
@hoffa I’m hitting the same. Can you please re-open and publish the status from “I’ve routed this issue internally.” ?
The issue also happens with AWS CDK (v1.134.0) generated CloudFormation templates. When the Lambda event source is a SQS queue.
As mentioned in https://github.com/aws/serverless-application-model/issues/1320#issuecomment-845558908 (and others), this has to do with the underlying resource, and can be reproduced without SAM. SAM only transforms the template into CloudFormation, but doesn’t otherwise handle the provisioning.
The issue is that changes to the property requires replacement, but due to how CloudFormation handles changes that require replacement (typically by first creating the new resource and then deleting the old one), it’ll try to create two event source mappings from the same resource, which Lambda doesn’t allow.
I’ve routed this issue internally.
Hit the issue same day trying to update the kinesis source mapping settings.
likely not, whatever was prepared for reInvent 6-7 years ago is what we are stuck with, I have yet to see any bugs that I have encountered in the last 5+ years ever be fixed, even with a 7 figure support contract.
On Fri, Aug 9, 2024 at 4:31 PM Rigoberto Perez @.***> wrote:
Hi Guys,
I ran into the same issue when I tried to register a SQS->lambda trigger. 1st deployment is successful but in the next deployment if there is any change in the configuration of lambda, SQS or event_source_mapping then it fails with the following error.
An event source mapping with SQS arn ("queue-arn") and function ("lambda-function") already exists. Please update or delete the existing mapping with UUIDSo, my question is have we already fixed this issue in the latest cdk version? I’m currently, using
aws-cdk-lib==2.17.0Any recommendations on how to handle it gracefully?
I also faced this issue while deploying the Terraform code 2nd time. Do we need to get rid of existing mapping everytime we make any change related to mapping ?
This is still occurring just happened to me today.