serverless: serverless deploy fails after adding properties to a lambda event stream
This is a Bug Report
Description
I have a serverless.yml file which defines a lambda function which fires based on kinesis stream events. This would successfully deploy when running sls deploy. An example snippet of this is shown below.
...
functions:
whos-got-the-func:
handler: handler.WhosGotTheFunc
timeout: 60
environment:
...
events:
- stream:
type: kinesis
arn:
Fn::ImportValue: ${env:KINESIS_FUNC_UPDATE}
...
If i then add some additional properties to the kinesis stream event, such as a batchSize, startingPosition and enabled then the sls deploy fails. Example of the changes shown below:
...
functions:
whos-got-the-func:
handler: handler.WhosGotTheFunc
timeout: 60
environment:
...
events:
- stream:
type: kinesis
arn:
Fn::ImportValue: ${env:KINESIS_FUNC_UPDATE}
batchSize: 100
startingPosition: LATEST
enabled: true
...
The error message output is as follows:
11:54:20.545 sls deploy -v
11:54:21.828
11:54:21.846 Serverless: Updating Log Forwarding Resources...
11:54:21.847 Serverless: Log Forwarding Resources Updated
11:54:21.853 Serverless: Packaging service...
11:54:22.695 Serverless: Uploading CloudFormation file to S3...
11:54:22.810 Serverless: Uploading artifacts...
11:54:23.427 Serverless: Validating template...
11:54:24.206 Serverless: Updating Stack...
11:54:25.480 Serverless: Checking Stack update progress...
11:54:30.742 CloudFormation - UPDATE_IN_PROGRESS - AWS::CloudFormation::Stack - MyCloudStack
11:55:02.387 CloudFormation - UPDATE_IN_PROGRESS - AWS::Lambda::Function - whos-got-the-func
11:55:02.387 CloudFormation - UPDATE_IN_PROGRESS - AWS::Lambda::Function - i-got-the-func
11:55:02.387 CloudFormation - UPDATE_IN_PROGRESS - AWS::Lambda::Function - you-got-the-func
11:55:02.387 CloudFormation - UPDATE_COMPLETE - AWS::Lambda::Function - i-got-the-func
11:55:02.387 CloudFormation - UPDATE_COMPLETE - AWS::Lambda::Function - whos-got-the-func
11:55:02.387 CloudFormation - UPDATE_IN_PROGRESS - AWS::Lambda::Function - we-got-the-func
11:55:02.387 CloudFormation - UPDATE_IN_PROGRESS - AWS::Lambda::Function - shes-got-the-func
11:55:02.387 CloudFormation - UPDATE_COMPLETE - AWS::Lambda::Function - you-got-the-func
11:55:02.388 CloudFormation - UPDATE_COMPLETE - AWS::Lambda::Function - we-got-the-func
11:55:02.388 CloudFormation - UPDATE_COMPLETE - AWS::Lambda::Function - shes-got-the-func
11:55:07.633 CloudFormation - UPDATE_IN_PROGRESS - AWS::Lambda::EventSourceMapping - WhosGotTheFuncEvenSourceMappingKinesisABCDUpdateKinesisArn
11:55:07.633 CloudFormation - UPDATE_FAILED - AWS::Lambda::EventSourceMapping - WhosGotTheFuncEvenSourceMappingKinesisABCDUpdateKinesisArn
11:55:12.857 CloudFormation - UPDATE_ROLLBACK_IN_PROGRESS - AWS::CloudFormation::Stack - MyCloudStack
11:55:18.107 CloudFormation - UPDATE_IN_PROGRESS - AWS::Lambda::Function - i-got-the-func
11:55:18.107 CloudFormation - UPDATE_IN_PROGRESS - AWS::Lambda::Function - whos-got-the-func
11:55:18.107 CloudFormation - UPDATE_IN_PROGRESS - AWS::Lambda::Function - shes-got-the-func
11:55:18.108 CloudFormation - UPDATE_IN_PROGRESS - AWS::Lambda::Function - we-got-the-func
11:55:18.108 CloudFormation - UPDATE_IN_PROGRESS - AWS::Lambda::Function - you-got-the-func
11:55:18.108 CloudFormation - UPDATE_COMPLETE - AWS::Lambda::Function - whos-got-the-func
11:55:18.108 CloudFormation - UPDATE_COMPLETE - AWS::Lambda::Function - i-got-the-func
11:55:18.108 CloudFormation - UPDATE_COMPLETE - AWS::Lambda::Function - shes-got-the-func
11:55:18.108 CloudFormation - UPDATE_COMPLETE - AWS::Lambda::Function - you-got-the-func
11:55:18.108 CloudFormation - UPDATE_COMPLETE - AWS::Lambda::Function - we-got-the-func
11:55:18.108 CloudFormation - UPDATE_COMPLETE - AWS::Lambda::EventSourceMapping - WhosGotTheFuncEvenSourceMappingKinesisABCDUpdateKinesisArn
11:55:28.582 CloudFormation - UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS - AWS::CloudFormation::Stack - MyCloudStack
11:55:28.582 CloudFormation - DELETE_COMPLETE - AWS::Lambda::EventSourceMapping - WhosGotTheFuncEvenSourceMappingKinesisABCDUpdateKinesisArn
11:55:28.582 CloudFormation - UPDATE_ROLLBACK_COMPLETE - AWS::CloudFormation::Stack - MyCloudStack
11:55:28.583 Serverless: Operation failed!
11:55:28.587
11:55:28.588 Serverless Error ---------------------------------------
11:55:28.588
11:55:28.588 An error occurred: WhosGotTheFuncEvenSourceMappingKinesisABCDUpdateKinesisArn -
The event source arn (arn:aws:kinesis:ap-southeast-2:6969696969:stream/Update-Kinesis)
and function (MyCloudStack-whos-got-the-func) provided mapping already exists.
Please update or delete the existing mapping with UUID 666666-7777-8888-9999-000000000000.
11:55:28.588
11:55:28.588 Get Support --------------------------------------------
11:55:28.588 Docs: docs.serverless.com
11:55:28.589 Bugs: github.com/serverless/serverless/issues
11:55:28.589 Forums: forum.serverless.com
11:55:28.589 Chat: gitter.im/serverless/serverless
11:55:28.589
11:55:28.589 Your Environment Information -----------------------------
11:55:28.589 OS: linux
11:55:28.589 Node Version: 6.11.3
11:55:28.589 Serverless Version: 1.22.0
11:55:28.589
11:55:28.596 make: *** [_deploy] Error 1
11:55:30.069 make: *** [deploy] Error 2
11:55:30.078 [go] Current job status: failed.
To solve this problem you need to manually remove the existing/previous trigger from the lambda function via the console. However, the behaviour i would expect here is that the deploy succeeds overriding the initial trigger but just defining the additional properties. Ie. no manual intervention required.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 27
- Comments: 34 (2 by maintainers)
Well… that’s a bit awkard…
My function was deleted but the mapping between it and the stream wasn’t so… I need to create a new one manually, magically the mapping appears in the new function, delete the mapping and the delete the function again,
hope this helps someone
Closing since this issue is quite stale and we’ve pushed some changes in the past. Furthermore one can find some workarounds in this thread.
Feel free to conitnue the discussion…
Can we reopen this? It’s makes the event mapping unusable via Serverless.com.
Since this issue still exists, I appreciate the (manual) workaround, but long-term requiring manual effort for CloudFormation and Serverless templates is anti-thetical to the purporse of these services. Not addressing this customer impacting root cause really is not acceptable (not sure why this was ever closed). Please reopen.
Please consider reopening. Manual or even scripted workarounds make serverless much less of an interesting proposition for managing lambda infrastructure. If you handle creation of mappings via config, you automatically create the expectation of being able to handle the updates, too.
Possible work-around through aws-cli:
aws lambda delete-event-source-mapping --uuid <UUID from error message>Why closed? This is still an issue
This problem is making it hard for us to deploy code into our production environment - would be great if this issue were re-opened!
The expected behavior is that
serverlesscorrects the erroneous binding (removes then readds). Serverless should remain idempotent and simply create or update the stack as it’s defined in serverless.yml without error.This is pretty easy to reproduce, just deploy a simple example like https://github.com/DavidWells/serverless-workshop/tree/master/lessons-code-complete/events/kinesis/kinesis-basic and then go to CloudFormation and delete the stack. Make sure it’s deleted and then re-deploy. It errors 100% of the time for me.
The workaround of creating a new function with the same name just to delete the mapping did work for me too. But it would indeed be very good if serverless did the right thing in the first place.
Another workaround is to delete the mapping in the command line via the aws-cli. This worked for me:
Docs: https://docs.aws.amazon.com/cli/latest/reference/lambda/delete-event-source-mapping.html
Make sure you’ve got your credentials set up to use the aws-cli for your OS: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html
Leaving breadcrumbs 😃
I’ve seen this issue when there was no actual change to the event source mapping, but the syntax of the template changed around the use of
Fn::GetAttfrom the short-form with dot-notation to the long form with array notation. This was for an SQS event source mapping.This doesn’t seem to be a serverless issue as much as an issue with CloudFormation. It appears that serverless is generating the EventSourceMapping correctly according to the Cloudformation docs:
This issue also mentions that this is a known issue with cloudformation currently.
@nojohnny101 Could you be a little more specific about what you did? It appears that Serverless declares the EventSourceMapping to depend on the IamRoleLambdaExecution only.
please reopen
Confirmed this is still happening in 1.40.0, please reopen.