Created
December 9, 2018 17:42
-
-
Save foxutech/1aaea05c07ea0dfaa51c5f6a3b800388 to your computer and use it in GitHub Desktop.
Automate RDS snapshot Deletion Using Lambda
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 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