1

I need the ability to query AWS to validate whether or not an Elastic IP is attached to an instance. This must be done via the command line or via script.

I have tried both Ansible and AWS CLI to try to obtain this information. Examples:

aws ec2 describe-addresses --filters Name='public-ip',Values=34.29.176.23

Error returned: HTTPSConnectionPool(host='ec2.us-west-2a.amazonaws.com', port=443): Max retries exceeded with url: / (Caused by NewConnectionError(': Failed to establish a new connection: [Errno -2] Name or service not known',))

and using the Opsworks

aws opsworks describe-elastic-ips --ips '34.29.176.20'

Error returned: HTTPSConnectionPool(host='opsworks.us-west-2a.amazonaws.com', port=443): Max retries exceeded with url: / (Caused by NewConnectionError(': Failed to establish a new connection: [Errno -2] Name or service not known',))

Steven K7FAQ
  • 277
  • 2
  • 3
  • 13

3 Answers3

2

You have configured your aws-cli installation incorrectly.

You have configured the region as us-west-2a, which is not a region -- it's an availability zone.

That's why you are getting the error -- it's not because you didn't specify a region, but because you did -- in configuration -- with an invalid value. Otherwise, aws-cli would have thrown an error that the operation requires a region selection.

Michael - sqlbot
  • 22,658
  • 2
  • 63
  • 86
1

Almost everything in AWS is organized by region. Specifying the region is necessary with most CLI commands.

When you setup the AWS CLI, a default region is setup along with your credentials.

At the console type "aws configure". If you have already configured your credentials press ENTER for each one and the saved value will be used. When the line "Default region name:" displays enter your default region name such as us-west-2. Now your CLI commands will run without specifying the --region option. Your scripts (Python, Java, etc.) will also be able to use your credentials and region automatically.

Configuring the AWS CLI

Also make sure that you are using the latest version. With all of the announcements at re:Invent 2017 there have been some excellent updates to the CLI. The current version is 1.14.2. At the console type "pip install awscli --upgrade". On Windows this needs to be run in an Administrator command shell.

Installing the AWS Command Line Interface

John Hanley
  • 4,754
  • 1
  • 11
  • 21
0

Evidently there are undocumented requirements at http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-addresses.html

The describe-addresses requires a region to be provided. Such as:

aws ec2 describe-addresses --filters Name='public-ip',Values='34.29.176.20' --region us-west-2
Steven K7FAQ
  • 277
  • 2
  • 3
  • 13