aws-cdk
aws-cdk copied to clipboard
(ecr): add option to auto delete images upon ECR repository removal
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
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.
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.
@kirintwn any chance we can publish your branch if it's fully working ? we need this feature terribly.
@MrArnoldPalmer is there anyway the CDK team can help on publishing this feature ?
Hi @heiba , I have updated my branch, added more tests & opened a PR #15932.
Any update or workaround for this?
do we have any updates on this feature?
This would be very nice. Constantly running into issues because of lack of this.
We would really appreciate such an option!
We really need this feature as well, would be a huge help
please add this feature
indeed, please add.
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.
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.
⚠️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.
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)
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?