繁体   English   中英

如何通过 cloudformation 删除包含图像的 aws ECR 存储库?

[英]How to delete aws ECR repository which contain images through cloudformation?

如何通过 cloudformation 删除包含图像的 aws ECR 存储库? 删除时出现以下错误。

注册表中名称为“test”且 ID 为“************”的存储库无法删除,因为它仍然包含图像

留下我使用 Python 的 boto3 客户端解决这个问题的方法。 (1) 清空存储库,然后 (2) 删除堆栈。

import boto3
ecr_client = boto3.client('ecr')
...

# Apply only to ecr cfn template
if '-ecr' in stack_name:
    print('Deleting existing images...')
    image_ids = ecr_client.list_images(repositoryName=ECR_REPO_NAME)['imageIds']
    ecr_client.batch_delete_image(
        repositoryName=ECR_REPO_NAME,
        imageIds=image_ids
    )
    print('ECR repository is now empty.')

# Now delete stack containing ECR repository
delete_stack(**cf_template)

我能够通过首先删除 ECR 中的所有图像然后返回到 CloudFormation 并再次删除来做到这一点。 删除图像的说明在此处: https ://docs.aws.amazon.com/AmazonECR/latest/userguide/delete_image.html。 在我这样做之后,我能够回到 CloudFormation 并毫无问题地删除。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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