简体   繁体   中英

Boto3 waiter for ECR deletion

Is there a way to wait until the AWS ECR repository force deletion is successful. Similar to waiters in cfn, ecs etc... there are waiters in ecr as well but those are only for image scan and lifecycle policy preview.

A scenario where we must force delete a ECR repo and wait until the deletion is successful, so we can proceed with next steps. If there are no waiters, is the only way to implement a custom one using describe_repositories?

Just used the describe repo operation with custom polling times and interval, posting the code below, so might help someone

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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