serverless: More than one s3 event failing deployment for existing s3 bucket.
This is a Bug Report
Description
I have 30 different suffixes for which i want to trigger event associated with S3 and lambda. So i need to define all of them in serverless.yml file. It is working fine for one event but not working when i put two or more events. I think it is not working for multiple events.
- What went wrong? Throwing following error:
Serverless Error ---------------------------------------
An error occurred: GICreateThumbnailsCustomS31 - Failed to create resource. The statement id (GICreateThumbnails-gi3-staging-original) provided already exists. Please provide a new statement id, or remove the existing statement. See details in CloudWatch Log: 2019/07/27/[$LATEST]337e42c16b0643bcadd452556a6dc004.
- What did you expect should have happened? I am expecting to see all events should be visible on my lambda console in AWS which i have defined in serverless.yml
- What was the config you used?
service: User
frameworkVersion: ">=1.48.4"
tenant: ginvoicing
app: ginvoicing
custom:
bucket: gi3-original
provider:
name: aws
runtime: nodejs8.10
memorySize: 192
timeout: 10
iamRoleStatements:
- Effect: "Allow"
Action:
- s3:*
Resource: "*"
logRetentionInDays: 5
stage: dev
region: ap-south-1
functions:
GICreateThumbnails:
handler: GICreateThumbnails.handler
name: GICreateThumbnails # optional, Deployed Lambda name
description: To create thumbnail of the uploaded picture on s3. # optional, Description to publish to AWS
events:
- s3:
bucket: ${self:custom.bucket}
event: s3:ObjectCreated:*
rules:
- prefix: images/items/
- suffix: .png
existing: true
- s3:
bucket: ${self:custom.bucket}
event: s3:ObjectCreated:*
rules:
- prefix: images/user/
- suffix: .png
existing: true
- What stacktrace or error message from your provider did you see?
Stack Trace --------------------------------------------
ServerlessError: An error occurred: GICreateThumbnailsCustomS31 - Failed to create resource. The statement id (GICreateThumbnails-gi3-staging-original) provided already exists. Please provide a new statement id, or remove the existing statement. See details in CloudWatch Log: 2019/07/27/[$LATEST]337e42c16b0643bcadd452556a6dc004.
at provider.request.then.data (/Users/tarunjangra/.nvm/versions/node/v8.11.3/lib/node_modules/serverless/lib/plugins/aws/lib/monitorStack.js:121:33)
From previous event:
at AwsDeploy.monitorStack (/Users/tarunjangra/.nvm/versions/node/v8.11.3/lib/node_modules/serverless/lib/plugins/aws/lib/monitorStack.js:27:12)
at provider.request.then.cfData (/Users/tarunjangra/.nvm/versions/node/v8.11.3/lib/node_modules/serverless/lib/plugins/aws/lib/updateStack.js:103:28)
From previous event:
at AwsDeploy.update (/Users/tarunjangra/.nvm/versions/node/v8.11.3/lib/node_modules/serverless/lib/plugins/aws/lib/updateStack.js:103:8)
From previous event:
at AwsDeploy.BbPromise.bind.then (/Users/tarunjangra/.nvm/versions/node/v8.11.3/lib/node_modules/serverless/lib/plugins/aws/lib/updateStack.js:117:35)
From previous event:
at AwsDeploy.updateStack (/Users/tarunjangra/.nvm/versions/node/v8.11.3/lib/node_modules/serverless/lib/plugins/aws/lib/updateStack.js:113:33)
From previous event:
at AwsDeploy.BbPromise.bind.then (/Users/tarunjangra/.nvm/versions/node/v8.11.3/lib/node_modules/serverless/lib/plugins/aws/deploy/index.js:127:39)
From previous event:
at Object.aws:deploy:deploy:updateStack [as hook] (/Users/tarunjangra/.nvm/versions/node/v8.11.3/lib/node_modules/serverless/lib/plugins/aws/deploy/index.js:123:30)
at BbPromise.reduce (/Users/tarunjangra/.nvm/versions/node/v8.11.3/lib/node_modules/serverless/lib/classes/PluginManager.js:464:55)
From previous event:
at PluginManager.invoke (/Users/tarunjangra/.nvm/versions/node/v8.11.3/lib/node_modules/serverless/lib/classes/PluginManager.js:464:22)
at PluginManager.spawn (/Users/tarunjangra/.nvm/versions/node/v8.11.3/lib/node_modules/serverless/lib/classes/PluginManager.js:484:17)
at AwsDeploy.BbPromise.bind.then (/Users/tarunjangra/.nvm/versions/node/v8.11.3/lib/node_modules/serverless/lib/plugins/aws/deploy/index.js:93:48)
From previous event:
at Object.deploy:deploy [as hook] (/Users/tarunjangra/.nvm/versions/node/v8.11.3/lib/node_modules/serverless/lib/plugins/aws/deploy/index.js:89:30)
at BbPromise.reduce (/Users/tarunjangra/.nvm/versions/node/v8.11.3/lib/node_modules/serverless/lib/classes/PluginManager.js:464:55)
From previous event:
at PluginManager.invoke (/Users/tarunjangra/.nvm/versions/node/v8.11.3/lib/node_modules/serverless/lib/classes/PluginManager.js:464:22)
at PluginManager.run (/Users/tarunjangra/.nvm/versions/node/v8.11.3/lib/node_modules/serverless/lib/classes/PluginManager.js:496:17)
at variables.populateService.then (/Users/tarunjangra/.nvm/versions/node/v8.11.3/lib/node_modules/serverless/lib/Serverless.js:116:33)
at runCallback (timers.js:810:20)
at tryOnImmediate (timers.js:768:5)
at processImmediate [as _immediateCallback] (timers.js:745:5)
From previous event:
at Serverless.run (/Users/tarunjangra/.nvm/versions/node/v8.11.3/lib/node_modules/serverless/lib/Serverless.js:103:74)
at serverless.init.then (/Users/tarunjangra/.nvm/versions/node/v8.11.3/lib/node_modules/serverless/bin/serverless.js:52:28)
at /Users/tarunjangra/.nvm/versions/node/v8.11.3/lib/node_modules/serverless/node_modules/graceful-fs/graceful-fs.js:111:16
at /Users/tarunjangra/.nvm/versions/node/v8.11.3/lib/node_modules/serverless/node_modules/graceful-fs/graceful-fs.js:45:10
at FSReqWrap.oncomplete (fs.js:135:15)
From previous event:
at initializeErrorReporter.then (/Users/tarunjangra/.nvm/versions/node/v8.11.3/lib/node_modules/serverless/bin/serverless.js:52:6)
at runCallback (timers.js:810:20)
at tryOnImmediate (timers.js:768:5)
at processImmediate [as _immediateCallback] (timers.js:745:5)
From previous event:
at Object.<anonymous> (/Users/tarunjangra/.nvm/versions/node/v8.11.3/lib/node_modules/serverless/bin/serverless.js:38:39)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
Similar or dependent issues:
Additional Data
- Serverless Framework Version you’re using: 1.48.4
- Operating System: darwin
- Enterprise Plugin Versione: 1.3.3
- Platform SDK Version: 2.1.0
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 4
- Comments: 41 (12 by maintainers)
@tarunjangra @michelem09 @HumbleBeck thanks for the in-depth error reporting.
I was finally able to reproduce the issue. It was caused by a race condition. I updated the PR which now includes the fix and the error seems to be resolved (I also added an integration test to cover this case). I know it might be annoying, but can one of you maybe test this PR again. TBH I’m not sure if there’s a way to test this deterministically since we already deployed some many different versions in the past which failed one way or another and the stack might be in a weird state. Anyway, I would be really grateful if one can jump in and give it a shot. 🙏
Thanks again for taking the time to take a deep dive into this issue. It’s certainly not that straightforward but I believe we’re onto something here! 👍 💯
@pmuens I tested it thoroughly and got new issue. I am not sure if i should create new issue or should open the same one. Just to make you sure, I have installed master branch and it already has that fixed branch merged.
serverless deploy --verbose
serverless.yml
Error I am getting now.
@tarunjangra it was deployed on another branch
npm i -g serverless/serverless#existing-s3-multiThanks for the update @michelem09 👍
Yes, I too see this error when I upgrade from an old deployment. Right now it’s just working if you deploy from scratch. I try to mitigate this shortcoming so that you can upgrade without running into this issue.