CADESUser DocumentationUser-Contributed Tutorial IndexAWS Overview

Describing (Listing) Instances

Show AWS Account and IAM user for calling identity

This is helpful should you need to verify to which AWS account, and as which user, you are interacting as.

If the user is allowed, you may sign into the AWS web console. For example, the web console login for the below account would be this, with login as user cades-ops-admin

https://890017512345.signin.aws.amazon.com/console

$ aws iam list-users
"Users": [
    {
        "UserName": "your-user-here",
        "PasswordLastUsed": "2018-11-20T20:12:37Z",
        "CreateDate": "2017-09-06T15:22:22Z",
        "UserId": "AIDAJ5W4MZQVLK5OABBA",
        "Path": "/",
        "Arn": "arn:aws:iam::890017512345:user/your-user-here"
     }

Also helpful:

$aws ec2 describe-account-attributes

Describe Existing Instances

Below are examples of describing (listing) EC2 instances. Additional AWS documentation provides more information.

  • List details about instances and their states
  • Uses region defined in .aws/config, or --region if provided.
  • Defaults to us-east-1 region
  • To see all instances in all regions see below
$ aws ec2 describe-instances 
{
    "Reservations": []
}

The above examples shows no instances exist for this IAM user in the region specified. As no --region was specified, the default of us-east-1 was searched.

If instances exist you may filter on the desired json element(s)

$ aws ec2 describe-instances --region us-east-1| jq '.Reservations[].Instances[].InstanceId, .Reservations[].Instances[].State'
"i-0e8a41ba81c941e1b"
"i-04e32003366d6d5f8"
{
  "Code": 80,
  "Name": "stopped"
}
{
  "Code": 80,
  "Name": "stopped"
}

Searching another region:

$ aws ec2 describe-instances --region us-east-2| jq '.Reservations[].Instances[].InstanceId, .Reservations[].Instances[].State'
"i-0570f28c24359e903"
{
  "Code": 80,
  "Name": "stopped"
}

Describe Instances in All Regions

Neither the web console, nor aws cli, have the ability to show instances in --region=all, so you must loop through:

for region in `aws ec2 describe-regions --output text | cut -f3`
do
     echo -e "\nListing Instances in region:'$region'..."
     aws ec2 describe-instances --region $region | jq '.Reservations[] | ( .Instances[] | {state: .State.Name, name: .KeyName, type: .InstanceType, key: .KeyName})'
done

or

for region in `aws ec2 describe-regions --output text | cut -f3`
do
     echo -e "\nListing Instances in region:'$region'..."
     aws ec2 describe-instances --region $region | jq '.Reservations[] | ( .Instances[] | {state: .State.Name, name: .KeyName, Tag_Name: .Tags[].Value,type: .InstanceType, key: .KeyName})'
done

https://github.com/aws/aws-cli/issues/1777

results matching ""

    No results matching ""