Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
cdimascio opened this issue Dec 14, 2020 · 15 comments
Labels
@aws-cdk/aws-ecr-assets Related to AWS CDK Docker Image Assets bug This issue is a bug. effort/small Small work item – less than a day of effort p1

Comments

@cdimascio
Copy link

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

@cdimascio cdimascio added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 14, 2020
@github-actions github-actions bot added the @aws-cdk/aws-ecr-assets Related to AWS CDK Docker Image Assets label Dec 14, 2020
@sbinyang
Copy link

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?

@olivboom
Copy link

+1 I'm also experiencing this issue and would appreciate a native fix within CDK instead of the given workaround.

@jmjava
Copy link

jmjava commented Feb 12, 2021

I am seeing this in both DockerImageFunction and DockerImageAsset. Are there any workarounds? I need to publish an image in my stack.

@eladb
Copy link
Contributor

eladb commented Feb 15, 2021

@cdimascio did you bootstrap your environment using cdk bootstrap with @aws-cdk/core:newStyleStackSynthesis context set to true?

@eladb eladb added p1 effort/small Small work item – less than a day of effort labels Feb 15, 2021
@eladb eladb removed their assignment Feb 25, 2021
@ryparker ryparker removed the needs-triage This issue or PR still needs to be triaged. label Jun 2, 2021
@ahammond
Copy link
Contributor

ahammond commented Dec 9, 2021

Reproduced this using CDK v2. We have never used any CDK v1 in this account.

@awhillas
Copy link

awhillas commented Mar 17, 2022

Anything happening with this? I'm still getting the massage after bootstrapping multiple times :(
When i bootstrap i get this message:

Trusted accounts for deployment: (none)
Trusted accounts for lookup: (none)
Using default execution policy of 'arn:aws:iam::aws:policy/AdministratorAccess'. Pass '--cloudformation-execution-policies' to customize.

Should i supply --cloudformation-execution-policies? What are the options here? SHould the "Trusted accounts" not be None?

@DJ-Icebear
Copy link

DJ-Icebear commented Apr 7, 2022

Our team is also having this issue. And if I understand correctly there no way to specify to which repo a built image is published when using ecs.ContainerImage.fromAsset(...)?

@vzolin
Copy link

vzolin commented Apr 14, 2022

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

@corymhall
Copy link
Contributor

This should not be an issue currently as long as you have bootstrapped your account. We have other issues tracking adding support for pushing ECR images to a user non-bootstrap ECR repository (see #12597).

I'll leave this open for a little bit to allow for responses in case this is still an issue for anyone.

@corymhall corymhall added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Aug 12, 2022
@ibrahimcesar
Copy link
Contributor

ibrahimcesar commented Aug 14, 2022

+1 on @vzolin. I faced this issue, but while debbuging a problem, I manually deleted the ECR repo created on cdk bootstrap. Since I was not able to force a new bootstrap, I delete the previous CDKToolkit stack in CloudFormation.

I only find in the docs how to customize the bootstrap not force a override or even a full deletion of the stack and all resources since, for this work, I also had to empty and delete the S3 bucket created by cdk bootstrap.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Aug 14, 2022
@corymhall
Copy link
Contributor

@ibrahimcesar before deleting the CDKToolkit stack or manually deleting the ECR repository did you try re-bootstrapping with cdk bootstrap? If so did you receive any error messages?

There is an option to run bootstrap with --force (e.g. cdk bootstrap --force) in order to force a re-bootstrap. This can sometimes get you passed some errors.

@corymhall corymhall added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Aug 15, 2022
@ibrahimcesar
Copy link
Contributor

@corymhall I only tried bootstrap without force. I didn't get an error per se, just a notice that my account was already bootstrapped. Next time I'll try with the --force flag. Thanks!

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Aug 15, 2022
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@abury
Copy link

abury commented Feb 7, 2023

I've come across this issue after starting a second CDK project. We bootstrapped in the first project, but that project didn't require a default ECR, so It wasn't created. Now trying to build this one with a new lambda.DockerImageFunction and seeing the error fail: No ECR repository named ....

Tried bootstrapping and force bootstrapping, neither have succeeded in creating the default ECR.. Nuking the original CDKToolkit CF Stack and s3 bucket and re-bootstrapping resolved the issue.

@willredington
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ecr-assets Related to AWS CDK Docker Image Assets bug This issue is a bug. effort/small Small work item – less than a day of effort p1
Projects
None yet
Development

No branches or pull requests