Fix Bedrock region detection to respect aws_profile and AWS_DEFAULT_REGION#1608
Open
Sarmkadan wants to merge 1 commit into
Open
Fix Bedrock region detection to respect aws_profile and AWS_DEFAULT_REGION#1608Sarmkadan wants to merge 1 commit into
Sarmkadan wants to merge 1 commit into
Conversation
…FAULT_REGION The _infer_region() function was not receiving the aws_profile parameter, so when a user passed aws_profile="my-profile" to AnthropicBedrock(), the profile-specific region from ~/.aws/config was ignored during region inference. The function also only checked AWS_REGION, missing the AWS_DEFAULT_REGION environment variable that boto3 and AWS CLI support. Changes: - Pass aws_profile to _infer_region() so boto3.Session resolves the correct profile-specific region - Check AWS_DEFAULT_REGION as fallback when AWS_REGION is unset - Set self.aws_profile before calling _infer_region() so it is available - Remove redundant "or us-east-1" fallbacks in _prepare_request since _infer_region() already guarantees a non-None return value Fixes anthropics#892
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
Fixes #892
The Bedrock client's
_infer_region()function had two issues causing incorrect region detection:aws_profilenot forwarded: When a user passedaws_profile="my-profile"toAnthropicBedrock(), the profile parameter was not passed through to_infer_region(), soboto3.Session()was created without the profile name. This meant the profile-specific region from~/.aws/configwas ignored, and the client would fall back tous-east-1instead of using the profile's configured region. (TheAWS_PROFILEenv var still worked because boto3 reads it internally, but the explicit constructor parameter did not.)AWS_DEFAULT_REGIONnot checked: The function only checked theAWS_REGIONenv var but notAWS_DEFAULT_REGION, which is also supported by boto3 and the AWS CLI.Changes
_infer_region()now accepts anaws_profileparameter and passes it toboto3.Session(profile_name=...)AWS_DEFAULT_REGIONis checked as a fallback whenAWS_REGIONis unsetself.aws_profileis assigned before_infer_region()is called so the profile is availableor "us-east-1"fallbacks in_prepare_request(both sync and async) since_infer_region()already guarantees a non-None returnResolution order (updated)
AWS_REGIONenvironment variableAWS_DEFAULT_REGIONenvironment variableboto3.Session(respectsAWS_PROFILEenv var,~/.aws/config, and the explicitaws_profileconstructor parameter)us-east-1(legacy fallback)Test plan
test_region_infer_from_aws_default_region- verifiesAWS_DEFAULT_REGIONis respectedtest_aws_region_takes_precedence_over_aws_default_region- verifiesAWS_REGIONwins overAWS_DEFAULT_REGIONtest_region_infer_from_explicit_aws_profile_param- verifies theaws_profileconstructor param is used for region inference (sync client)test_region_infer_from_explicit_aws_profile_param_async- same for async client