-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(aws-lambda-python): Change assetHashType to cdk.AssetHashType.SOURCE #12770
Comments
When a Python handler uses external dependencies, the hash calculated on the output is non-determinstic due to the fact that it includes timestamps. To resolve that, change the asset hash strategy to `SOURCE` which means that the bundle will only be re-created if one of the source files changes. Fixes #12770 Fixes #12684
Would the fix for this also address aws-lambda-nodejs? As seen in #11625 (comment), node js lambda functions always end up being rebuilt as well. |
@TLadd no, the current PR only addresses the python lambdas. But for nodejs the same approach would work: aws-cdk/packages/@aws-cdk/aws-lambda-nodejs/lib/bundling.ts Lines 37 to 42 in 7dc45b2
Currently we are discussing the best solution to this in the PR #12984 |
When a Python handler uses external dependencies, the hash calculated on the output is non-determinstic due to the fact that it includes timestamps. To resolve that, change the asset hash strategy to `SOURCE` which means that the bundle will only be re-created if one of the source files changes. Additionally, the Python image hash, which is also included in the asset hash (to ensure that if the build image changes, the bundle is invalidated) included the absolute path for the `Dockerfile`. This caused the image hash itself to change every time the image was built on a different system. To fix this, we stage the dependency files & dockerfile into a temp directory and build the image from there. Fixes #12770 Fixes #12684 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
|
I noticed that my lambda layers get rebuild everytime I run the cdk.
Becaus the current implementation defines
cdk.AssetHashType.BUNDLE
it has some side effects if dependencies change. I can mitigate the side effects by specifining the versions in therequirements.txt
e.g.pandas==1.1.*
but still it always bundles the layer even if nothing changes.I would propose to change the
assetHashType
toSOURCE
especially becauseBUNDLE
is deprecated and the suggested change toOUTPUT
would still have the described side effects mentioned above.aws-cdk/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts
Line 65 in 7dc45b2
That would also solve #12684
The text was updated successfully, but these errors were encountered: