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

Time:10-02

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.

CodePudding user response:

aws ec2 describe-instances | jq -r ".Reservations[].Instances[] | .InstanceId, .LaunchTime"

will give you each instance id and it's launch date. From there you'll need to wrap it with a script of you choice to test the date and do what you want with the InstanceId.

CodePudding user response:

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).

  • Related