aws_lambda: Only update Docker image based Lambdas when changes occur #23038
Labels
@aws-cdk/aws-lambda
Related to AWS Lambda
duplicate
This issue is a duplicate.
feature-request
A feature should be added or improved.
Describe the feature
cdk deploy
is pretty insistent on pushing new Docker images and updating Lambdas every time it is run - even if the contents of the Docker images haven't changed.CDK could instead only push new images and Lambda updates when changes have occurred, reducing the amount of deployment work that is done.
Use Case
We have a CDK stack with a few dozen Lambdas, defined via
aws_lambda.DockerImageCode.from_image_asset
, all pointing to a local Dockerfile.Our CI/CD system currently takes 10-15 minutes to run
cdk deploy
, mostly spent on updating all defined Lambdas with every deployment, regardless of whether a new image needed to be built or not. This is despite caching thecdk.out
directory and pushing/pulling the Docker images for the Lambdas to an external repository as part of the build process.While Docker realises that there are no changes (i.e. it outputs
CACHED
for all steps in the Dockerfile, both when runningdocker build
andcdk deploy
), it has proven challenging to stop CDK from pushing the images as if they were new each time. It appears that CDK is unable to determine that no changes need to be pushed.If CDK could selectively update Lambdas, this would significantly improve our deploy time - often, only a single Lambda is affected and needs updating.
Proposed Solution
CDK caches, stores, or references Docker images in some way which mean that identical images (at least, as seen by Docker) do not get re-submitted as a new version of the Lambda each time.
Other Information
A potential alternative is that we build the Docker images outside of CDK, pushing them to ECR, and passing the tags through to CDK. However, this is a very heavyweight solution that requires us to re-implement much of the Docker image management that CDK undertakes.
Acknowledgements
CDK version used
2.44.0
Environment details (OS name and version, etc.)
CI/CD workers running Ubuntu-20.04
The text was updated successfully, but these errors were encountered: