aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

(ecr): add option to auto delete images upon ECR repository removal

Open kirintwn opened this issue 4 years ago • 9 comments

Use Case

ECR repositories currently do not get delete if they contain images even the removalPolicy is set to DESTROY.

It was reported in #2765, and was thought to be a responsibility of CloudFormation team https://github.com/aws-cloudformation/aws-cloudformation-coverage-roadmap/issues/515.

Proposed Solution

I do think we should add a option to force delete the images using custom resource provider, which is just like #12090 that uses a custom resource provider to delete objects in s3.

The code might looks like this:

const bucket = new ecr.Repository(this, 'Repo', {
  repositoryName: 'delete-even-if-contains-images',
  removalPolicy: cdk.RemovalPolicy.DESTROY,
  autoDeleteImages: true,
});

The props autoDeleteImages can only to be true if removalPolicy is set to DESTROY.

Other

  • [x] :wave: I may be able to implement this feature request
  • [ ] :warning: This feature might incur a breaking change

This is a :rocket: Feature Request

kirintwn avatar Jan 20 '21 09:01 kirintwn

I have created a branch to show how it works. Note that the unit tests are not completed because I think we better wait until #12620 get merged.

kirintwn avatar Jan 21 '21 10:01 kirintwn

hey @kirintwn, would you be interested in publishing this as a separate module? There definitely is a need and it would be a good way to get some users testing it before merging into the CDK. It may be possible to extend the existing ecr.Repository class and intercept this prop and then create the custom resource.

MrArnoldPalmer avatar May 17 '21 23:05 MrArnoldPalmer

@kirintwn any chance we can publish your branch if it's fully working ? we need this feature terribly.

heiba avatar Aug 07 '21 06:08 heiba

@MrArnoldPalmer is there anyway the CDK team can help on publishing this feature ?

heiba avatar Aug 07 '21 06:08 heiba

Hi @heiba , I have updated my branch, added more tests & opened a PR #15932.

kirintwn avatar Aug 07 '21 08:08 kirintwn

Any update or workaround for this?

nemmison avatar May 04 '22 12:05 nemmison

do we have any updates on this feature?

mikaeelkhalidnbs avatar Jul 06 '22 13:07 mikaeelkhalidnbs

This would be very nice. Constantly running into issues because of lack of this.

JessieWadman avatar Sep 10 '22 11:09 JessieWadman

We would really appreciate such an option!

MikeGongolidis avatar Sep 22 '22 12:09 MikeGongolidis

We really need this feature as well, would be a huge help

kushal-ti avatar Oct 13 '22 07:10 kushal-ti

please add this feature

ozgenbaris1 avatar Nov 02 '22 10:11 ozgenbaris1

indeed, please add.

amirse avatar Nov 10 '22 07:11 amirse

To whoever ends up implementing this, be mindful of this issue: https://github.com/aws/aws-cdk/issues/16603 We don't want to end up with the same problem.

madeline-k avatar Jan 24 '23 23:01 madeline-k

This issue has received a significant amount of attention so we are automatically upgrading its priority. A member of the community will see the re-prioritization and provide an update on the issue.

github-actions[bot] avatar Jan 29 '23 00:01 github-actions[bot]

⚠️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.

github-actions[bot] avatar Mar 21 '23 23:03 github-actions[bot]

Tested this feature this morning with cdk 2.70.0. I am still seeing the error

Resource handler returned message: "The repository with name 'test-app' in registry with id '1234567890' 
cannot be deleted because it still contains images (Service: Ecr, Status Code: 400,
Request ID: 842c370d-f12344XXXXX-ed47d07f0443)" 
(RequestToken: c64e0c80-9xxxxxxca5006c6c, HandlerErrorCode: GeneralServiceException)

missourian55 avatar Mar 26 '23 16:03 missourian55

This is now supported by CloudFormation https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecr-repository.html#cfn-ecr-repository-emptyondelete

Do we still need this custom resource?

markmansur avatar Dec 02 '23 03:12 markmansur