Skip to content

Instantly share code, notes, and snippets.

@benoitMariaux
Created April 7, 2021 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benoitMariaux/128d479d145b9c5d8e8c759192fd94d6 to your computer and use it in GitHub Desktop.
Save benoitMariaux/128d479d145b9c5d8e8c759192fd94d6 to your computer and use it in GitHub Desktop.
Remove all Cloudformation Stacks, but make empty ECR repositories before
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