列出使用Boto 3今天创建的RDS快照 [英] list RDS snapshot created today using Boto 3

查看:128
本文介绍了列出使用Boto 3今天创建的RDS快照的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Python Lambda函数来描述今天创建的RDS快照列表.面临的挑战是如何将datetime.datetime.today()转换为RDS客户端可以理解的格式?

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?

更新:我已经实现了建议的一些更改,我添加了一个字符串变量以将日期表达式转换为Boto3 RDS可以理解的格式.

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),

'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

推荐答案

SnapshotCreateTime是datetime.datetime对象.因此,您只需执行i['SnapshotCreateTime'].date()即可获取日期.

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)

这篇关于列出使用Boto 3今天创建的RDS快照的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆