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.
Asked
Active
Viewed 9,247 times
2

Kiran
- 67
- 4
- 10
-
1As with RAM and disk usage, it cannot be fetched via AWS API. Amazon doesn't have that sort of visibility inside your VMs. – ceejayoz Oct 15 '16 at 01:27
-
1You could use a configuration management system to get this information en mass, like SaltStack. – Spooler Oct 15 '16 at 12:15
2 Answers
4
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.

John Rotenstein
- 871
- 7
- 16
1
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.

Willem van Ketwich
- 141
- 4
-
3Note that this assumes the instance has been up consistently since the launch time and has not been stopped/started in between. – whoughton Mar 14 '18 at 18:16