[ECR] Fails to deploy if ECR repository already exists
See original GitHub issueReproduction Steps
import cdk = require('@aws-cdk/core');
import ecr = require('@aws-cdk/aws-ecr');
export class EcrStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const ecrRepo = new ecr.Repository(this, 'MyECRRepo', {
repositoryName: 'my-ecr-repo'
});
new cdk.CfnOutput(this, 'MyECRRepoURI', {
value: ecrRepo.repositoryUri,
});
}
}
Error Log
I see an error state the ECR Repository with name my-ecr-repo
already exists and the CFN deployment cancels and rolls back.
Environment
- CLI Version :1.16.3
- Framework Version: 1.16.3
- OS : macOS
- **Language : typescript **
Other
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 4 years ago
- Reactions:9
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Troubleshooting Amazon ECR error messages
HTTP 404: "Repository Does Not Exist " error For more information about creating repositories, see Amazon ECR private repositories. To use the Amazon...
Read more >Create AWS ECR repository if it doesn't exist - Stack Overflow
One liner to create a repo if it doesn't exist (or the describe command fails for any other reason): aws ecr describe-repositories ......
Read more >Found out that CDK throws an error if the resource already ...
Lo and behold AWS starts screaming at me in caps that ECR repo with a matching name already exists. It then rolls everything...
Read more >circleci/aws-ecr@8.2.1
Should the repo be created if it does not exist? ... Whether to skip image building if all specified tags already exist in...
Read more >"Already exists in stack" error when attempting to re-deploy a ...
I had the same issue. It was caused by an earlier development stage where I'd created my s3 bucket manually. Removing the s3...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@rix0rrr Could you provide a best-practice on how to approach a situation like this?
E.g. we want to setup a pipeline that pushes to ECR and have our deployment pull from ECR. Of course we can’t delete the repository when the pipeline is removed nor use dynamic names for the ECR as our deployment depends on this. Hence we would choose static names and only create a new ECR repository in the pipeline if one with the name doesn’t exist.
One common workaround found online is to query the ecr for existing repos, however this approach is of course not safe due to the async nature of synth and deploy. Furthermore this would introduce an anti-pattern as referenced here: https://github.com/aws/aws-cdk/issues/8273
Would this be addresses by the context provider framework?
Judging from the comments here and elsewhere, this seems like a common use case.
I’d be very curious to hear how this should ideally be approached.
Correct, this is the only place I specify a name.
I would imagine resource update would be skipped if the name is the same as the existing resource especially when nothing on the resource has changed in the updated template.
That seems like a CloudFormation issue in that case.