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

查看:23
本文介绍了确定 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天全站免登陆