CodeSHA256 is different from current CodeSHA256 in $LATEST
This is a Bug Report
Description
For bug reports:
- What went wrong?
After upgrading to Serverless 1.14.0, I'm now getting:
Serverless: Deployment failed!
Serverless Error ---------------------------------------
An error occurred while provisioning your stack: SaveAttachmentLambdaVersionXX
- CodeSHA256 (XX)
is different from current CodeSHA256 in $LATEST (XX).
Please try again with the CodeSHA256 in $LATEST..
- What did you expect should have happened?
New deployment should have succeeded
- What was the config you used?
Deploying to AWS. Using serverless-plugins-typescript to compile TS to a .build folder before deployment.
- What stacktrace or error message from your provider did you see?
ServerlessError: An error occurred while provisioning your stack: SaveSearchLambdaVersionXXX- CodeSHA256 (XXX) is different from current CodeSHA256 in $LATEST (XXX). Please try again with the CodeSHA256 in $LATEST..
at provider.request.then (/Users/cmmoyer/.nvm/v6.10.1/lib/node_modules/serverless/lib/plugins/aws/lib/monitorStack.js:109:33)
From previous event:
at AwsDeploy.monitorStack (/Users/cmmoyer/.nvm/v6.10.1/lib/node_modules/serverless/lib/plugins/aws/lib/monitorStack.js:26:12)
at provider.request.then (/Users/cmmoyer/.nvm/v6.10.1/lib/node_modules/serverless/lib/plugins/aws/lib/updateStack.js:88:30)
From previous event:
at AwsDeploy.update (/Users/cmmoyer/.nvm/v6.10.1/lib/node_modules/serverless/lib/plugins/aws/lib/updateStack.js:88:8)
From previous event:
at AwsDeploy.BbPromise.bind.then (/Users/cmmoyer/.nvm/v6.10.1/lib/node_modules/serverless/lib/plugins/aws/lib/updateStack.js:105:12)
From previous event:
at AwsDeploy.updateStack (/Users/cmmoyer/.nvm/v6.10.1/lib/node_modules/serverless/lib/plugins/aws/lib/updateStack.js:99:8)
From previous event:
at Object.aws:deploy:deploy:updateStack [as hook] (/Users/cmmoyer/.nvm/v6.10.1/lib/node_modules/serverless/lib/plugins/aws/deploy/index.js:99:10)
at BbPromise.reduce (/Users/cmmoyer/.nvm/v6.10.1/lib/node_modules/serverless/lib/classes/PluginManager.js:234:55)
From previous event:
at PluginManager.invoke (/Users/cmmoyer/.nvm/v6.10.1/lib/node_modules/serverless/lib/classes/PluginManager.js:234:22)
at PluginManager.spawn (/Users/cmmoyer/.nvm/v6.10.1/lib/node_modules/serverless/lib/classes/PluginManager.js:246:17)
at AwsDeploy.BbPromise.bind.then (/Users/cmmoyer/.nvm/v6.10.1/lib/node_modules/serverless/lib/plugins/aws/deploy/index.js:85:48)
From previous event:
at Object.deploy:deploy [as hook] (/Users/cmmoyer/.nvm/v6.10.1/lib/node_modules/serverless/lib/plugins/aws/deploy/index.js:81:10)
at BbPromise.reduce (/Users/cmmoyer/.nvm/v6.10.1/lib/node_modules/serverless/lib/classes/PluginManager.js:234:55)
at runCallback (timers.js:666:20)
at tryOnImmediate (timers.js:639:5)
at processImmediate [as _immediateCallback] (timers.js:611:5)
From previous event:
at PluginManager.invoke (/Users/cmmoyer/.nvm/v6.10.1/lib/node_modules/serverless/lib/classes/PluginManager.js:234:22)
at PluginManager.run (/Users/cmmoyer/.nvm/v6.10.1/lib/node_modules/serverless/lib/classes/PluginManager.js:253:17)
at variables.populateService.then (/Users/cmmoyer/.nvm/v6.10.1/lib/node_modules/serverless/lib/Serverless.js:100:33)
From previous event:
at Serverless.run (/Users/cmmoyer/.nvm/v6.10.1/lib/node_modules/serverless/lib/Serverless.js:87:74)
at serverless.init.then (/Users/cmmoyer/.nvm/v6.10.1/lib/node_modules/serverless/bin/serverless:23:50)
Additional Data
- Serverless Framework Version you're using: 1.14.0
- Operating System: darwin (macOS 10.12.4)
- Stack Trace: See above
- Provider Error messages: CodeSHA256 (XX) is different from current CodeSHA256 in $LATEST (XX)
- Node Version: v6.10.1
Also just started seeing this. I'm on serverless 1.13.2, using the serverless webpack plugin also.
Upgrade to 1.14 did not fix it. Downgrade down to 1.11 also did not fix it.
Started seeing this as well... serverless 1.14.0, also using serverless-webpack. I see the same error in the CloudFormation stack event:
CodeSHA256 (xx) is different from current CodeSHA256 in $LATEST (xx). Please try again with the CodeSHA256 in $LATEST.
Saw the same error today. Ended up working after a redeploy, but hopefully it doesn't happen again...
Same with me, I downgraded to 1.13 and it didn't fix it, but after waiting a while it's working again.
This might have been an AWS issue after all?
Thanks for the feedback everyone 👍
We saw such a behavior a few months ago. It was also resolved by simply waiting and re-reploying after some time. Seems to be smth. on AWS end.
I'll close this issue for now. Feel free to re-open / continue the discussion if this problems pops up again.
FWIW, we've been seeing this failure a lot more frequently over the past several days. We're on 1.5 right now and not able to move up to latest quite yet. As others have said, retrying once or twice takes care of it.
Did anyone actually figure out what the problem generally seems to be when this error occurs?
It's hard to believe that AWS has some batch job that runs once a day that magically fixes all the SHA problems. Maybe they do?
Adding versionFunctions: false to the provider property of serverless.yml is a possible workaround.
I just ran into this myself because I we had to workaround permissions issues in the built zip by unzipping, chmodding, and then rezipping. I created a script to update the SHAs in the json files, the primary guts of which are:
# Fix perms in built zip
mkdir package-temp
mkdir deploy-temp
unzip -d package-temp/ .serverless/group-api.zip
rm .serverless/group-api.zip
cp .serverless/* deploy-temp/
chmod o+r package-temp/*
zip -j deploy-temp/group-api.zip package-temp/*
# Update SHA hash in json files
sha=$(openssl dgst -sha256 -binary deploy-temp/group-api.zip | openssl enc -base64)
echo CodeSHA256 is ${sha}
sed -i "s/\"CodeSha256\": \".*\"/\"CodeSha256\": \"${sha}\"/g" deploy-temp/*.json
# Deploy fixed zip/json files
./node_modules/.bin/serverless deploy --package deploy-temp
BTW I also experienced this using claudiajs (not serverless framework). So there's something on AWS's end.
I have also been hitting this issue a lot more frequently , but updating the stack does not seem to fix it, versionFunction: false does not allow you to update your lambda functions. Any solutions ?
For me, it happened because I used the same filename in artifact for two functions
So I renamed the ZIP files ... and now it works
The issue:
functions:
statusBadge:
handler: index.handler
package:
artifact: ./services/commit-badges/dist/dist.zip
...
functions:
statusBadge:
handler: index.handler
package:
artifact: ./services/status-badges/dist/dist.zip
Solution:
functions:
statusBadge:
handler: index.handler
package:
artifact: ./services/commit-badges/dist/dist_commit_badges.zip
...
functions:
statusBadge:
handler: index.handler
package:
artifact: ./services/status-badges/dist/dist_status_badges.zip
a little late to this, but could this be an alias issue? I just tried deploying my function and received this error. I removed my alias and then deployed again and that error was gone, albeit a different one which I was expecting was there instead 😄
happening to me as well, does anybody know what is happening?
I found a solution by updating the permissions in was IAM:
Debugging:
When running the deploy command add the --verbose option, this gave me this:
CloudFormation - CREATE_FAILED - AWS::Lambda::Version - XXX
Solution:
In IAM I gave my Policy that is attached to the user that is authenticated with the aws configure command full access to Lambda. I would absolutely not advise you to do the same if this is production code, instead, you should find the specific Access setting that is needed, I think it's in Permissions Management somewhere.
Now that line has changed to:
CloudFormation - CREATE_COMPLETE - AWS::Lambda::Version - XXX
I get this error when trying to overwrite the serverless generated zip files in a separate pipeline job (due to lack of immutability in serverless [see #4715]). anyone solved for this?
I package my functions individually so I can't specify the artifact via --artifact
give zip file name different for lambda function . issue will fix .
Having encountered this with my own local plugin - the issue was that SLS was doing a SHA on the old artifact prior to the build, which would then generate a new artifact with a different SHA when uploaded.
Using the lifecycle hook package:init instead of package:compileFunctions fixed the issue for me.