1

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.

  • 1
    As 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 1:27
  • 1
    You could use a configuration management system to get this information en mass, like SaltStack. – Spooler Oct 15 '16 at 12:15
2

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.

| improve this answer | |
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.

| improve this answer | |
  • 3
    Note 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.