删除 ECR 的 Boto3 服务员

Boto3 waiter for ECR deletion

有没有办法等到AWS ECR存储库强制删除成功。类似于cfn、ecs等中的waiter。。。ecr中也有waiter,但只用于图片扫描和生命周期策略预览。

我们必须强制删除一个ECR repo 并等待删除成功才能继续下一步的场景。如果没有服务员,是使用 describe_repositories 实现自定义服务员的唯一方法吗?

刚刚使用了带有自定义轮询时间和间隔的 describe repo 操作,发布下面的代码,因此可能会对某人有所帮助

while num_checks <= 30:
    print(f'\n\tWaiting for ECR: {ecr_repo} to be deleted')
    try:
        response = ecr_client.describe_repositories(
            repositoryNames=[ecr_repo]
        )
        if response['ResponseMetadata']['HTTPStatusCode'] == 200:
            num_checks += 1
            if num_checks == 30:
                raise Exception(f'Cannot force delete the ECR - {ecr_repo}')
            time.sleep(10)
            continue
        elif response['ResponseMetadata']['HTTPStatusCode'] != 200:
            raise Exception(f'Cannot force delete the ECR - {ecr_repo}')

    except ClientError as ce:
        if ce.response['Error']['Code'] == 'RepositoryNotFoundException':
            print(f'\tECR:{ecr_repo} DELETED SUCCESSFULLY\n')
            break
        else:
            raise Exception(f"\n{ce.response['Error']['Message']}\n")