简体   繁体   中英

How to get Launch time of instance?

I want to get infromation of aws instance which are running or stopped with their launched_at time. I tried this:

@resp = client.describe_instance_status({
  filters: [
    {  
      name: "instance-state-name",
      values: ["stopped","running"],
    },
  ],
  instance_ids: aws_instance_ids,  # this is array of aws instance ids
  dry_run: false,
  include_all_instances: true,
})

This api call give me this output in response.

<struct Aws::EC2::Types::InstanceStatus availability_zone="us-east-1b", events=[], instance_id="XXXXXXXXXXXXX", instance_state=<struct Aws::EC2::Types::InstanceState code=80, name="stopped">, instance_status=# <struct Aws::EC2::Types::InstanceStatusSummary details=[], status="not-applicable">, system_status=<struct Aws::EC2::Types::InstanceStatusSummary details=[], status="not-applicable">>

but i don't get launched_at instance information. How can i get it with this API call?

There is no reliable method for getting the Launch time of an instance that is stopped. (Besides -- it might have many of them!)

Instead, use AWS Config , which can provide a full history of activity with resources including when it was started, stopped and modified.

     @resp = client.describe_instances({ 
     filters: [ 
       {
          name: "instance-state-name", 
          values: ["stopped","running"], 
        }, 
      ], 
     instance_ids: aws_instance_ids, #we pass here array of ec2 instance id
     dry_run: false, })

this api call fetched launched time details or all details of ec2 instances

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM