How do I use the AWS CLI to find the uptime of servers?

6,555

Solution 1

There is no specific 'uptime' measure in Amazon EC2.

If AWS Config has been configured, you could use get-resource-config-history to retrieve the history of an instance, eg:

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

AWS Config will show the state change of an Amazon EC2 instance (eg stopped, running) as a Configuration.State.Name value. The change will also have a timestamp.

Using this configuration history, you could piece together enough information to calculate uptime.

Alternatively, you could calculate the uptime from within the instance (eg from system logs or via a custom app) rather than obtaining it from EC2.

Solution 2

From the AWS documentation, you are probably after LaunchTime:

aws ec2 describe-instances --query "Reservations[].Instances[].[LaunchTime]"

From there, you can calculate the offset from the current date and time to find the uptime.

Share:
6,555

Related videos on Youtube

Kiran
Author by

Kiran

Updated on September 18, 2022

Comments

  • Kiran
    Kiran almost 2 years

    I've reviewed reference documentation for the AWS CLI. I know how to use the aws ec2 describe-instances command. Is there a variation to list the uptime (not the creation time) of the servers? The OS uptime is useful. It seems like this could be obtained via an aws cli command.

  • whoughton
    whoughton over 6 years
    Note that this assumes the instance has been up consistently since the launch time and has not been stopped/started in between.