Determining Amazon EC2 instance creation date/time

后端 未结 5 631
灰色年华
灰色年华 2021-01-02 02:32

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

http://boto.readthedocs.org/en/latest/ref/ec2.html doesn\'t seem to be giving any

5条回答
  •  一个人的身影
    2021-01-02 02:48

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

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

    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.

提交回复
热议问题