question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

S3 Deployment Assets with tokens result in different source object keys for zipped asset.

See original GitHub issue

I’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:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
OrEisenbergcommented, Sep 13, 2021

@eladb Ah yes, these tokens were getting resolved due to some hacky stuff on our end of which I was unaware. !מצטער מאוד על הצרות

0reactions
eladbcommented, Sep 14, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

aws-cdk/aws-s3-deployment module - AWS Documentation
The source bucket/key is set to point to the assets bucket. The custom resource downloads the .zip archive, extracts it and issues aws...
Read more >
@aws-cdk/aws-s3-deployment | Yarn - Package Manager
The source bucket/key is set to point to the assets bucket. The custom resource downloads the .zip archive, extracts it and issues aws...
Read more >
aws_s3_bucket_object | Resources | hashicorp/aws
Provides an S3 object resource. Example Usage. Uploading a file to a bucket. resource "aws_s3_bucket_object" "object" { ...
Read more >
@aws-cdk/pipelines - npm
There are 29 other projects in the npm registry using @aws-cdk/pipelines. ... By default, the source object will look for a secret named...
Read more >
Metadata API Developer Guide
Deploying and Retrieving Metadata with the Zip File . ... To translate different languages for your objects, you include.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found