Skip to content

fix(bedrock): pass aws_profile to _infer_region() for correct region detection#1635

Open
Oxygen56 wants to merge 1 commit into
anthropics:mainfrom
Oxygen56:fix/bedrock-aws-profile-region
Open

fix(bedrock): pass aws_profile to _infer_region() for correct region detection#1635
Oxygen56 wants to merge 1 commit into
anthropics:mainfrom
Oxygen56:fix/bedrock-aws-profile-region

Conversation

@Oxygen56
Copy link
Copy Markdown

@Oxygen56 Oxygen56 commented Jun 1, 2026

Summary

When aws_profile is specified in AnthropicBedrock or AnthropicBedrockClient but AWS_REGION is not set, _infer_region() previously created a boto3.Session() without profile_name, defaulting to the 'default' profile and ignoring the caller's explicitly configured profile. This caused cross-region inference failures (HTTP 403) for users with non-default AWS profiles.

Root cause

_infer_region() called boto3.Session() with no arguments, which uses the default profile regardless of what aws_profile the caller specified. The user's profile might have region = us-west-2 configured, but _infer_region would still return us-east-1.

Fix

  • Accept an optional aws_profile parameter in _infer_region()
  • Pass it through to boto3.Session(profile_name=aws_profile)
  • Update both call sites (AnthropicBedrock and AnthropicBedrockClient) to pass aws_profile

Test plan

The fix matches the verified solution from the issue thread (multiple users confirmed it works).

Before:

# profile "prod" has region = us-west-2, but AWS_REGION is unset
client = AnthropicBedrock(aws_profile="prod")
print(client.aws_region)  # us-east-1 (WRONG)

After:

client = AnthropicBedrock(aws_profile="prod")
print(client.aws_region)  # us-west-2 (CORRECT)

Closes #892.

…detection

When aws_profile is specified in AnthropicBedrock or AnthropicBedrockClient
but AWS_REGION is not set, _infer_region() previously created a boto3.Session()
without profile_name, defaulting to the 'default' profile and ignoring the
caller's explicitly configured profile. This caused cross-region inference
failures for users with non-default AWS profiles.

Fix: accept an optional aws_profile parameter in _infer_region() and pass it
through to boto3.Session(profile_name=aws_profile).

Closes anthropics#892.
@Oxygen56 Oxygen56 requested a review from a team as a code owner June 1, 2026 18:13
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