@@ -186,6 +186,15 @@ def display_account(account):
186186 return account_template .format (** account )
187187
188188
189+ def get_account_sorting_key (account ):
190+ only_account_id = ('accountName' not in account and 'emailAddress' not in account )
191+ for key in ('accountName' , 'emailAddress' , 'accountId' ):
192+ value = account .get (key , None )
193+ if value is not None :
194+ return (only_account_id , value .lower ())
195+ return (only_account_id , None )
196+
197+
189198class SSOSessionConfigurationPrompter :
190199 _DEFAULT_SSO_SCOPE = 'sso:account:access'
191200 _KNOWN_SSO_SCOPES = {
@@ -441,9 +450,7 @@ def _handle_multiple_accounts(self, accounts):
441450 'There are {} AWS accounts available to you.\n '
442451 )
443452 uni_print (available_accounts_msg .format (len (accounts )))
444- sorted_accounts = sorted (accounts , key = lambda x : (
445- 'accountName' not in x , x .get ('accountName' ,
446- x .get ('accountId' )).lower ()))
453+ sorted_accounts = sorted (accounts , key = get_account_sorting_key )
447454 selected_account = self ._selector (
448455 sorted_accounts , display_format = display_account
449456 )
0 commit comments