Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boto3 isnt fetching region from IMDS #375

Closed
alex-luminal opened this issue Nov 20, 2015 · 5 comments
Closed

Boto3 isnt fetching region from IMDS #375

alex-luminal opened this issue Nov 20, 2015 · 5 comments
Labels
documentation This is a problem with documentation.

Comments

@alex-luminal
Copy link

According to the docs (https://boto3.readthedocs.org/en/latest/guide/configuration.html), boto3 should be fetching the region from the instance metadata service if it's running on an EC2 instance. This does not appear to be the case.

Steps to reproduce:

  1. Spin up an instance in us-west-2 with an appropriate IAM role
  2. Install boto3 on the instance
>>> import boto3
>>> boto3.resource("sqs")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/boto3/__init__.py", line 87, in resource
    return _get_default_session().resource(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/boto3/session.py", line 292, in resource
    aws_session_token=aws_session_token, config=config)
  File "/usr/local/lib/python2.7/site-packages/boto3/session.py", line 200, in client
    aws_session_token=aws_session_token, config=config)
  File "/usr/lib/python2.7/dist-packages/botocore/session.py", line 762, in create_client
    client_config=config, api_version=api_version)
  File "/usr/lib/python2.7/dist-packages/botocore/client.py", line 62, in create_client
    verify, credentials, scoped_config, client_config)
  File "/usr/lib/python2.7/dist-packages/botocore/client.py", line 227, in _get_client_args
    endpoint_url)
  File "/usr/lib/python2.7/dist-packages/botocore/client.py", line 117, in _get_signature_version_and_region
    service_model.endpoint_prefix, region_name, scheme=scheme)
  File "/usr/lib/python2.7/dist-packages/botocore/regions.py", line 70, in construct_endpoint
    raise NoRegionError()
botocore.exceptions.NoRegionError: You must specify a region.
@jamesls
Copy link
Member

jamesls commented Nov 20, 2015

This is a doc bug. We only use IMDS for credentials, not for configuration. #376 corrects the docs.

@jamesls jamesls added the documentation This is a problem with documentation. label Nov 20, 2015
@alex-luminal
Copy link
Author

shouldn't it also use the IMDS for region if none is provided? If I'm running some boto code on an EC2 instance, and have not provided a region through any other mechanism (env, arg to the connection method, etc), then I probably want that code to connect to the local region.

@jamesls
Copy link
Member

jamesls commented Nov 23, 2015

This was also requested for the AWS CLI: aws/aws-cli#486

I think the main hesitation was that this could be unexpected for users. If you have a script you've developed that worked in us-west-2 (relying on this behavior) and you copy it over to a us-east-1 instance, it could be hard to troubleshoot why the script wasn't working, especially if this feature is on by default. A user may not be aware they're relying on this functionality.

That being said, we'd still like more feedback on this. I assume you'd find this functionality useful?

@kennyk65
Copy link

kennyk65 commented Aug 3, 2019

AWS's Java SDK resolves region via instance metadata, if there is no environment variable, system property, or ~.aws/config value saying otherwise. Its too bad the different SDKs follow different preferences for doing the same thing. It is very nice that all the SDKs now resolve credentials the exact same way (see https://aws.amazon.com/blogs/security/a-new-and-standardized-way-to-manage-credentials-in-the-aws-sdks/), too bad region resolution has to be inconsistent.

@gandroz
Copy link

gandroz commented Jun 10, 2020

any dynamic way to get the current region of the EC2 instance other than a curl (python resquests.get) to get metadata ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation This is a problem with documentation.
Projects
None yet
Development

No branches or pull requests

4 participants