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!
Assuming you are using an EBS-backed instance and aren't doing any fancy drive juggling, the best way to figure out the creation date of an instance is to look at the creation time of the drive's root volume.
In the server dashboard report, you can view the details of the SQL Server instance. The SQL Server instance uptime is in the Server Startup Time dashboard of the Configuration Details grid. The Server startup time is in HH: MM AM/PM format. As you can see in the above screenshot, the server startup time is 12:10 AM.
This service uses a fleet of satellite-connected and atomic reference clocks in each AWS Region to deliver accurate current time readings of the Coordinated Universal Time (UTC) global standard. The Amazon Time Sync Service automatically smooths any leap seconds that are added to UTC.
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.
Assuming you are using an EBS-backed instance and aren't doing any fancy drive juggling, the best way to figure out the creation date of an instance is to look at the creation time of the drive's root volume. While the launch time of the instance will change every time you stop and start it, the creation time of an EBS volume is static.
Here's a quick script to find the creation time of the instance you're currently running from:
import boto
import subprocess
instance_id = subprocess.check_output(['curl', '-s', 'http://169.254.169.254/latest/meta-data/instance-id'])
conn = boto.connect_ec2()
root_device = conn.get_instance_attribute(instance_id, 'rootDeviceName')['rootDeviceName']
root_vol = conn.get_all_volumes(filters={"attachment.instance-id": instance_id, "attachment.device": root_device})[0]
print root_vol.create_time
Note that this requires the IAM Role of the instance to have ec2:DescribeInstanceAttribute
and ec2:DescribeVolumes
permissions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With