0

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.

Deepak Tatyaji Ahire
  • 4,883
  • 2
  • 13
  • 35
  • What command line? Bash, Powershell, CICS? – stdunbar Oct 01 '22 at 22:19
  • 1
    Does this answer your question? [Determining Amazon EC2 instance creation date/time](https://stackoverflow.com/questions/18916135/determining-amazon-ec2-instance-creation-date-time) – Paolo Oct 02 '22 at 11:55
  • No @Paolo. My question specifically asks about the "using command line only". The answers in the above question include python scripts, which I don't want. – Deepak Tatyaji Ahire Oct 03 '22 at 06:21

1 Answers1

2

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

Riz
  • 1,131
  • 1
  • 9
  • 12