使用aws客户端(https://github.com/aws/aws-cli),是否有方法使用日期范围筛选器查找实例?还是使用“早于X日期”或“最后X天”过滤器?
似乎唯一与日期相关的筛选器是指定确切日期,或使用字符串通配符指定部分日期。例如,我发现按照以下方式指定日期是可行的:
aws ec2 describe-instances --filters "Name=launch-time,Values=2015-03\*"例如,所有实例都会在2015年3月启动。
我想要的相当于POSIX的“查找”命令,“查找过去30天的所有内容”:
find . -mtime -30发布于 2015-03-10 16:25:35
您不能这样做,但是在python中使用boto库可以这样做,例如,列出30多天前启动的aws区域"eu-west-1“中的实例。
import boto.ec2
import datetime
from dateutil import parser
conn = boto.ec2.connect_to_region('eu-west-1')
reservations = conn.get_all_instances()
for r in reservations:
for i in r.instances:
launchtime = parser.parse(i.launch_time)
launchtime_naive = launchtime.replace(tzinfo=None)
then = datetime.datetime.utcnow() + datetime.timedelta(days = -30)
if launchtime_naive < then:
print i.id发布于 2015-07-24 00:07:38
在使用过滤器“启动时间”来查找所有比X日期更新的实例?上使用JMESPath查询找到的:
aws ec2 describe-instances --query 'Reservations[].Instances[?LaunchTime>=`2015-03-01`][].{id: InstanceId, type: InstanceType, launched: LaunchTime}'https://serverfault.com/questions/674319
复制相似问题