Skip to content

fix(bedrock): pass aws_profile to boto3.Session in _infer_region#1697

Open
Vitaliy-Pikalo wants to merge 1 commit into
anthropics:mainfrom
Vitaliy-Pikalo:fix/bedrock-infer-region-respects-aws-profile
Open

fix(bedrock): pass aws_profile to boto3.Session in _infer_region#1697
Vitaliy-Pikalo wants to merge 1 commit into
anthropics:mainfrom
Vitaliy-Pikalo:fix/bedrock-infer-region-respects-aws-profile

Conversation

@Vitaliy-Pikalo

Copy link
Copy Markdown

Fixes #892

Problem

_infer_region() creates a boto3.Session() without forwarding the aws_profile that was passed to the AnthropicBedrock / AsyncAnthropicBedrock constructor. This means the region is resolved from the default AWS profile, not the requested one — causing a 403 when the profile's region differs from the default.

Example: if aws_profile='prod' maps to us-west-2 in ~/.aws/config, the SDK still defaults to us-east-1 because boto3.Session() ignores the profile name.

Fix

Accept an optional aws_profile: str | None = None parameter in _infer_region() and pass it to boto3.Session(profile_name=aws_profile). Both AnthropicBedrock.__init__ and AsyncAnthropicBedrock.__init__ now forward aws_profile to the helper.

-def _infer_region() -> str:
+def _infer_region(aws_profile: str | None = None) -> str:
     ...
-            session = boto3.Session()
+            session = boto3.Session(profile_name=aws_profile)
     ...
-        self.aws_region = _infer_region() if aws_region is None else aws_region
+        self.aws_region = _infer_region(aws_profile) if aws_region is None else aws_region

When aws_profile is None (the default), boto3.Session(profile_name=None) behaves identically to boto3.Session(), so there is no change for existing callers that don't use a profile.

@Vitaliy-Pikalo Vitaliy-Pikalo requested a review from a team as a code owner June 22, 2026 07:04
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