Created
March 22, 2016 20:28
-
-
Save gabrielferreira/4082afa79771df150cf9 to your computer and use it in GitHub Desktop.
Script to delete EBS Snapshots identified by Tags
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 boto3 | |
import re | |
import datetime | |
ec = boto3.client('ec2',region_name='us-east-1') | |
iam = boto3.client('iam') | |
def lambda_handler(event, context): | |
account_ids = list() | |
delete_on = datetime.date.today().strftime('%Y-%m-%d') | |
filters = [ | |
{'Name': 'tag-key', 'Values': ['DeleteOn']}, | |
{'Name': 'tag-value', 'Values': [delete_on]}, | |
] | |
snapshot_response = ec.describe_snapshots(OwnerIds=account_ids, Filters=filters) | |
for snap in snapshot_response['Snapshots']: | |
print "Deleting snapshot %s" % snap['SnapshotId'] | |
ec.delete_snapshot(SnapshotId=snap['SnapshotId']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Got Error:
syntax error in module 'index': Missing parentheses in call to 'print' (index.py, line 19)