Skip to content

Instantly share code, notes, and snippets.

@brianrogers
Created May 11, 2022 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianrogers/b33dbb7e1b2e97d3020acc45c40e378e to your computer and use it in GitHub Desktop.
Save brianrogers/b33dbb7e1b2e97d3020acc45c40e378e to your computer and use it in GitHub Desktop.
pull old RDS snapshot info and create csv files per region
from asyncore import write
import boto3
import datetime
import pytz
import csv
regions = ['us-east-1','eu-central-1','eu-west-1','ca-central-1','us-east-2','eu-west-2','us-west-1','ap-southeast-2','ap-southeast-1','us-west-2']
headers = ['DBSnapshotIdentifier', 'DBInstanceIdentifier', 'SnapshotCreateTime', 'AllocatedStorage', 'DBSnapshotArn']
now = pytz.utc.localize(datetime.datetime.now())
for region in regions:
rds = boto3.client("rds", region)
with open(region + '_old_snapshots_2022.csv', 'w', encoding='UTF8') as f:
writer = csv.writer(f)
writer.writerow(headers)
for snapshot in rds.describe_db_snapshots()['DBSnapshots']:
# print(snapshot)
if snapshot['SnapshotCreateTime'] < now - datetime.timedelta(days=365):
row = []
for item in headers:
row.append(snapshot[item])
writer.writerow(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment