Skip to content

Bedrock client failing to detect AWS region correctly can cause cross-region inference to fail #892

@charles-dyfis-net

Description

@charles-dyfis-net

I'm using an AWS_PROFILE environment variable where ~/.aws/config specifies region = "us-west-2".

Using boto3.client("bedrock-runtime") to make requests of cross-region endpoints, it properly attempts to communicate with https://bedrock-runtime.us-west-2.amazonaws.com.

By contrast, using anthropic.AnthropicBedrock() is defaulting to us-east-1, and when attempting to use a system-defined cross-region inference profile (as required for Sonnet 3.7) with credentials generated for us-west-2, https://bedrock-runtime.us-east-1.amazonaws.com is throwing a HTTP 403 (without enough supporting detail to make the cause of this failure readily apparent).

Insofar as the dependency set of anthropic-sdk-python includes both boto3 and botocore, consider using Amazon's libraries to more accurately populate the region, rather than falling back to hardcoded us-east-1 whenever AWS_REGION is unset.

Code to do this might look like:

try:
    default_bedrock_region = typing.cast(str, boto3.client("bedrock").meta.region_name)
except botocore.exceptions.NoRegionError:
    default_bedrock_region = 'us-east-1' # fall back to legacy behavior; maybe log?

...whereafter default_bedrock_region can be used as the fallback when no region is explicitly set, rather than the hardcoded us-east-1 literal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bedrockbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions