diff --git a/src/anthropic/lib/bedrock/_client.py b/src/anthropic/lib/bedrock/_client.py index f7298adc..ca6f6fcf 100644 --- a/src/anthropic/lib/bedrock/_client.py +++ b/src/anthropic/lib/bedrock/_client.py @@ -3,6 +3,7 @@ import os from typing import Any, Union, Mapping, TypeVar from typing_extensions import Self, override +import boto3 import httpx @@ -116,9 +117,8 @@ def __init__( self.aws_access_key = aws_access_key - if aws_region is None: - aws_region = os.environ.get("AWS_REGION") or "us-east-1" - self.aws_region = aws_region + self.aws_region = aws_region or os.environ.get("AWS_REGION") or self.get_region_from_boto3() or "us-east-1" + self.aws_session_token = aws_session_token @@ -167,6 +167,12 @@ def _prepare_request(self, request: httpx.Request) -> None: ) request.headers.update(headers) + def get_region_from_boto3( + self + ) -> str | None: + session = boto3.Session() + return session.region_name + def copy( self, *,