How to find out when an EC2 instance was shutdown

amazon ec2amazon-web-servicesaws-cli

I have hundreds of instances in the EC2 web console.

Some are shutdown. I can see that they were created many months or years ago. They seem abandoned and forgotten for a while but it's hard to tell if terminating them is safe.

e.g. They could be some old backup, someone could have just migrated a load to new instances and keep the old ones for a few weeks as precaution, etc…

We end up keeping most of them as it's the safest choice.

We are still paying for the EBS volumes when the instance is shutdown (but not terminated). The price can escalate over time with many unused instances (EBS is $140 per month per TB). So I'd like to do some cleanup.

I'm thinking that if I could find the time when the instance was shutdown, that would be a good indicator of how "abandoned" it is.

How can I find when an instance was last shutdown?

Best Answer

Using the awscli. pip install awscli

aws ec2 describe-instances --output table --instance-id i-aef88019

Output:

|||  StateTransitionReason |  User initiated (2015-11-16 13:36:40 GMT)   |||
[...]
||||                             StateReason                            ||||
|||+---------+----------------------------------------------------------+|||
||||  Code   |  Client.UserInitiatedShutdown                            ||||
||||  Message|  Client.UserInitiatedShutdown: User initiated shutdown   ||||

We can see what happened to the instance and at what time.

For instance, this one was shutdown manually at 2015-11-16 13:36:40 GMT.