def bucket_delete_retry()

in deployment/solution-assistant/src/lambda_function.py [0:0]


def bucket_delete_retry(bucket_name):
    # Try to empty the bucket then delete the model-data bucket 5 times
    # This is needed because the thread we open
    s3_client = boto3.client("s3")
    for _ in range(5):
        delete_s3_objects(bucket_name)
        delete_s3_bucket(bucket_name)

        # Give the delete op time to finish
        time.sleep(10)

        try:
            _ = s3_client.head_bucket(Bucket=bucket_name)
        except s3_client.exceptions.ClientError:
            break  # This is good, the bucket was deleted, so we just exit the loop

        # Otherwise wait a minute and try again
        time.sleep(60)