确定Amazon EC2实例创建日期/时间 [英] Determining Amazon EC2 instance creation date/time

查看:145
本文介绍了确定Amazon EC2实例创建日期/时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以(通过boto)确定何时创建特定的EC2实例?

Is it possible to determine (via boto) when a particular EC2 instance was created?

http://在这种情况下,boto.readthedocs.org/en/latest/ref/ec2.html 似乎没有提供任何帮助。需要找出一组特定的EC2实例的创建日期。

http://boto.readthedocs.org/en/latest/ref/ec2.html doesn't seem to be giving anything helpful in this case. Need to find out the creation date of a particular set of EC2 instances.

谢谢!

推荐答案

对于EC2实例,没有名为 create_time 的属性,只有 launch_time 可用。

There's is no attribute called create_time for EC2 instance, only launch_time is available.

但是,您可以使用以下Python代码来了解何时创建了卷,这反过来又给了您实例创建时间(请注意,我在谈论卷创建实例时附加):

However, you can use the following Python code to know when the volume was created, which in turn gives you instance creation time (note that I'm talking about the volume attached while creating instance):

import boto3
ec2 = boto3.resource('ec2', region_name='instance_region_name')
volume = ec2.Volume('vol-id')
print volume.create_time.strftime("%Y-%m-%d %H:%M:%S")

另一种方法是使用自定义代码。使用 create_instances()创建实例时,可以记录给定实例的 launch_time 以及实例ID和名称到DynamoDB之类的地方,以便您可以随时使用实例ID检索创建时间。

The alternative is using custom code. When you create instances with create_instances(), you can log the launch_time for given instance along with it's instance ID and name to some place like DynamoDB so that you can retrieve the "create times" whenever you want using the instance IDs.

这篇关于确定Amazon EC2实例创建日期/时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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