Skip to content
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

Closed
fsmanuel opened this issue Jan 29, 2021 · 3 comments · Fixed by #12984
Closed

(aws-lambda-python): Change assetHashType to cdk.AssetHashType.SOURCE #12770

fsmanuel opened this issue Jan 29, 2021 · 3 comments · Fixed by #12984
Assignees
Labels
@aws-cdk/aws-lambda-python bug This issue is a bug. effort/small Small work item – less than a day of effort in-progress This issue is being actively worked on. needs-triage This issue or PR still needs to be triaged. p1

Comments

@fsmanuel
Copy link

fsmanuel commented Jan 29, 2021

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 the requirements.txt e.g. pandas==1.1.* but still it always bundles the layer even if nothing changes.

I would propose to change the assetHashType to SOURCE especially because BUNDLE is deprecated and the suggested change to OUTPUT would still have the described side effects mentioned above.

assetHashType: cdk.AssetHashType.BUNDLE,

That would also solve #12684

@fsmanuel fsmanuel added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 29, 2021
eladb pushed a commit that referenced this issue Feb 11, 2021
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
@eladb eladb added effort/small Small work item – less than a day of effort in-progress This issue is being actively worked on. p1 labels Feb 15, 2021
@TLadd
Copy link
Contributor

TLadd commented Feb 19, 2021

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.

@fsmanuel
Copy link
Author

@TLadd no, the current PR only addresses the python lambdas. But for nodejs the same approach would work:

public static bundle(options: BundlingProps): AssetCode {
return Code.fromAsset(path.dirname(options.depsLockFilePath), {
assetHashType: cdk.AssetHashType.OUTPUT,
bundling: new Bundling(options),
});
}

Currently we are discussing the best solution to this in the PR #12984

@mergify mergify bot closed this as completed in #12984 Feb 24, 2021
mergify bot pushed a commit that referenced this issue Feb 24, 2021
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*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda-python bug This issue is a bug. effort/small Small work item – less than a day of effort in-progress This issue is being actively worked on. needs-triage This issue or PR still needs to be triaged. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants