5

I want to make sure the instance has passed the two status checks(System/Instance reachability check) using command line.

When I run this

ec2-describe-instance-status
ec2-describe-instance-status XX($InstanceID)

it would show running instances like

INSTANCE    $InstanceID $REGION running 16

But when I tried adding a filter to make sure the instance passed the status check

ec2-describe-instance-status XX($InstanceID) --filter instance-status.reachability=passed
ec2-describe-instance-status XX($InstanceID) --filter "instance-status.reachability=passed"
ec2-describe-instance-status --filter instance-status.reachability=passed

nothing ever returned.

I've double-checked the instances are running fine and actually passed the 2 status checks, but why nothing is returned after applying the filters?

Update: In response to Rico, I tried the -v option

ec2-describe-instance-status -v

returns one item in the instanceStatusSet, with the fields

    <item>
      <instanceId>i-XXX</instanceId>
      <availabilityZone>us-east-1d</availabilityZone>
      <instanceState>
        <code>16</code>
        <name>running</name>
      </instanceState>
    </item>

while

ec2-describe-instance-status --filter instance-status.reachability=passed -v
ec2-describe-instance-status --filter "instance-status.reachability=passed" -v

both return an empty instanceStatusSet...

3
  • It works fine for me. Can you try running it with the verbose option ? ec2-describe-instance-status --filter instance-status.reachability=passed -v Commented Feb 8, 2014 at 18:22
  • Thanks for the suggestion. I tried but still failed. I'll update this in the post. Commented Feb 8, 2014 at 18:53
  • Or are there any other ways to check the status? Commented Feb 8, 2014 at 19:31

2 Answers 2

4

Use the AWS Command Line Interface unified tool instead.

aws ec2 describe-instance-status --instance-ids i-01234567 --filters Name=instance-status.reachability,Values=passed
{
"InstanceStatuses": [
    {
        "InstanceId": "i-01234567",
        "InstanceState": {
            "Code": 16,
            "Name": "running"
        },
        "AvailabilityZone": "us-west-2c",
        "SystemStatus": {
            "Status": "ok",
            "Details": [
                {
                    "Status": "passed",
                    "Name": "reachability"
                }
            ]
        },
        "InstanceStatus": {
            "Status": "ok",
            "Details": [
                {
                    "Status": "passed",
                    "Name": "reachability"
                }
            ]
        }
    }
]
}
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry for checking back late. Thanks for the answer!
0

Note: (If you have a ton of instances, as in 100's or 1000's)
Annoyingly the ec2 web console and aws cli don't let you filter instance status health check failures of a tagged subset of nodes. also --instance-ids only lets you specify a max of 100 ids, if you go over that it complains, so this also works around that.

It took me a while to come up with this hacky yet working command so I figured I'd share it in case it's of use to anyone else.

list_of_failed=$(aws --region=eu-west-1 ec2 describe-instance-status --filters "Name=instance-status.reachability,Values=failed" | cat | jq '.InstanceStatuses | .[].InstanceId')

list_of_tagged=$(aws ec2 describe-instances --filters "Name=tag:Env,Values=dev" --query 'Reservations[].Instances[]' | jq '.[].InstanceId')

echo $list_of_failed | sort > /tmp/list1
echo $list_of_tagged | sort > /tmp/list2
comm -1 -2 /tmp/list1 /tmp/list2
  • list_of_failed represents a list of instance ids that failed ec2 reachability health check. (that list is based on all possible ec2 instances in a region, and the command doesn't seem to offer you the ability to filter by tag)
  • list_of_tagged represents a list of instance ids that match tag (in the example the tag KV pair is Env=dev, you should be able to adjust the query to your needs.)
  • comm -1 -2 /tmp/list1 /tmp/list2 returns the common / union / overlapping values of the 2 lists. So it effectively gives you a list of instance id's that both failed the check and have the tag.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.