Deepak Tatyaji Ahire
Deepak Tatyaji Ahire

Reputation: 5321

How to check the aws ec2 instance creation date using command line?

To determine how old the aws ec2 instances are, and to destroy those nodes if they are older than 90 days, I need to check the creation date of the node.

What is the correct way to do that using COMMAND LINE?

What I tried?

I tried the command ec2metadata, but the output doesn't contain creation date.

Upvotes: 0

Views: 2299

Answers (1)

Riz
Riz

Reputation: 1167

You can get this information with

aws configservice get-resource-config-history --resource-type AWS::EC2::Instance --resource-id i-xxxxxxxx   

The last element in this json is what you need.
You can check get-resource-config-history and find resources between specific dates.
You can also get creation date of your root volume with

aws ec2 describe-volumes --volume-ids vol-xxxxx    

This can also give you age of your root volume (if not changed).

Upvotes: 2

Related Questions