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

Python Sample Code Error #34

Open
faizalrf opened this issue Oct 28, 2024 · 1 comment
Open

Python Sample Code Error #34

faizalrf opened this issue Oct 28, 2024 · 1 comment

Comments

@faizalrf
Copy link

The Sample code for the Alternator load balancing, try1.py and try2.py when executing, gives the error

botocore.exceptions.NoRegionError: You must specify a region.

The line responsible for this is

    dynamodb = boto3.resource('dynamodb', endpoint_url=alternator_url, 
            aws_access_key_id='alternator', aws_secret_access_key='secret_pass')

Updated code with the additional region_name='us-east-1' fixes the issue

    dynamodb = boto3.resource('dynamodb', endpoint_url=alternator_url, region_name='us-east-1',
            aws_access_key_id='alternator', aws_secret_access_key='secret_pass')
@nyh
Copy link
Contributor

nyh commented Oct 28, 2024

This is true, this is a strange AWS SDK bug, that you need a region name even if it's not actually used (because the explicit endpoint_url overrides the region anyway). The java/README.md explains (this text isn't present in python/README.md):

The region passed to withRegion does not matter (and can be any string),
because AlternatorRequestHandler will override the chosen endpoint anyway,
Unfortunately we can't just drop the withRegion() call, because without
it the library will expect to find a default region in the configuration file
and complain when it is missing.

As this text explains if you have in ~/.aws/config

[default]
region = us-east-1

The region_name option will no longer be required.

But I agree it's worth changing the test to include region_name='doesnt-matter' or something (I think using the name doesnt-matter instead of us-east-1 is better because it emphasizes that this parameter is needed but ignored).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants