list RDS snapshot created today using Boto 3

笑着哭i 提交于 2019-12-11 06:35:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!