fix(bedrock): improve AWS region detection#1310
Closed
hkc5 wants to merge 1 commit intoanthropics:mainfrom
Closed
Conversation
- Check both AWS_REGION and AWS_DEFAULT_REGION environment variables - Treat empty strings as unset, falling back to boto3/config file - Maintain backward compatibility with existing behavior Fixes anthropics#892
Author
|
Closing to reduce noise. Will reopen if needed. |
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.
Problem
The Bedrock client was failing to detect AWS region correctly in certain scenarios:
AWS_DEFAULT_REGIONwas set (instead ofAWS_REGION), it was ignoredAWS_REGIONwas set to an empty string, the code didn't fall back to boto3/config fileAWS_PROFILEpointing to a profile with a region in~/.aws/configwould getus-east-1instead of their configured regionThis caused cross-region inference to fail with HTTP 403 errors when credentials were generated for a different region than the one being used.
Solution
Updated
_infer_region()to:AWS_REGIONandAWS_DEFAULT_REGIONenvironment variablesus-east-1if nothing else works)Changes
src/anthropic/lib/bedrock/_client.py- Updated_infer_region()functionAWS_DEFAULT_REGIONsupport and empty string handlingFixes #892