Search code examples
pythonbotoamazon-route53boto3

boto3 Route53 complains Could not connect to the endpoint URL:


I was trying to get some Route53 automation working with boto, and noticed that this tiny boto3 (version 1.3.1) example:

import boto3
client = boto3.client('route53')
print client.list_hosted_zones()

blows up with a complaint about:

  File "... venv/lib/python2.7/site-packages/botocore/retryhandler.py", line 356, in _check_caught_exception
    raise caught_exception
botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "https://route53.us-east-1e.amazonaws.com/2013-04-01/hostedzone"

while this similar boto2 (using version 2.38.0) code seems to work fine:

from boto.route53.connection import Route53Connection
r53_conn = Route53Connection()
print r53_conn.get_all_hosted_zones()

and prints out a dictionary of info about my hosted zones. If I attempt to coax boto3 into using the endpoint suggested by Amazon (even though it seems boto3 should know how to do this by default...), like this:

client = boto3.client('route53', endpoint_url='https://route53.amazonaws.com')

I get this error:

  File "... venv/lib/python2.7/site-packages/botocore/client.py", line 572, in _make_api_call
    raise ClientError(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (SignatureDoesNotMatch) when calling the ListHostedZones operation: Credential should be scoped to a valid region, not 'us-east-1e'. 

Is there something particular I need to do to teach boto3 how to talk to Route53 correctly, and why is it that boto2 seems to know how to do this automatically?


Solution

  • Thanks to this answer Exception in Boto3 - botocore.exceptions.EndpointConnectionError all you need to do is to configure your ~/.aws/config file. That's seems like you didn't configure it or configured incorrectly.