fix: pass aws_profile to boto3.Session() in _infer_region()#1243
Open
alvinttang wants to merge 1 commit intoanthropics:mainfrom
Open
fix: pass aws_profile to boto3.Session() in _infer_region()#1243alvinttang wants to merge 1 commit intoanthropics:mainfrom
alvinttang wants to merge 1 commit intoanthropics:mainfrom
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AnthropicBedrock(aws_profile='my-profile')now correctly infers the AWS region from the specified profile's config instead of ignoring it and falling back tous-east-1_infer_region()now accepts an optionalaws_profileparameter and passes it asprofile_nametoboto3.Session()AnthropicBedrockandAsyncAnthropicBedrockconstructors now passaws_profilethrough to_infer_region()Changes
In
src/anthropic/lib/bedrock/_client.py:_infer_region()signature to acceptaws_profile: str | None = Noneboto3.Session()toboto3.Session(profile_name=aws_profile)so the session respects the profile's configured regionaws_profileto_infer_region()self.aws_profile = aws_profilebefore the_infer_region()call for clarityTest plan
us-west-2) and confirmAnthropicBedrock(aws_profile='my-profile').aws_regionreturns that regionaws_profileis passed, behavior is unchanged (falls back to default profile, thenus-east-1)aws_regionstill takes precedence over profile-based inference🤖 Generated with Claude Code