Last active
October 6, 2016 13:34
-
-
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.
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 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