Question

I am writing java code for EC2 that will consume messages from SQS. My code will run for the hour and then review the queue to determine whether it should shut itself down (due to not enough items to warrant processing for another hour) or to keep running. In order for this to work, I need to know the precise time stamp of when billing for the instance began so I can add one hour to it and shutdown a few minutes before the hour is up if necessary.

How can I get the launch time stamp (the time AWS begins billing for the instance hour) of the EC2 instance my java code is currently running on using the java SDK preferably?

Was it helpful?

Solution

If shelling to uptime or dropping date +%s > /etc/started-at into your bootscript are too platform-dependent for your tastes, you could perform the DescribeInstances SOAP call and pluck out the launchTime field.

To discover the running machine's instance id, you can (from within the machine) make an http GET such as

curl http://169.254.169.254/latest/meta-data/instance-id
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top