【问题标题】:How to delete aws ECR repository which contain images through cloudformation?如何通过cloudformation删除包含图像的aws ECR存储库?
【发布时间】:2018-08-22 23:21:57
【问题描述】:

如何通过cloudformation删除包含图像的aws ECR存储库?删除时低于错误。

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

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation


    【解决方案1】:

    留下我使用 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)
    
    

    【讨论】:

      【解决方案2】:

      我能够做到这一点,首先删除 ECR 中的所有图像,然后返回 CloudFormation 并再次删除。删除图像的说明在这里:https://docs.aws.amazon.com/AmazonECR/latest/userguide/delete_image.html。完成此操作后,我可以返回 CloudFormation 并毫无问题地删除。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-06-08
        • 1970-01-01
        • 2022-11-28
        • 1970-01-01
        • 1970-01-01
        • 2017-04-18
        • 2020-10-22
        • 2015-04-30
        相关资源
        最近更新 更多