You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Enhance Update Logic for Individually Packaged Lambdas #9732
I have a simple project with 3 functions which I am choosing to package individually.
On top of that, they all use a common layer for NodeJS dependencies.
When I deploy for the first time, 4 zips are generated (1 layer, 3 function zips).
Subsequently, when I update 1 of the 3 Lambda functions, 3 function zips are uploaded, 1 layer zip is skipped since it hasn't changed.
It would be great if the same kind of change detection that allows us to skip unmodified layers could be applied to functions as well.
So in this scenario, If only 1 lambda function is changed, then definitely its zip hash will have changed, but the other 2 functions would have remained the same (again, they are packaged individually). Meaning, ideally only one update should be detected and thus only one zip file uploaded for deployment.
There are hints at improving some of this logic in #6580, but I am not sure If this use case would be completely covered if some of the proposed changes mentioned there are implemented.
Would appreciate comments/feedback regarding this.
Hello @bojanraic, thanks for reporting. Could you please share a reproducible example? At the moment we're detecting if zip did no change and if that's the case it's not re-uploaded. Could you check if in fact the zips for your individually packed functions are not changing?
Hi @pgrzesik, thanks for the reply.
I will include some code and log snippets from a test project a while back. Hope that will help.
Serverless version: 2.46.0
Change that triggered the deployment:
Showing 1 changed file with 2 additions and 2 deletions. +2 −2 src/func-03/handler.js
module.exports.main=async()=>({statusCode: 200,body: JSON.stringify({message: "Hello from FuncThree!",},null,2),});
CI/CD Output
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Excluding development dependencies...
Serverless: Excluding development dependencies...
Serverless: Excluding development dependencies...
Here layer upload is skipped, but all 3 function zips are uploaded
Serverless: Layer nodeModules is already uploaded.
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Skip uploading nodeModules
Serverless: Uploading service funcOne.zip file to S3 (944 B)...
Serverless: Uploading service funcTwo.zip file to S3 (681 B)...
Serverless: Uploading service funcThree.zip file to S3 (309 B)...
And then in CFN, onlyFuncThreegets versioned, which is good.
So the behavior of uploading packaged artifacts vs actually updating AWS resources is a bit counterintuitive.
I would have expected 1 zip (funcThree.zip) to be uploaded, which would be in line with the actual code change (FuncThree being the only one that was changed, as confirmed by CFN versioning only FuncThree).
I'm not sure if that's something that can be improved to be more consistent or if it is the intended behavior or some kind of restriction/limitation.
Looking forward to hearing back from you.
Are you using integration with Serverless Dashboard (do you have org and app configured in your config file)?
No.
Could you check the zip files and determine if only the one for funcThree in your case changed?
My AWS Sandbox where I tested this is gone. I may not be able to get to setting it up in the next few days, but will keep you posted once I get a definitive confirmation which zips have actually changed.
I can give you a ci/cd log snippet for a previous run, and only funcThree zip size is different.
Serverless: Uploading service funcOne.zip file to S3 (944 B)...
Serverless: Uploading service funcTwo.zip file to S3 (681 B)...
Serverless: Uploading service funcThree.zip file to S3 (311 B)...
Namely, 311 B vs 309 B in the subsequent commit/deployment for funcThree, whereas funcOne and funcTwo zip sizes did not change.
If we suspect that 3 zips are uploaded because all 3 did indeed change, then how come only one function got a new version (based on CFN-related logs) and not all 3?
Not sure how much the zip size comparison helps, but I will try to set it up again later this week, test it a bit more and compare zips more carefully to be more precise.
I believe it would be great to not reupload packages that did not change at all by comparing remote hashes of zip packages beforehand, however, given that we have some work planned on changing how packaging logic works, I'm not sure if this is the best time to introduce smaller changes to the logic as this one. @medikoo What is your opinion here?
Thanks for confirming this, @pgrzesik!
I've seen several issues discussing packaging/upload optimizations, but wanted to share this scenario and provide some logs/outputs.
Please feel free to close it as a duplicate if you wish, and I will continue to keep an eye on the other related issue(s).
Cheers!
Thanks a lot @medikoo - I did not find the related issue and it's indeed a duplicate of this one. As for the rollback - to be honest I was not aware of how that feature works in details but you're right that in current form the change I'm proposing is going to break it so that's a no-go.
I think the approach outlined in the linked issue is probably the best way to go, however, if I'm not mistaken also require adjustments to how our current rollback feature works. I think we should continue further discussion in the #8666 so I'm going to close this one.
Activity
pgrzesik commentedon Jul 12, 2021
Hello @bojanraic, thanks for reporting. Could you please share a reproducible example? At the moment we're detecting if zip did no change and if that's the case it's not re-uploaded. Could you check if in fact the zips for your individually packed functions are not changing?
bojanraic commentedon Jul 12, 2021
Hi @pgrzesik, thanks for the reply.
I will include some code and log snippets from a test project a while back. Hope that will help.
Serverless version: 2.46.0
Change that triggered the deployment:
Showing 1 changed file with 2 additions and 2 deletions.+2 −2 src/func-03/handler.jsCI/CD Output
Here layer upload is skipped, but all 3 function zips are uploaded
And then in CFN, only
FuncThreegets versioned, which is good.So the behavior of uploading packaged artifacts vs actually updating AWS resources is a bit counterintuitive.
I would have expected 1 zip (
funcThree.zip) to be uploaded, which would be in line with the actual code change (FuncThreebeing the only one that was changed, as confirmed by CFN versioning onlyFuncThree).I'm not sure if that's something that can be improved to be more consistent or if it is the intended behavior or some kind of restriction/limitation.
Looking forward to hearing back from you.
pgrzesik commentedon Jul 12, 2021
Thanks for additional details @bojanraic 👍 Two additional questions:
organdappconfigured in your config file)?funcThreein your case changed?I'll try to reproduce your problem and will report back with my findings.
bojanraic commentedon Jul 13, 2021
Thanks for your reply. See my answers below.
No.
My AWS Sandbox where I tested this is gone. I may not be able to get to setting it up in the next few days, but will keep you posted once I get a definitive confirmation which zips have actually changed.
I can give you a ci/cd log snippet for a previous run, and only
funcThreezip size is different.Namely,
311 Bvs309 Bin the subsequent commit/deployment forfuncThree, whereasfuncOneandfuncTwozip sizes did not change.If we suspect that 3 zips are uploaded because all 3 did indeed change, then how come only one function got a new version (based on CFN-related logs) and not all 3?
Not sure how much the zip size comparison helps, but I will try to set it up again later this week, test it a bit more and compare zips more carefully to be more precise.
Thanks.
pgrzesik commentedon Jul 14, 2021
Thanks a lot @bojanraic - I've managed to reproduce your exact issue and while we compare hashes of already uploaded files, including zip packages (
serverless/lib/plugins/aws/deploy/lib/checkForChanges.js
Line 142 in a04a714
serverless/lib/plugins/aws/deploy/lib/uploadArtifacts.js
Line 143 in a04a714
serverless/lib/plugins/aws/deploy/lib/uploadArtifacts.js
Line 129 in a04a714
I believe it would be great to not reupload packages that did not change at all by comparing remote hashes of zip packages beforehand, however, given that we have some work planned on changing how packaging logic works, I'm not sure if this is the best time to introduce smaller changes to the logic as this one. @medikoo What is your opinion here?
medikoo commentedon Jul 14, 2021
@pgrzesik I think the only reliable fix to that is addressing #8666 (and I consider this issue as duplicate of that)
As not uploading some files will break our rollback feature, or do you see some way to do that in non-breaking way?
bojanraic commentedon Jul 14, 2021
Thanks for confirming this, @pgrzesik!
I've seen several issues discussing packaging/upload optimizations, but wanted to share this scenario and provide some logs/outputs.
Please feel free to close it as a duplicate if you wish, and I will continue to keep an eye on the other related issue(s).
Cheers!
pgrzesik commentedon Jul 15, 2021
Thanks a lot @medikoo - I did not find the related issue and it's indeed a duplicate of this one. As for the
rollback- to be honest I was not aware of how that feature works in details but you're right that in current form the change I'm proposing is going to break it so that's a no-go.I think the approach outlined in the linked issue is probably the best way to go, however, if I'm not mistaken also require adjustments to how our current
rollbackfeature works. I think we should continue further discussion in the #8666 so I'm going to close this one.Thanks once again @bojanraic for reporting 🙇