Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Impossible to create a bucket in us-east-1 if underlying botocore session sets another default region #3489

Closed
ChristianWeymannTNG opened this issue Nov 11, 2022 · 2 comments
Assignees
Labels
bug This issue is a confirmed bug.

Comments

@ChristianWeymannTNG
Copy link

Describe the bug

When creating an S3 client with region_name=us-east-1 from a boto3.Session, if the underlying botocore.session.Session is setup with a botocore.config.Config that defines a different region_name, creating buckets will always fail with an IllegalLocationConstraintException

Expected Behavior

Being able to create buckets in the us-east-1 region

Current Behavior

Traceback (most recent call last):
  File "scratch_20.py", line 14, in <module>
    client.create_bucket(Bucket="test-bucket-creation-20221111")
  File "site-packages/botocore/client.py", line 495, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "site-packages/botocore/client.py", line 914, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (IllegalLocationConstraintException) when calling the CreateBucket operation: The unspecified location constraint is incompatible for the region specific endpoint this request was sent to.

Traceback (most recent call last):
  File "scratch_20.py", line 14, in <module>
    client.create_bucket(Bucket="test-bucket-creation-20221111", CreateBucketConfiguration={"LocationConstraint": "us-east-1"})
  File "site-packages/botocore/client.py", line 495, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "site-packages/botocore/client.py", line 914, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (IllegalLocationConstraintException) when calling the CreateBucket operation: The us-east-1 location constraint is incompatible for the region specific endpoint this request was sent to.

Reproduction Steps

import boto3
from botocore.config import Config
from botocore.session import Session

config = Config(region_name="eu-west-1")
session = Session()
session.set_default_client_config(config)
boto_session = boto3.Session(botocore_session=session)

client = boto_session.client("s3", region_name="us-east-1")
client.create_bucket(Bucket="test-bucket-creation-20221111") #raises
client.create_bucket(Bucket="test-bucket-creation-20221111", CreateBucketConfiguration={"LocationConstraint": "us-east-1"}) #raises

client = boto_session.client("s3", region_name="ap-southeast-1")
client.create_bucket(Bucket="test-bucket-creation-20221111", CreateBucketConfiguration={"LocationConstraint": "ap-southeast-1"}) #works as expected

Possible Solution

In the example above, it seems like like for the specific case of "us-east-1", the S3 endpoint for "eu-west-1" is still called.

Additional Information/Context

No response

SDK version used

boto3 1.26.1, botocore 1.29.1

Environment details (OS name and version, etc.)

Tested on Ubuntu 20.04 and lambda runtime python3.9

@ChristianWeymannTNG ChristianWeymannTNG added bug This issue is a confirmed bug. needs-triage This issue or PR still needs to be triaged. labels Nov 11, 2022
@ChristianWeymannTNG
Copy link
Author

As a workaround, we currently reset the config around the calls

config = session._session.get_default_client_config()
config_no_region = config.merge(Config(region_name=None))
session._session.set_default_client_config(config_no_region)
try:
    ...
finally:
    session._session.set_default_client_config(config)

@tim-finnigan tim-finnigan self-assigned this Nov 11, 2022
@tim-finnigan tim-finnigan removed the needs-triage This issue or PR still needs to be triaged. label Nov 11, 2022
@tim-finnigan
Copy link
Contributor

Hi @ChristianWeymannTNG thanks for reaching out. A similar issue was raised here before: #125. The create-bucket documentation notes that regions outside of us-east-1 require the appropriate LocationConstraint to be specified in order to create the bucket in the desired region. Otherwise the default is us-east-1. Please let us know if you had any further questions on this. Since this issue involves a guidance on expected behavior rather than a bug I am going to convert it to a discussion as per our triage process.

@boto boto locked and limited conversation to collaborators Nov 11, 2022
@tim-finnigan tim-finnigan converted this issue into discussion #3491 Nov 11, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
bug This issue is a confirmed bug.
Projects
None yet
Development

No branches or pull requests

2 participants