Skip to content

fix(bedrock): improve AWS region detection#1310

Closed
hkc5 wants to merge 1 commit intoanthropics:mainfrom
hkc5:fix-bedrock-region-detection
Closed

fix(bedrock): improve AWS region detection#1310
hkc5 wants to merge 1 commit intoanthropics:mainfrom
hkc5:fix-bedrock-region-detection

Conversation

@hkc5
Copy link
Copy Markdown

@hkc5 hkc5 commented Mar 29, 2026

Problem

The Bedrock client was failing to detect AWS region correctly in certain scenarios:

  1. When AWS_DEFAULT_REGION was set (instead of AWS_REGION), it was ignored
  2. When AWS_REGION was set to an empty string, the code didn't fall back to boto3/config file
  3. Users with AWS_PROFILE pointing to a profile with a region in ~/.aws/config would get us-east-1 instead of their configured region

This 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:

  • Check both AWS_REGION and AWS_DEFAULT_REGION environment variables
  • Treat empty strings as unset (falsy), allowing fallback to boto3/config file
  • Maintain backward compatibility with existing behavior (default to us-east-1 if nothing else works)

Changes

  • Modified src/anthropic/lib/bedrock/_client.py - Updated _infer_region() function
  • Added tests for AWS_DEFAULT_REGION support and empty string handling

Fixes #892

- 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
@hkc5 hkc5 requested a review from a team as a code owner March 29, 2026 05:27
@hkc5
Copy link
Copy Markdown
Author

hkc5 commented Mar 30, 2026

Closing to reduce noise. Will reopen if needed.

@hkc5 hkc5 closed this Mar 30, 2026
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