You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi All, I am new to Python, I am trying to delete RDS snapshots based on some conditions, actually it should not be only based on time as we have daily weekly and monthly backup but deleting the backup based on time is not possible as AWS RDS API doesn’t support that. if Anyone has done this, deleting a python code based on name and date, possible to help me here.
This is my code
import boto3
import datetime
def lambda_handler(event, context):
print(“Connecting to RDS”)
client = boto3.client(‘rds’)
response = client.describe_db_snapshots(
SnapshotType='manual',
Name=ndi-spcp-'dbname-20-02-19-10'
)
for snapshot in response(DBInstanceIdentifier=‘dbane’, MaxRecords=50)[‘DBSnapshots’]:
create_ts = snapshot[‘SnapshotCreateTime’].replace(tzinfo=None)
if create_ts < datetime.datetime.now() - datetime.timedelta(days=7):
print(“Deleting snapshot id:”, snapshot[‘DBSnapshotIdentifier’])
boto3.client(‘rds’).delete_db_snapshot(
DBSnapshotIdentifier=snapshot[‘DBSnapshotIdentifier’]
)
The text was updated successfully, but these errors were encountered:
Hi All, I am new to Python, I am trying to delete RDS snapshots based on some conditions, actually it should not be only based on time as we have daily weekly and monthly backup but deleting the backup based on time is not possible as AWS RDS API doesn’t support that. if Anyone has done this, deleting a python code based on name and date, possible to help me here.
This is my code
import boto3
import datetime
def lambda_handler(event, context):
print(“Connecting to RDS”)
client = boto3.client(‘rds’)
response = client.describe_db_snapshots(
SnapshotType='manual',
Name=ndi-spcp-'dbname-20-02-19-10'
)
for snapshot in response(DBInstanceIdentifier=‘dbane’, MaxRecords=50)[‘DBSnapshots’]:
create_ts = snapshot[‘SnapshotCreateTime’].replace(tzinfo=None)
if create_ts < datetime.datetime.now() - datetime.timedelta(days=7):
print(“Deleting snapshot id:”, snapshot[‘DBSnapshotIdentifier’])
boto3.client(‘rds’).delete_db_snapshot(
DBSnapshotIdentifier=snapshot[‘DBSnapshotIdentifier’]
)
The text was updated successfully, but these errors were encountered: