Created
April 7, 2021 22:08
-
-
Save benoitMariaux/128d479d145b9c5d8e8c759192fd94d6 to your computer and use it in GitHub Desktop.
Remove all Cloudformation Stacks, but make empty ECR repositories before
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import botocore, boto3 | |
ecr = boto3.client('ecr') | |
repos = ecr.describe_repositories() | |
for repo in repos['repositories']: | |
images = ecr.list_images(repositoryName=repo['repositoryName']) | |
if bool(images['imageIds']) == True: | |
ecr.batch_delete_image( | |
repositoryName=repo['repositoryName'], | |
imageIds=images['imageIds'] | |
) | |
cf = boto3.client('cloudformation') | |
r = cf.describe_stacks() | |
for stack in r['Stacks']: | |
try: | |
cf.delete_stack(StackName=stack['StackName']) | |
except: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment