(cdk deploy): cdk deploy fails when shared assets are deployed to different accounts because Docker assets are not built locally for all targets #26446
Labels
@aws-cdk/assets
Related to the @aws-cdk/assets package
bug
This issue is a bug.
effort/medium
Medium work item – several days of effort
p2
Describe the bug
What is the issue?
In version
2.87.0
of theAWS CDK CLI
Docker assets are not properly built locally and assets push toAmazon ECR
fails. This happens when Docker assets are shared between stacks that are deployed to different accounts.Deployment fails with the following error:
Deployment with version
2.79.1
is fine. These findings are related to a change in the asset deployment with recentAWS CLI
versions.What is the impact?
If a
CDK
app contains two stacks deployed to different accounts that use the same asset, thecdk deploy
command would fail because local assets are not built for all target accounts.Who is affected?
Recent
CDK
versions for example version2.87.0
.How do I resolve this?
Work around with the recent
AWS CDK CLI
is to force asset build using theextraHash
functionality. This work around can be complex for customers deploying several stacks sharing assets. Good choice for theextraHash
parameter string is thetarget account id
to avoid unnecessary rebuild of assets deployed to the same account.Customers need to explicitly force asset build with extra flags while this was the default behavior with older
AWS CDK CLI
versions.Additional information
This ticket has been opened as documentation for customers having similar issues and to guide for a proper work around. It would be nice to restore the previous
AWS CDK
functionality or provide an explanation of the reasons of this change.Expected Behavior
Running
cdk deploy
should create/update CloudFormation stacks.Current Behavior
The following is the output from a
cdk deploy
run that should have triggeredcdk
to create the app's stacks in CloudFormation.Reproduction Steps
CDK
app folder structure:Content of
jest.config.js
:Content of
tsconfig.json
:Content of
package.json
:Content of
source/index.js
:Content of
cdk.json
:Content of
Dockerfile
:Content of
bin/cdk-app.ts
:Similar project and code structure is in the Reproduction Steps of issue #25714.
Run
npm install
to generate thepackage-lock.json
and install the npm packages locally.For the deployment to multiple target accounts make sure to execute
cdk bootstrap
setting the flags--trust
and--cloudformation-execution-policies
.Run
npx cdk deploy --all --require-approval never
to reproduce the issue.Possible Solution
Introduce
extraHash
to force asset rebuild when same asset has to be locally built and deployed to multiple target accounts.Content of
bin/cdk-app.ts
:Additional Information/Context
Test deployment with
AWS CDK
version2.79.1
changing the version in the filepackage.json
:Install the packages
npm install
and runnpx cdk deploy --all --require-approval never
to check that deployment is successful with the olderAWS CDK
version.CDK CLI Version
2.87.0 (build 9fca790)
Framework Version
No response
Node.js Version
v18.16.1
OS
OS X & Ubuntu & Amazon Linux 2
Language
Typescript
Language Version
5.1.6
Other information
Thanks for the hard work on CDK! I'm a very happy user.
The text was updated successfully, but these errors were encountered: