@@ -221,7 +221,7 @@ class AWSShell(object):
221
221
"""
222
222
223
223
def __init__ (self , completer , model_completer , docs ,
224
- input = None , output = None ):
224
+ env = None , input = None , output = None ):
225
225
self .completer = completer
226
226
self .model_completer = model_completer
227
227
self .history = InMemoryHistory ()
@@ -232,10 +232,12 @@ def __init__(self, completer, model_completer, docs,
232
232
self .refresh_cli = False
233
233
self .key_manager = None
234
234
self ._dot_cmd = DotCommandHandler ()
235
- self ._env = os .environ .copy ()
236
235
self ._profile = None
237
236
self ._input = input
238
237
self ._output = output
238
+ self ._env = env
239
+ if self ._env is None :
240
+ self ._env = os .environ .copy ()
239
241
240
242
# These attrs come from the config file.
241
243
self .config_obj = None
@@ -483,6 +485,11 @@ def profile(self, new_profile_name):
483
485
# it's worth adding an event system or observers just yet.
484
486
# If this gets hard to manage, the complexity of those systems
485
487
# would be worth it.
488
+
489
+ # Remove explicit keys to ensure the profile will be used
490
+ self ._env .pop ('AWS_ACCESS_KEY_ID' , None )
491
+ self ._env .pop ('AWS_SECRET_ACCESS_KEY' , None )
492
+
486
493
self ._env ['AWS_DEFAULT_PROFILE' ] = new_profile_name
487
494
self .completer .change_profile (new_profile_name )
488
495
self ._profile = new_profile_name
0 commit comments