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
Open
fix(bedrock): use boto3 Session region from aws_profile instead of hardcoded us-east-1#1236giulio-leone wants to merge 1 commit intoanthropics:mainfrom
giulio-leone wants to merge 1 commit intoanthropics:mainfrom
Conversation
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
Author
|
Friendly ping — CI is green, tests pass, rebased on latest. Ready for review whenever convenient. Happy to address any feedback. 🙏 |
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.
Fixes #892
Problem
When
AWS_REGIONis unset,AnthropicBedrockfalls back to a hardcodedus-east-1region instead of reading the region from the user's AWS profile. This means users who configure a non-default region viaaws_profile(e.g.,eu-west-1,ap-southeast-1) are silently routed tous-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 theaws_profileparameter. It checked only theAWS_REGION/AWS_DEFAULT_REGIONenvironment variables and, if neither was set, returnedus-east-1unconditionally — even when a valid profile with a configured region was available.Fix
_infer_region()now accepts an optionalaws_profileparameter and creates aboto3.Session(profile_name=aws_profile)to read the configured region.AnthropicBedrock) and async (AsyncAnthropicBedrock) constructors forward theiraws_profileargument to_infer_region().us-east-1only when no profile is provided and no environment variable is set, preserving backward compatibility.Testing
Two new tests verify:
boto3.Sessionus-east-1when no profile or environment region is available