Skip to content

Instantly share code, notes, and snippets.

@foxutech
Created December 9, 2018 17:42
Show Gist options
  • Save foxutech/1aaea05c07ea0dfaa51c5f6a3b800388 to your computer and use it in GitHub Desktop.
Save foxutech/1aaea05c07ea0dfaa51c5f6a3b800388 to your computer and use it in GitHub Desktop.
Automate RDS snapshot Deletion Using Lambda
import boto3
import datetime
def lambda_handler(event, context):
print("Connecting to RDS")
client = boto3.client('rds')
for snapshot in client.describe_db_snapshots(DBInstanceIdentifier='test-db-final', MaxRecords=5)['DBSnapshots']:
if create_ts < datetime.datetime.now - datetime.timedelta(days=3):
print ("Deleting snapshot id:", snapshot['DBSnapshotIdentifier'])
client.delete_db_snapshot(
DBSnapshotIdentifier=snapshot['DBSnapshotIdentifier']
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment