Open igirardi opened 1 year ago
I receive a similar error when using publishing a single docker image to multiple regions in the same account via a TarballImageAsset construct.
ecs.ContainerImage.fromTarball(path.join(__dirname, "..", "..", "..", "apps", "api", "image.tar")),
Regions: us-east-1 and us-west-2
Error:
fail: docker push XXXXXXXXXX.dkr.ecr.us-west-2.amazonaws.com/cdk-hnb659fds-container-assets-XXXXXXXXXX-us-west-2:16a6587ca24fb32b32d096b40b6d2a99615c0320829bbe41dc76861ba859b1dd exited with error code 1: tag does not exist: XXXXXXXXXX.dkr.ecr.us-west-2.amazonaws.com/cdk-hnb659fds-container-assets-XXXXXXXXXX-us-west-2:16a6587ca24fb32b32d096b40b6d2a99615c0320829bbe41dc76861ba859b1dd
Using an older version of the CDK ^2.70.0 fixes the issue as previously mentioned by @igirardi. However, I want to use the latest CDK version for other reasons.
Related: #25962
Thank you @tmokmss for the insights https://github.com/aws/aws-cdk/issues/25962#issuecomment-1633154332
As a workaround I have cleared all docker cache locally via the following commands which forces to rebuild images and push to AWS ECR.
docker rmi $(docker images -a --filter=dangling=true -q)
docker rm $(docker ps --filter=status=exited --filter=status=created -q)
docker system prune -a
As of November 2024 and cdk version 2.166.0 I'm seeing the same error as @naataaniitsosie. Is there a way to use the extrahash parameter with the fromTarball() method as suggested in https://github.com/aws/aws-cdk/issues/25962?
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 olderAWS 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 https://github.com/aws/aws-cdk/issues/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.