-
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
feat(lambda-python-alpha): cache python lambda dependencies usig lambda layer #30157
feat(lambda-python-alpha): cache python lambda dependencies usig lambda layer #30157
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.
A comment requesting an exemption should contain the text Exemption Request
. Additionally, if clarification is needed add Clarification Request
to a comment.
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Exemption Request This is a first PR for me in this codebase, i have the general idea of the design and the required code changes, and could use some help with the PR process |
This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week. |
This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error. |
The pull request linter fails with the following errors:
PRs must pass status checks before we can provide a meaningful review. If you would like to request an exemption from the status checks or clarification on feedback, please leave a comment on this PR containing ✅ A exemption request has been requested. Please wait for a maintainer's review. |
Issue # (if applicable)
Closes #23829
Reason for this change
cdk synth takes very long to synthesize a
PythonFunction
construct, because the dependencies are getting installed regardless if there was any changes made to them.The dependencies, whether they are specified in a
requirements.txt
file, apoetry.lock
file or apipenv.lock
file, get installed as part of theCMD
in the bundling phase, meaning that we don't use docker's cache or any other caching mechanism and re-install the dependencies from the internet every time.Trying to compute a custom
assetHash
based on the dependencies file won't work, because of where the call for install is currently placed (in theCMD
of the bundling phase container)This causes deployment times to rise significantly, in some cases from minutes to hours.
Description of changes
The PythonFunction construct in
function.ts
will introduce a new prop:layer
which is defined as:If
layer
is true, we create the layer before the constructor ofPythonFunction
is called, and attach the layer to PythonFunction in the constructor'slayers
prop.To control whether dependencies are installed during the Bundling phase, a new prop is introduced to
BundlingOptions
and is defined as:Since bundling is used for the PythonLayerVersion and PythonFunction props, this prop defaults to true, to not alter any behavior of PythonLayerVersion.
When initializing a PythonFunction, if
layer
is true, and we are creating a layer, theinstallDependencies
is set to true for the layer creation, and false for the constructor of PythonFunction, so dependencies will only be installed in the layer.To compute the assetHash for the layer, I added a
dependenciesHash(entry)
method inside thePackaging
class, with this we can compute the hash of the lock file, and in the created layer we can useAssetHashType.CUSTOM
with this hash.Description of how you validated changes
This is my first PR here, and in open source in general, I am working on adding and validating the changes with unit tests, I would appreciate some help with that, if possible.
Checklist
TODOs
README.md
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license