简体   繁体   中英

AWS CDK - How do I create ECR repo conditionally

Using the AWS CDK STACK how do I check and create a ECR repository if it does not exist. In other words how I do check if the ECR repository with a specific name(for example "TestRepository") already exists.

The code to create new rep:

 this.TestRepository = new Repository(this, "TestRepository", new RepositoryProps
        {
            RepositoryName = "TestRepository"
        });

When I try to deploy the stack again(redeploy) it shows error repository with the name already exists

So in order to avoid this error how I do check if the ECR repository with a specific name(for example "TestRepository") already exists...I am looking for something like UPSERT

I know to handle this scenario with Terraform but not used CDKTF but seems like this one should work. Please refer https://loige.co/create-resources-conditionally-with-cdk

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM