How to find exact stopped time of AWS EC2 instances

0 votes
HI,

I really need to know about the stopped time of AWS EC2 instances. I have checked with AWS cloudtrail, but its not easy to find my problems. Is possible to see exact time of stopped EC2 instances by aws-cli commands or any boto3 script?

Kindly give me example with screenshot.
Dec 3, 2020 in AWS by Lakshminarayanan
• 1,370 points
3,398 views

1 answer to this question.

0 votes

Hi@Lakshminarayanan,

You can use InstanceState Data Types in your AWS CLI command. You need to create your own customized command to meet your requirement. I found one command. Try to use the below command. It may help.

$ aws ec2 describe-instances --region us-west-2 --filters "Name=instance-state-code,Values=80" --query 'Reservations[].Instances[].[Tags[?Key==`Name`] | [0].Value, PrivateIpAddress, State.Name, StateTransitionReason]' --output table | sort -k 6,6 
answered Dec 3, 2020 by MD
• 95,460 points
Hi @MD,

many thanks, I have tried same commands to check. But it doesn't shown stopped time of EC2 instances. I have attached screenshot.  What should i add in aws-cli commands to see exact time of EC2 stopped.

                   DescribeInstances
|  None                      |  172.31.3.250  |  stopped |  User initiated

|  None                      |  172.31.38.135 |  stopped |  User initiated
Hi,

Remove the pipe and try once. If possible paste your output here.
aws ec2 describe-instances --region ap-south-1 --filters "Name=instance-state-code,Values=80" --query 'Reservations[].Instances[].[Tags[?Key==`Name`] | [0].Value, PrivateIpAddress, State.Name, StateTransitionReason]' --output table
-------------------------------------------------------------------------------------------------------
|                                          DescribeInstances                                          |
+----------------------------+----------------+----------+--------------------------------------------+
|  None                      |  172.31.42.234 |  stopped |  User initiated                            |
|  None                      |  172.31.44.224 |  stopped |  User initiated                            |
|  None                      |  172.31.38.135 |  stopped |  User initiated                            |
Hi,

Do one thing, first run the aws ec2 describe-instances command. And find the key that shows the time. Is it StateTransitionReason?
Hi,

If i run simple describe ec2 instances, then i got details like Launch time and etc., But i dont get stopped time. How do i get stopped time of ec2 instances? bro

Hi,

Did you try with Cloudtrail? Generally, it holds this information. Just check the below steps once.

  1. Go to your Cloudtrail console and there, you will see a list of your EC2 Actions.

  2. Click on StopInstances

Under EventTime, you can see both the date and time of your stopped instance.

Related Questions In AWS

0 votes
0 answers
+1 vote
1 answer

How to add SSL certificate to AWS EC2 with the help of new AWS Certificate Manager service

refer this link  https://aws.amazon.com/certificate-manager/faqs/ You can't install the certificates ...READ MORE

answered Jul 19, 2018 in AWS by Priyaj
• 58,020 points
1,880 views
0 votes
1 answer
0 votes
1 answer

AWS S3 uploading hidden files by default

versioning is enabled in your bucket. docs.aws.amazon.com/AmazonS3/latest/user-guide/….... the ...READ MORE

answered Oct 4, 2018 in AWS by Priyaj
• 58,020 points
6,017 views
0 votes
1 answer

How to get the last stopped time & date of EC2 instance?

Hi@akhtar, To get the details of your last ...READ MORE

answered Jun 16, 2020 in AWS by MD
• 95,460 points
14,246 views
0 votes
1 answer

What kind of data generates from EC2 to EBS in AWS

Hi, First thing is EC2 is a compute service whereas EBS is ...READ MORE

answered Mar 16, 2020 in AWS by MD
• 95,460 points
1,150 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP