Skip to content

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

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

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

Conversation

@alvinttang
Copy link

Summary

Changes

In src/anthropic/lib/bedrock/_client.py:

  1. Updated _infer_region() signature to accept aws_profile: str | None = None
  2. Changed boto3.Session() to boto3.Session(profile_name=aws_profile) so the session respects the profile's configured region
  3. Updated both sync and async constructor call sites to pass aws_profile to _infer_region()
  4. Moved self.aws_profile = aws_profile before the _infer_region() call for clarity

Test plan

  • Verify with an AWS profile that has a non-default region configured (e.g., us-west-2) and confirm AnthropicBedrock(aws_profile='my-profile').aws_region returns that region
  • Verify that when no aws_profile is passed, behavior is unchanged (falls back to default profile, then us-east-1)
  • Verify that explicitly passing aws_region still takes precedence over profile-based inference

🤖 Generated with Claude Code

When using `aws_profile` with `AnthropicBedrock`, the `_infer_region()`
function was creating a `boto3.Session()` without passing the profile
name, causing it to ignore the region configured in the specified AWS
profile and fall back to us-east-1.

This passes the `aws_profile` parameter through to `boto3.Session(
profile_name=aws_profile)` so that the region is correctly inferred
from the user's AWS profile configuration.

Fixes anthropics#892

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@alvinttang alvinttang requested a review from a team as a code owner March 14, 2026 03:53
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