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.

(aws-ecr-assets): DockerImageAsset fails to upload to ECR as the repo is not created

See original GitHub issue

When 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

  1. Delete the stack
  2. Manually create an ECR repo with the name, cdk-<xxxx>-container-assets-<account>-<region> as specified in the error message.
  3. 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:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

7reactions
vzolincommented, Apr 14, 2022

I had the same issue, my workaround was deleting CDKToolkit from CloudFormation and it’s S3 bucket and then bootstraping again.

4reactions
sbinyangcommented, Dec 18, 2020

Hi, I’m also seeing a similar issue while trying to create a lambda function using the new DockerImageFunction:

const fn = new lambda.DockerImageFunction(this, "AssetFunction", {
      code: lambda.DockerImageCode.fromImageAsset(path_to_src),
});

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.



Failure: Error: No ECR repository named 'cdk-{xxxx}-container-assets-{account}-{‘region} in account {account}. Is this account bootstrapped?
Read more comments on GitHub >

github_iconTop Results From Across the Web

class DockerImageAsset (construct) · AWS CDK
An asset that represents a Docker image. The image will be created in build time and uploaded to an ECR repository. Example. import...
Read more >
aws cdk push image to ecr - Stack Overflow
The CLI will not create the repository any more, it must already exist. ... custom ECR repository at (aws-ecr-assets) ecr-deployment #12597.
Read more >
@aws-cdk/aws-ecr-assets - npm
Images are built from a local Docker context directory (with a Dockerfile ), uploaded to Amazon Elastic Container Registry (ECR) by the CDK ......
Read more >
AWS ECR - Push Successful, Image Does Not Appear in Repo
We have noticed that the AWS ECR Repositories Console does not list recently pushed/tagged images in real time.
Read more >
@aws-cdk/aws-ecr-assets | Yarn - Package Manager
Images are built from a local Docker context directory (with a Dockerfile ), uploaded to Amazon Elastic Container Registry (ECR) by the CDK...
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