@@ -81,23 +81,21 @@ def __init__(
8181 if profile_name is not None :
8282 self ._session .set_config_variable ('profile' , profile_name )
8383
84- creds = (
85- aws_access_key_id ,
86- aws_secret_access_key ,
87- aws_session_token ,
88- aws_account_id ,
89- )
90- if any (creds ):
91- if self ._account_id_set_without_credentials (
92- aws_account_id , aws_access_key_id , aws_secret_access_key
93- ):
84+ credentials_kwargs = {
85+ "aws_access_key_id" : aws_access_key_id ,
86+ "aws_secret_access_key" : aws_secret_access_key ,
87+ "aws_session_token" : aws_session_token ,
88+ "aws_account_id" : aws_account_id ,
89+ }
90+
91+ if any (credentials_kwargs .values ()):
92+ if self ._account_id_set_without_credentials (** credentials_kwargs ):
9493 raise NoCredentialsError ()
95- self ._session .set_credentials (
96- aws_access_key_id ,
97- aws_secret_access_key ,
98- aws_session_token ,
99- aws_account_id ,
100- )
94+
95+ if aws_account_id is None :
96+ del credentials_kwargs ["aws_account_id" ]
97+
98+ self ._session .set_credentials (* credentials_kwargs .values ())
10199
102100 if region_name is not None :
103101 self ._session .set_config_variable ('region' , region_name )
@@ -332,8 +330,8 @@ def client(
332330 'aws_account_id' : aws_account_id ,
333331 }
334332 if aws_account_id is None :
335- # Remove aws_account_id for lambda for arbitrary
336- # botocore version mismatches.
333+ # Remove aws_account_id for arbitrary
334+ # botocore version mismatches in AWS Lambda .
337335 del create_client_kwargs ['aws_account_id' ]
338336
339337 return self ._session .create_client (
@@ -562,10 +560,15 @@ def _register_default_handlers(self):
562560 )
563561
564562 def _account_id_set_without_credentials (
565- self , account_id , access_key , secret_key
563+ self ,
564+ * ,
565+ aws_account_id ,
566+ aws_access_key_id ,
567+ aws_secret_access_key ,
568+ ** kwargs ,
566569 ):
567- if account_id is None :
570+ if aws_account_id is None :
568571 return False
569- elif access_key is None or secret_key is None :
572+ elif aws_access_key_id is None or aws_secret_access_key is None :
570573 return True
571574 return False
0 commit comments