Skip to content

Instantly share code, notes, and snippets.

@seventhskye
Last active October 6, 2016 13:34
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 seventhskye/1c906745b9edd10d08ee363069e1c820 to your computer and use it in GitHub Desktop.
Save seventhskye/1c906745b9edd10d08ee363069e1c820 to your computer and use it in GitHub Desktop.
A lambda function to perform cron tasks, this one deletes cloudformation stacks. Fill in REGEX with a regular expression for the CF stack name you wish to delete.
import sys
import boto3
import re
def lambda_handler(event, context):
cloudformation = boto3.client('cloudformation')
stacks = cloudformation.describe_stacks()['Stacks']
for s in stacks:
if re.match(REGEX, s['StackName'], flags=0):
response = cloudformation.delete_stack(StackName=s['StackName'])
return "Deleting stack {}".format(s['StackName'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment