(aws-ecr-assets): DockerImageAsset fails to upload to ECR as the repo is not created
See original GitHub issueWhen creating a DockerImageAsset
like below…
const asset = new aws_ecr_assets.DockerImageAsset(this, "MyAsset", {
directory: path.join(SRC_DIR),
});
The image is created successfully at build time, however it fails to upload to an ECR repository. When the task enters a “stopped” status, the following error is reported.
Status reason CannotPullContainerError: Error response from daemon:
repository XXXX.dkr.ecr.us-west-2.amazonaws.com/cdk-<xxxx>-container-assets-<account>-<region>
not found: name unknown: The repository with name 'cdk-<xxxx>-container-assets-<account>'
It fails because the repo it’s trying to publish to does not exist. It was never created.
What did you expect to happen?
The ECR repository referenced in the error message e.g XXXX.dkr.ecr.us-west-2.amazonaws.com/cdk-<xxxx>-container-assets-<account>-<region>
would have been be created by CDK and subsequently the image would successfully upload to that ECR repo.
What actually happened?
The upload fails since the ECR repo was not created.
Also, during stack creation the Task status continuously iterates from pending, provisioning, to stopped. Each time it reaches status, stopped, it reports the the error above, then tries again. Ulitmately, the task goes intoa loop and cannot successfully start (i waited ~40+ minutes. it’s possible that it would eventually give up).
Workaround
- Delete the stack
- Manually create an ECR repo with the name,
cdk-<xxxx>-container-assets-<account>-<region>
as specified in the error message. - Create the stack
For my use case, I refrenced the DockerImageAsset
above in the taskImageOptions
on ApplicationLoadBalancedFargateService
, like so…
new ecs_patterns.ApplicationLoadBalancedFargateService(this, 'MyTask', {
vpc,
publicLoadBalancer: true,
redirectHTTP: true,
protocol: elb.ApplicationProtocol.HTTPS,
domainName,
domainZone,
cpu: 256,
desiredCount: 2,
listenerPort: 443,
taskImageOptions: {
taskRole: apiServiceRole,
containerPort: 3000,
enableLogging: true,
image: ecs.ContainerImage.fromDockerImageAsset(asset), // <- referenced asset here
containerName: 'api-server',
},
loadBalancer,
memoryLimitMiB: 512,
});
Environment
- **CDK CLI Version :1.76.0 (build c207717)
- Framework Version:: 1.77.0
- Node.js Version:: v14.9.0
- OS : MacOS
- Language (Version):: TypeScript (3.9.7)
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:13 (6 by maintainers)
Top GitHub Comments
I had the same issue, my workaround was deleting CDKToolkit from CloudFormation and it’s S3 bucket and then bootstraping again.
Hi, I’m also seeing a similar issue while trying to create a lambda function using the new DockerImageFunction:
The image also created successfully at build, but failed to upload to an ECR repo with the following error. I ran it again after bootstrapping the account and it did not fix the issue.