Skip to content

fix(bedrock): respect AWS profile region instead of hardcoding us-east-1 (#892)#1465

Open
MukundaKatta wants to merge 1 commit intoanthropics:mainfrom
MukundaKatta:fix/bedrock-aws-profile-region
Open

fix(bedrock): respect AWS profile region instead of hardcoding us-east-1 (#892)#1465
MukundaKatta wants to merge 1 commit intoanthropics:mainfrom
MukundaKatta:fix/bedrock-aws-profile-region

Conversation

@MukundaKatta
Copy link
Copy Markdown

Summary

Fixes #892 — when aws_profile= is passed to AnthropicBedrock / AsyncAnthropicBedrock, the region from that profile in ~/.aws/config is now honored.

PR #974 added _infer_region() to fall back to boto3.Session().region_name, but the session was created without profile_name=..., so the default profile's region was always used regardless of what aws_profile= was passed to the constructor. Cross-region setups still ended up on us-east-1 (or whichever region the default profile defines), which is exactly the symptom the original issue describes for users running AWS_PROFILE setups with non-default regions.

Changes

  • src/anthropic/lib/bedrock/_client.py: _infer_region now accepts an optional aws_profile and passes it through to boto3.Session(profile_name=aws_profile). Both AnthropicBedrock.__init__ and AsyncAnthropicBedrock.__init__ forward the constructor's aws_profile argument.
  • tests/lib/test_bedrock.py: regression test test_region_infer_from_constructor_profile covers the constructor-profile path. The existing mock_aws_config fixture is reused (no new test infra).

Resolution order is unchanged: explicit aws_region wins, then AWS_REGION, then the boto3 session (now profile-aware), then us-east-1 fallback.

Test plan

  • ./scripts/test tests/lib/test_bedrock.py
  • Without the fix, test_region_infer_from_constructor_profile returns us-east-2 (default profile) instead of us-west-1 (custom profile) and fails.

…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.
@MukundaKatta MukundaKatta requested a review from a team as a code owner April 28, 2026 15:16
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

Successfully merging this pull request may close these issues.

Bedrock client failing to detect AWS region correctly can cause cross-region inference to fail

1 participant