From a5ad882ae47ed00026152d28ab16c746095c20b1 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 22 Jun 2026 03:02:32 -0400 Subject: [PATCH] fix(bedrock): pass aws_profile to boto3.Session in _infer_region --- src/anthropic/lib/bedrock/_client.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/anthropic/lib/bedrock/_client.py b/src/anthropic/lib/bedrock/_client.py index e91ca176..5c15d751 100644 --- a/src/anthropic/lib/bedrock/_client.py +++ b/src/anthropic/lib/bedrock/_client.py @@ -69,7 +69,7 @@ def _prepare_options(input_options: FinalRequestOptions) -> FinalRequestOptions: return options -def _infer_region() -> str: +def _infer_region(aws_profile: str | None = None) -> str: """ Infer the AWS region from the environment variables or from the boto3 session if available. @@ -79,7 +79,7 @@ def _infer_region() -> str: try: import boto3 - session = boto3.Session() + session = boto3.Session(profile_name=aws_profile) if session.region_name: aws_region = session.region_name except ImportError: @@ -181,7 +181,7 @@ def __init__( self.aws_access_key = aws_access_key - self.aws_region = _infer_region() if aws_region is None else aws_region + self.aws_region = _infer_region(aws_profile) if aws_region is None else aws_region self.aws_profile = aws_profile self.aws_session_token = aws_session_token @@ -361,7 +361,7 @@ def __init__( self.aws_access_key = aws_access_key - self.aws_region = _infer_region() if aws_region is None else aws_region + self.aws_region = _infer_region(aws_profile) if aws_region is None else aws_region self.aws_profile = aws_profile self.aws_session_token = aws_session_token