Skip to content

Instantly share code, notes, and snippets.

@gabrielferreira
Created March 22, 2016 20:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabrielferreira/4082afa79771df150cf9 to your computer and use it in GitHub Desktop.
Save gabrielferreira/4082afa79771df150cf9 to your computer and use it in GitHub Desktop.
Script to delete EBS Snapshots identified by Tags
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'])
@raakey
Copy link

raakey commented May 20, 2017

Got Error:

syntax error in module 'index': Missing parentheses in call to 'print' (index.py, line 19)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment