S3 Deployment Assets with tokens result in different source object keys for zipped asset.
See original GitHub issueI’m dynamically rendering a directory using tokens for an S3 deployment. That is, I’m creating a directory which contains files that have tokens embedded within them. I then try to use this directory as an S3 deployment Source.asset
and everything works (the tokens get rendered upon deployment) but the hash that is used as the name for the source object key for this asset changes upon each deployment. This is presumably because the name of this key is being generated by hashing the directory contents before the tokens are resolved and since the (string) tokens, prior to rendering, will have random numbers as substrings (e.g., on one run, the unresolved token will be ${Token[TOKEN.123]}
, but on a subsequent run where none of the code has changed, it will be ${Token[TOKEN.456]}
), the hash generating the name of this key ends up being different.
Reproduction Steps
bucket = aws_s3.Bucket(...)
with open('directory/file.txt', 'w') as f:
f.write(bucket.bucket_name)
other_bucket = aws_s3.Bucket(...)
bucket_deployment = aws_s3_deployment(
...,
sources=[aws_s3_deployment.Source.asset('directory'),
destination=other_bucket,
...
)
This results in the following output on runs A & B of cdk diff
(with no code changed):
[~] Custom::CDKBucketDeployment <resource-name>/CustomResource <resource-id>
└─ [~] SourceObjectKeys
└─ @@ -1,3 +1,3 @@
[ ] [
[-] "<original hash>.zip"
[+] "<new hash A>.zip"
[ ] ]
and
[~] Custom::CDKBucketDeployment <resource-name>/CustomResource <resource-id>
└─ [~] SourceObjectKeys
└─ @@ -1,3 +1,3 @@
[ ] [
[-] "<original hash>.zip"
[+] "<new hash B>.zip"
[ ] ]
Note that that is the entire diff.
Environment
- CDK CLI Version: 1.119.0
- Framework Version: 2.0.0rc18
- Node.js Version: 16.6.1
- OS: macOS Big Sur 11.4
- Language (Version): Python 3.8.11
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
@eladb Ah yes, these tokens were getting resolved due to some hacky stuff on our end of which I was unaware. !מצטער מאוד על הצרות
No worries. In fact the use case of generating content that includes deploy time values is something we are looking into.
https://github.com/aws/aws-cdk/issues/12903