@@ -69,20 +69,20 @@ def _prepare_options(input_options: FinalRequestOptions) -> FinalRequestOptions:
6969 return options
7070
7171
72- def _infer_region (aws_session : boto3 .Session | None = None ) -> str :
72+ def _infer_region (aws_session : boto3 .Session | None = None , aws_profile : str | None = None ) -> str :
7373 """
7474 Infer the AWS region from the environment variables or
7575 from the boto3 session if available.
7676 """
7777 if aws_session is not None and aws_session .region_name :
7878 return aws_session .region_name
7979
80- aws_region = os .environ .get ("AWS_REGION" )
80+ aws_region = os .environ .get ("AWS_REGION" ) or os . environ . get ( "AWS_DEFAULT_REGION" )
8181 if aws_region is None :
8282 try :
8383 import boto3
8484
85- session = boto3 .Session ()
85+ session = boto3 .Session (profile_name = aws_profile )
8686 if session .region_name :
8787 aws_region = session .region_name
8888 except ImportError :
@@ -168,7 +168,7 @@ def __init__(
168168 self .aws_access_key = aws_access_key
169169
170170 self .aws_session = aws_session
171- self .aws_region = aws_region or _infer_region (aws_session )
171+ self .aws_region = aws_region or _infer_region (aws_session , aws_profile = aws_profile )
172172 self .aws_profile = aws_profile
173173
174174 self .aws_session_token = aws_session_token
@@ -322,7 +322,7 @@ def __init__(
322322 self .aws_access_key = aws_access_key
323323
324324 self .aws_session = aws_session
325- self .aws_region = aws_region or _infer_region (aws_session )
325+ self .aws_region = aws_region or _infer_region (aws_session , aws_profile = aws_profile )
326326 self .aws_profile = aws_profile
327327
328328 self .aws_session_token = aws_session_token
0 commit comments