fix(bedrock): respect AWS profile region instead of hardcoding us-east-1 (#892)#1465
Open
MukundaKatta wants to merge 1 commit intoanthropics:mainfrom
Open
fix(bedrock): respect AWS profile region instead of hardcoding us-east-1 (#892)#1465MukundaKatta wants to merge 1 commit intoanthropics:mainfrom
MukundaKatta wants to merge 1 commit intoanthropics:mainfrom
Conversation
…cs#892) _infer_region() previously created boto3.Session() without forwarding the aws_profile passed to AnthropicBedrock, so the default profile's region was used instead of the requested profile's region. Pass aws_profile through to boto3.Session(profile_name=...) so the region configured for that profile in ~/.aws/config is honored.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #892 — when
aws_profile=is passed toAnthropicBedrock/AsyncAnthropicBedrock, the region from that profile in~/.aws/configis now honored.PR #974 added
_infer_region()to fall back toboto3.Session().region_name, but the session was created withoutprofile_name=..., so the default profile's region was always used regardless of whataws_profile=was passed to the constructor. Cross-region setups still ended up onus-east-1(or whichever region the default profile defines), which is exactly the symptom the original issue describes for users runningAWS_PROFILEsetups with non-default regions.Changes
src/anthropic/lib/bedrock/_client.py:_infer_regionnow accepts an optionalaws_profileand passes it through toboto3.Session(profile_name=aws_profile). BothAnthropicBedrock.__init__andAsyncAnthropicBedrock.__init__forward the constructor'saws_profileargument.tests/lib/test_bedrock.py: regression testtest_region_infer_from_constructor_profilecovers the constructor-profile path. The existingmock_aws_configfixture is reused (no new test infra).Resolution order is unchanged: explicit
aws_regionwins, thenAWS_REGION, then the boto3 session (now profile-aware), thenus-east-1fallback.Test plan
./scripts/test tests/lib/test_bedrock.pytest_region_infer_from_constructor_profilereturnsus-east-2(default profile) instead ofus-west-1(custom profile) and fails.