[assets] layer and function assets bundled through lambda.Code.fromAsset bundling option keep getting re-uploaded and new versions published despite nothing having changed
See original GitHub issueI have a lambda function that uses two lambda layers to optimize for my use case (slow upload speed where I live).
It contains 3 assets:
- layer asset for ‘other’ jars (the third party dependencies that get changed the least often)
const otherDepsLayer = new lambda.LayerVersion(this, 'OtherJars', {
compatibleRuntimes: [props.runtime],
code: lambda.Code.fromAsset(props.basePath, {
bundling: {
image: props.runtime.bundlingDockerImage,
volumes: [m2Volume],
command: ['bash', '-c', otherDepsCommand],
},
}),
});
- layer asset for ‘our’ jars (the other modules in a maven reactor project that may have a higher rate of change)
const ourDepsLayer = new lambda.LayerVersion(this, 'OurJars', {
compatibleRuntimes: [props.runtime],
code: lambda.Code.fromAsset(props.basePath, {
bundling: {
image: props.runtime.bundlingDockerImage,
volumes: [m2Volume],
command: ['bash', '-c', ourDepsCommand],
},
}),
});
- lambda function classes asset (the module with the highest rate of change when I develop it)
this.lambdaFunction = new lambda.Function(this, "Function", {
...props,
layers: [otherDepsLayer, ourDepsLayer],
code: lambda.Code.fromAsset(props.basePath, {
bundling: {
image: props.runtime.bundlingDockerImage,
volumes: [m2Volume],
command: ['bash', '-c', commandToBundleClasses],
},
}),
})
When I run cdk deploy
twice in a row (within modifying anything in between), I expect:
- the ‘other’ jars asset not be uploaded, no new layer version to be created
- the ‘our’ jars asset not be uploaded, no new layer version to be created
- the lambda function classes assets not to be uploaded, no new lambda function to be created
- no new asset.* directory to be created in cdk.out
What happens
- the ‘other’ jars asset is uploaded again (it says
start: Publishing
thensuccess: Published
) - a new ‘other’ jars layer version is created
- the ‘our’ jars asset is uploaded again (it says
start: Publishing
thensuccess: Published
) - a new ‘our’ jars layer version is created
- the lambda function classes assets is uploaded again (it says
start: Publishing
thensuccess: Published
) - a new lambda function version is created
I was going to spend time making sure ‘our’ jars are created in a reproducible manner to ensure the checksums are always the same. But that will be for nought if there is no intelligence in the CDK for asset content deduplication.
This is already how SAM CLI works, so I’d expect CDK to have the same behaviour.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top Results From Across the Web
aws-cdk/aws-lambda module - AWS Documentation
To produce a new lambda version each time the lambda function is modified, the currentVersion property under the hood, computes a new logical...
Read more >Creating Lambda Layers with TypeScript and CDK
First we're setting up the Lambda Layer, and using Code.fromAsset to grab the code we made for the layer. Next we're setting up...
Read more >How to install external modules in a Python Lambda Function ...
new Function (this, 'Function', { code: Code.fromAsset(path.join(__dirname, 'my-python-handler'), { bundling: { ...
Read more >5 Ways To Bundle a Lambda Function Within an AWS CDK ...
Have you ever tried to publish a CDK construct that was using a Lambda function, for example to create a custom resource or...
Read more >How to Create AWS CDK Lambda Functions? 4 Easy Steps
This article provides you with a stepwise guide to easily create and deploy your AWS CDK Lambda function.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry for the delay. Adding
AssetHashType.Bundle
helps. But it feels counter intuitive to have to specify this when someone is usingbundling
right next to it. Shouldn’t the very presence of thebundling
property swich the AssetHashType toBundle
by default?I guess I don’t understand the difference between SOURCE and BUNDLE yet (or I kinda do, but I think the way it’s explained is insufficient and / or misleading).
The API documentation for AssetHashType should really explain what’s going on, and why one would want to use one vs the other. The optimal answer will vary based on the runtime for example, so that even choosing a default for the user is fraught for risks.
Documentation: