问题
I am doing a Python Lambda function to describe list of RDS snapshots created today. The challenge is how to convert the datetime.datetime.today() into a format which RDS client understands?
UPDATE: I have implemented some changes suggested, I have added a string variable to convert the date expression into format which Boto3 RDS understands.
'SnapshotCreateTime': datetime(2015, 1, 1),
today = (datetime.today()).date()
rds_client = boto3.client('rds')
snapshots = rds_client.describe_db_snapshots(SnapshotType='automated')
harini = "datetime("+ today.strftime('%Y,%m,%d') + ")"
print harini
print snapshots
for i in snapshots['DBSnapshots']:
if i['SnapshotCreateTime'].date() == harini:
print(i['DBSnapshotIdentifier'])
print (today)
it is still unable to retrieve list of automated snapshots created today
回答1:
SnapshotCreateTime is a datetime.datetime object. So, you can just do i['SnapshotCreateTime'].date()
to get the date.
import boto3
from datetime import datetime, timezone
today = (datetime.today()).date()
rds_client = boto3.client('rds')
snapshots = rds_client.describe_db_snapshots()
for i in snapshots['DBSnapshots']:
if i['SnapshotCreateTime'].date() == today:
print(i['DBSnapshotIdentifier'])
print (today)
来源:https://stackoverflow.com/questions/50151598/list-rds-snapshot-created-today-using-boto-3