Skip to content

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

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

fix(bedrock): pass aws_profile to boto3.Session in _infer_region#1521
nileshpatil6 wants to merge 1 commit intoanthropics:mainfrom
nileshpatil6:fix/bedrock-infer-region-aws-profile

Conversation

@nileshpatil6
Copy link
Copy Markdown

Problem

When a user passes aws_profile to AnthropicBedrock or AsyncAnthropicBedrock without an explicit aws_region, _infer_region() is called to look up the region. However _infer_region() creates boto3.Session() with no arguments, so the named profile's configured region is silently ignored. The client then falls back to AWS_REGION env var or hard-coded us-east-1.

Minimal reproduction:

# ~/.aws/config has [profile my-profile] with region = eu-west-1
client = AnthropicBedrock(aws_profile="my-profile")
print(client.aws_region)  # prints "us-east-1" instead of "eu-west-1"

Fixes #892.

Fix

Add aws_profile: str | None = None to _infer_region() and forward it to boto3.Session(profile_name=aws_profile). Update both AnthropicBedrock.__init__ and AsyncAnthropicBedrock.__init__ call sites from _infer_region() to _infer_region(aws_profile).

# before
session = boto3.Session()

# after
session = boto3.Session(profile_name=aws_profile)

The change is backward-compatible: when aws_profile is None (the default), boto3.Session(profile_name=None) behaves identically to boto3.Session().

When a user specifies aws_profile, _infer_region() was creating a
boto3.Session() without profile_name, so the profile's configured
region was silently ignored and the client fell back to AWS_REGION env
var or us-east-1.

Fix: accept aws_profile as an optional parameter and forward it to
boto3.Session(profile_name=aws_profile). Update both AnthropicBedrock
and AsyncAnthropicBedrock call sites accordingly.

Fixes anthropics#892
@nileshpatil6 nileshpatil6 requested a review from a team as a code owner May 8, 2026 10:35
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