fix: stackset template asset keys diverge from the objects the asset bucket deployment uploads#896
Open
dannysteenman wants to merge 1 commit into
Open
Conversation
…bucket deployment uploads The template's S3 object key was derived from the hash embedded in the staged asset file name, while the BucketDeployment uploads the asset under the re-staged content fingerprint (Source.asset + extract: false). For assets staged with an explicit assetHash - such as the aws-cdk-lib custom-resource handler assets since v2.258.0 (aws/aws-cdk#37634) - the two hashes diverge and stack instances fail with S3 NoSuchKey. Derive the template key from the same content fingerprint the upload uses. Fixes cdklabs#895
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #895
Problem
Deploying a
StackSetwhoseStackSetStackcontains anAwsCustomResource(or any construct backed by an aws-cdk-lib custom-resource handler) fails on every stack instance with:StackSetStackSynthesizer.addFileAsset()derives the template's S3 object key from the hash embedded in the staged asset file name:But the object that actually lands in the asset bucket is uploaded by the
BucketDeploymentcreated in the same method:Source.asset(assetPath)re-stages the staged asset and computes a fresh content fingerprint, and withextract: falsethe destination object key is that fingerprint — not the hash in the staged file name.These two keys are only identical when the original asset's hash is the plain content fingerprint. That implicit assumption broke with aws-cdk-lib 2.258.0: aws/aws-cdk#37634 ("custom-resource-handlers: deterministic asset hashes for generated lambdas") stages all generated custom-resource handler assets with an explicit
assetHash, e.g.:I verified the regression window release by release: the generated handlers in aws-cdk-lib 2.254.0–2.257.0 contain no
assetHash; 2.258.0 is the first version that does. Concrete values from a real deployment on 2.258.1:cdk.out/asset.8b1c21ef...(derived from the customassetHash)Code.S3Key:8b1c21ef....zip→ never uploaded →NoSuchKeyBucketDeployment:0528c009....zip(=FileSystem.fingerprint()of the staged directory)Fix
Derive the template's object key the same way
Source.asset()does, so the two can never diverge:For assets whose hash already is the content fingerprint (plain directory assets, pre-zipped bundled assets such as
NodejsFunctionoutput), this produces the exact same key as before — no template churn, no re-uploads. Only custom-hash assets, which were broken, change key.Testing
lambda asset keys in the stackset template match the bucket deployment uploadssynthesizes aStackSetStackcontaining a Lambda asset with an explicitassetHashand asserts everyCode.S3Keyin the stackset template appears in the parent stack'sCustom::CDKBucketDeploymentSourceObjectKeys. It fails against the previous implementation and passes with this change.integ.stack-setsnapshot pass unchanged.NoSuchKeyon aws-cdk-lib 2.258.1 deploys successfully with this fix applied.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.