Determining Amazon EC2 instance creation date/time

megazoe picture megazoe · Sep 20, 2013 · Viewed 19.4k times · Source

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 anything helpful in this case. Need to find out the creation date of a particular set of EC2 instances.

Thanks!

Answer

Venkatesh Wadawadagi picture Venkatesh Wadawadagi · Jul 27, 2016

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.