Skip to content

fix(bedrock): use boto3 Session region from aws_profile instead of hardcoded us-east-1#1236

Open
giulio-leone wants to merge 1 commit intoanthropics:mainfrom
giulio-leone:fix/bedrock-region-detection
Open

fix(bedrock): use boto3 Session region from aws_profile instead of hardcoded us-east-1#1236
giulio-leone wants to merge 1 commit intoanthropics:mainfrom
giulio-leone:fix/bedrock-region-detection

Conversation

@giulio-leone
Copy link

@giulio-leone giulio-leone commented Mar 9, 2026

Fixes #892

Problem

When AWS_REGION is unset, AnthropicBedrock falls back to a hardcoded us-east-1 region instead of reading the region from the user's AWS profile. This means users who configure a non-default region via aws_profile (e.g., eu-west-1, ap-southeast-1) are silently routed to us-east-1, causing cross-region inference failures or unexpected latency. The issue is particularly confusing because the user has correctly configured their AWS profile but the SDK ignores it.

Root Cause

The _infer_region() helper did not accept or use the aws_profile parameter. It checked only the AWS_REGION / AWS_DEFAULT_REGION environment variables and, if neither was set, returned us-east-1 unconditionally — even when a valid profile with a configured region was available.

Fix

  • _infer_region() now accepts an optional aws_profile parameter and creates a boto3.Session(profile_name=aws_profile) to read the configured region.
  • Both sync (AnthropicBedrock) and async (AsyncAnthropicBedrock) constructors forward their aws_profile argument to _infer_region().
  • Falls back to us-east-1 only when no profile is provided and no environment variable is set, preserving backward compatibility.

Testing

Two new tests verify:

  • Profile-based region detection returns the correct region from boto3.Session
  • Graceful fallback to us-east-1 when no profile or environment region is available

When aws_profile is passed to AnthropicBedrock or AsyncAnthropicBedrock
constructor, _infer_region() now forwards it to boto3.Session(profile_name=...)
so the region configured in that AWS profile is used instead of falling back
to us-east-1.

Fixes anthropics#892
@giulio-leone giulio-leone requested a review from a team as a code owner March 9, 2026 10:52
@giulio-leone
Copy link
Author

Friendly ping — CI is green, tests pass, rebased on latest. Ready for review whenever convenient. Happy to address any feedback. 🙏

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