Repository: aws/aws-cli

Issue:
aws codeartifact login fails in CircleCI pipeline
Confirm by changing [ ] to [x] below to ensure that it's a bug:
- [x] I've gone though the [User Guide](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) and the [API reference](https://docs.aws.amazon.com/cli/latest/reference/)
- [x] I've searched for [previous similar issues](https://github.com/aws/aws-cli/issues) and didn't find any solution
  
**Describe the bug**
running `aws codeartifact login` results in "list index out of range" error

**SDK version number**
2.2.6

**Platform/OS/Hardware/Device**
Linux/4.15.0-1102-aws exe/x86_64.ubuntu.20

**To Reproduce (observed behavior)**
run the following as after setting up aws credentials in circieci workflow
`aws codeartifact login --tool dotnet --domain **** --domain-owner ******* --repository dotnet --debug`

**Expected behavior**
successfully sign in

**Logs/output**
```
2021-05-27 03:03:25,145 - MainThread - awscli.clidriver - DEBUG - CLI version: aws-cli/2.2.6 Python/3.8.8 Linux/4.15.0-1102-aws exe/x86_64.ubuntu.20
2021-05-27 03:03:25,145 - MainThread - awscli.clidriver - DEBUG - Arguments entered to CLI: ['codeartifact', 'login', '--tool', 'dotnet', '--domain', '***', '--domain-owner', '******', '--repository', 'dotnet', '--debug']
2021-05-27 03:03:25,156 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler <function add_s3 at 0x7f2140d67b80>
2021-05-27 03:03:25,156 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler <function add_ddb at 0x7f2140f24940>
2021-05-27 03:03:25,157 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler <bound method BasicCommand.add_command of <class 'awscli.customizations.configure.configure.ConfigureCommand'>>
2021-05-27 03:03:25,157 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler <function change_name at 0x7f2140f4e160>
2021-05-27 03:03:25,157 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler <function change_name at 0x7f2140f53280>
2021-05-27 03:03:25,157 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler <function alias_opsworks_cm at 0x7f2140d765e0>
2021-05-27 03:03:25,157 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler <function add_history_commands at 0x7f2140eed790>
2021-05-27 03:03:25,157 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler <bound method BasicCommand.add_command of <class 'awscli.customizations.devcommands.CLIDevCommand'>>
2021-05-27 03:03:25,157 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler <function add_waiters at 0x7f2140dbb820>
2021-05-27 03:03:25,157 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /usr/local/aws-cli/v2/2.2.6/dist/awscli/data/cli.json
2021-05-27 03:03:25,159 - MainThread - botocore.hooks - DEBUG - Event top-level-args-parsed: calling handler <function resolve_types at 0x7f2140e1f790>
2021-05-27 03:03:25,159 - MainThread - botocore.hooks - DEBUG - Event top-level-args-parsed: calling handler <function no_sign_request at 0x7f2140e22310>
2021-05-27 03:03:25,159 - MainThread - botocore.hooks - DEBUG - Event top-level-args-parsed: calling handler <function resolve_verify_ssl at 0x7f2140e22280>
2021-05-27 03:03:25,159 - MainThread - botocore.hooks - DEBUG - Event top-level-args-parsed: calling handler <function resolve_cli_read_timeout at 0x7f2140e22430>
2021-05-27 03:03:25,160 - MainThread - botocore.hooks - DEBUG - Event top-level-args-parsed: calling handler <function resolve_cli_connect_timeout at 0x7f2140e223a0>
2021-05-27 03:03:25,160 - MainThread - botocore.hooks - DEBUG - Event top-level-args-parsed: calling handler <built-in method update of dict object at 0x7f2140c8f8c0>
2021-05-27 03:03:25,160 - MainThread - awscli.clidriver - DEBUG - CLI version: aws-cli/2.2.6 Python/3.8.8 Linux/4.15.0-1102-aws exe/x86_64.ubuntu.20 prompt/off
2021-05-27 03:03:25,160 - MainThread - awscli.clidriver - DEBUG - Arguments entered to CLI: ['codeartifact', 'login', '--tool', 'dotnet', '--domain', '****', '--domain-owner', '*********', '--repository', 'dotnet', '--debug']
2021-05-27 03:03:25,160 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function add_timestamp_parser at 0x7f2140d691f0>
2021-05-27 03:03:25,160 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function register_uri_param_handler at 0x7f21418074c0>
2021-05-27 03:03:25,160 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function add_binary_formatter at 0x7f2140cd6040>
2021-05-27 03:03:25,161 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function no_pager_handler at 0x7f21418038b0>
2021-05-27 03:03:25,161 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function inject_assume_role_provider_cache at 0x7f2141766160>
2021-05-27 03:03:25,161 - MainThread - botocore.utils - DEBUG - IMDS ENDPOINT: http://169.254.169.254/
2021-05-27 03:03:25,163 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function attach_history_handler at 0x7f2140eed670>
2021-05-27 03:03:25,163 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function inject_json_file_cache at 0x7f2140f1f820>
2021-05-27 03:03:25,174 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /usr/local/aws-cli/v2/2.2.6/dist/botocore/data/codeartifact/2018-09-22/service-2.json
2021-05-27 03:03:25,179 - MainThread - botocore.hooks - DEBUG - Event building-command-table.codeartifact: calling handler <function inject_commands at 0x7f2140f9db80>
2021-05-27 03:03:25,179 - MainThread - botocore.hooks - DEBUG - Event building-command-table.codeartifact: calling handler <function add_waiters at 0x7f2140dbb820>
2021-05-27 03:03:25,191 - MainThread - botocore.hooks - DEBUG - Event building-command-table.codeartifact_login: calling handler <function add_waiters at 0x7f2140dbb820>
2021-05-27 03:03:25,192 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.custom.login.tool: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7f214044c1f0>
2021-05-27 03:03:25,192 - MainThread - botocore.hooks - DEBUG - Event process-cli-arg.custom.login: calling handler <awscli.argprocess.ParamShorthandParser object at 0x7f21417ada30>
2021-05-27 03:03:25,192 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.custom.login.domain: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7f214044c1f0>
2021-05-27 03:03:25,192 - MainThread - botocore.hooks - DEBUG - Event process-cli-arg.custom.login: calling handler <awscli.argprocess.ParamShorthandParser object at 0x7f21417ada30>
2021-05-27 03:03:25,192 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.custom.login.domain-owner: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7f214044c1f0>
2021-05-27 03:03:25,192 - MainThread - botocore.hooks - DEBUG - Event process-cli-arg.custom.login: calling handler <awscli.argprocess.ParamShorthandParser object at 0x7f21417ada30>
2021-05-27 03:03:25,192 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.custom.login.namespace: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7f214044c1f0>
2021-05-27 03:03:25,192 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.custom.login.duration-seconds: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7f214044c1f0>
2021-05-27 03:03:25,192 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.custom.login.repository: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7f214044c1f0>
2021-05-27 03:03:25,193 - MainThread - botocore.hooks - DEBUG - Event process-cli-arg.custom.login: calling handler <awscli.argprocess.ParamShorthandParser object at 0x7f21417ada30>
2021-05-27 03:03:25,193 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.custom.login.dry-run: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7f214044c1f0>
2021-05-27 03:03:25,193 - MainThread - botocore.hooks - DEBUG - Event process-cli-arg.custom.login: calling handler <awscli.argprocess.ParamShorthandParser object at 0x7f21417ada30>
2021-05-27 03:03:25,193 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: env
2021-05-27 03:03:25,193 - MainThread - botocore.credentials - INFO - Found credentials in environment variables.
2021-05-27 03:03:25,193 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /usr/local/aws-cli/v2/2.2.6/dist/botocore/data/endpoints.json
2021-05-27 03:03:25,200 - MainThread - botocore.hooks - DEBUG - Event choose-service-name: calling handler <function handle_service_name_alias at 0x7f21430eb0d0>
2021-05-27 03:03:25,201 - MainThread - botocore.hooks - DEBUG - Event creating-client-class.codeartifact: calling handler <function add_generate_presigned_url at 0x7f21431093a0>
2021-05-27 03:03:25,203 - MainThread - botocore.endpoint - DEBUG - Setting codeartifact timeout as (60, 60)
2021-05-27 03:03:25,204 - MainThread - botocore.hooks - DEBUG - Event provide-client-params.codeartifact.GetAuthorizationToken: calling handler <function base64_decode_input_blobs at 0x7f2140cd6790>
2021-05-27 03:03:25,204 - MainThread - botocore.hooks - DEBUG - Event before-parameter-build.codeartifact.GetAuthorizationToken: calling handler <function generate_idempotent_uuid at 0x7f2143102160>
2021-05-27 03:03:25,204 - MainThread - botocore.hooks - DEBUG - Event before-call.codeartifact.GetAuthorizationToken: calling handler <function inject_api_version_header_if_needed at 0x7f21430859d0>
2021-05-27 03:03:25,204 - MainThread - botocore.endpoint - DEBUG - Making request for OperationModel(name=GetAuthorizationToken) with params: {'url_path': '/v1/authorization-token', 'query_string': {'domain': '****', 'domain-owner': '*********'}, 'method': 'POST', 'headers': {'User-Agent': 'aws-cli/2.2.6 Python/3.8.8 Linux/4.15.0-1102-aws exe/x86_64.ubuntu.20 prompt/off command/codeartifact.login'}, 'body': b'', 'url': 'https://codeartifact.**************.amazonaws.com/v1/authorization-token?domain=test&domain-owner=*', 'context': {'client_region': '**************', 'client_config': <botocore.config.Config object at 0x7f2140139490>, 'has_streaming_input': False, 'auth_type': None}}
2021-05-27 03:03:25,205 - MainThread - botocore.hooks - DEBUG - Event request-created.codeartifact.GetAuthorizationToken: calling handler <bound method RequestSigner.handler of <botocore.signers.RequestSigner object at 0x7f2140139550>>
2021-05-27 03:03:25,205 - MainThread - botocore.hooks - DEBUG - Event choose-signer.codeartifact.GetAuthorizationToken: calling handler <function set_operation_specific_signer at 0x7f2143102040>
2021-05-27 03:03:25,205 - MainThread - botocore.auth - DEBUG - Calculating signature using v4 auth.
2021-05-27 03:03:25,205 - MainThread - botocore.auth - DEBUG - CanonicalRequest:
POST
/v1/authorization-token
domain=test&domain-owner=****
host:codeartifact.**************.amazonaws.com
x-amz-date:20210527T030325Z

host;x-amz-date
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
2021-05-27 03:03:25,205 - MainThread - botocore.auth - DEBUG - StringToSign:
AWS4-HMAC-SHA256
20210527T030325Z
20210527/**************/codeartifact/aws4_request
d3b4d29845e306fe92afe4ccf77c67ef4dec958fc1f2f3e351d4084970e3a52e
2021-05-27 03:03:25,205 - MainThread - botocore.auth - DEBUG - Signature:
f3610804d0018be5a306ddbe228eb37667a9f2749c246ad6e294b7da3f544302
2021-05-27 03:03:25,205 - MainThread - botocore.endpoint - DEBUG - Sending http request: <AWSPreparedRequest stream_output=False, method=POST, url=https://codeartifact.**************.amazonaws.com/v1/authorization-token?domain=test&domain-owner=*******, headers={'User-Agent': b'aws-cli/2.2.6 Python/3.8.8 Linux/4.15.0-1102-aws exe/x86_64.ubuntu.20 prompt/off command/codeartifact.login', 'X-Amz-Date': b'20210527T030325Z', 'Authorization': b'AWS4-HMAC-SHA256 Credential=********************/20210527/**************/codeartifact/aws4_request, SignedHeaders=host;x-amz-date, Signature=f3610804d0018be5a306ddbe228eb37667a9f2749c246ad6e294b7da3f544302', 'Content-Length': '0'}>
2021-05-27 03:03:25,206 - MainThread - botocore.httpsession - DEBUG - Certificate path: /usr/local/aws-cli/v2/2.2.6/dist/botocore/cacert.pem
2021-05-27 03:03:25,206 - MainThread - urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): codeartifact.**************.amazonaws.com:443
2021-05-27 03:03:26,145 - MainThread - urllib3.connectionpool - DEBUG - https://codeartifact.**************.amazonaws.com:443 "POST /v1/authorization-token?domain=test&domain-owner=**** HTTP/1.1" 200 1262
2021-05-27 03:03:26,146 - MainThread - botocore.parsers - DEBUG - Response headers: {'Date': 'Thu, 27 May 2021 03:03:26 GMT', 'Content-Type': 'application/json', 'Content-Length': '1262', 'Connection': 'keep-alive', 'x-amzn-RequestId': '5f114a70-6c65-4d0b-875d-94fa4b906fe4'}
2021-05-27 03:03:26,146 - MainThread - botocore.parsers - DEBUG - Response body:
b'{"authorizationToken":"eyJ2ZXIiOjEsImlzdSI6MTYyMjA4NDYwNiwiZW5jIjoiQTEyOEdDTSIsInRhZyI6ImhneUM0U3RWcndjazVVM2pEakNPd3ciLCJleHAiOjE2MjIxMjc4MDYsImFsZyI6IkExMjhHQ01LVyIsIml2Ijoic21aOGdDMk1aYkVQS29tMiJ9.416-9zq1ZSN_1b62GB9FMw.C-rB8hPiSKSKy38w.dWerZX-Nxd7uZUTA3CTVGz0BbMqhwXX-paE1F0cG_ypYn5h9OHFGBoR7yFBVvWMBzqL2t2rQwyEMgGi4ajsuiYP6JYnrKEDrzegM4QRelKZWlkLgEoLXnyzj_R9GngJf2R708DpywHEeDwWX_PpQDjRqQciEjrRsjngfcqJGtD62PNC6oI5CW2pnRAvjLj7k2p0SMZpZB0YLvPTyMyOG_aWHCGRUOjEOPk2TV7HOB1-drop1yilTiXIhobH1VQ5Fmeh9H0ilz4wb8TVbYKs0yx7TH0UE2uCzNCMEZY9KRqfXDroVkW-eYd8KzSewupdL1mRkqxFpl8qUMBuMiYfxzV6ovGsYbbq751_FHeI0tzIgR2SEaQ_8lX_POBYvY01Aer1lS9ENci8bc6YpWYggrSoX8ZdNXiht8LEc7ZhN3yoz2gYiXl7S98qZU1WBjkz7VtlHcBZWVlENXLOGOmZXqiQ28VoBAifDiwrXIcsD9zVoxXLoDgLe856bjKw4cqYXrfFfxlcYGP2h-hffbStmADAz3B65CjfeVy3RJAWQZH0TsXy4FrG7DlILMo4fmW1CbaS0Zc3_ebnXANQE8OU8NpnaANS1VLmfZm4E6UmmJ0rHt6J2ePjA_5-Slx29RmsBke1YuT25camS9ROLs4zSFhAqSKB0vzmvx-yAKYM8eYzYH0_yJg6tmIWP1ImnZaMjtDykUlCDfPPKd5EdYULNH7sMbChzZNCWsDuPjumgbDYeIwWgLK2nX5y0HLG--lolEHS_YWvb_qXpvk_WXyGEGq9x9Ym5VqHP7hkZVrQYOWG3VUMNu02aalpj2kt4S5-m0MT6ttHjE0TCluidnYt2v-cDisngW0Oxo0YJDZQ26_SgaQ8OYAN54WbcYKmVAwe4GT8kEaGEkEuIxpJM5fa8IvjmC2PWGQVpPXlADOCJ9Quhb1i5S6W12hJOhj5rlhSyvam2nYRhvQ.tGaSJNV7GjD7U9WWI7wghw","expiration":1.622127806E9}'
2021-05-27 03:03:26,148 - MainThread - botocore.hooks - DEBUG - Event needs-retry.codeartifact.GetAuthorizationToken: calling handler <bound method RetryHandler.needs_retry of <botocore.retries.standard.RetryHandler object at 0x7f2140139fa0>>
2021-05-27 03:03:26,148 - MainThread - botocore.retries.standard - DEBUG - Not retrying request.
2021-05-27 03:03:26,148 - MainThread - botocore.hooks - DEBUG - Event after-call.codeartifact.GetAuthorizationToken: calling handler <bound method RetryQuotaChecker.release_retry_quota of <botocore.retries.standard.RetryQuotaChecker object at 0x7f2140139b20>>
2021-05-27 03:03:26,148 - MainThread - botocore.hooks - DEBUG - Event provide-client-params.codeartifact.GetRepositoryEndpoint: calling handler <function base64_decode_input_blobs at 0x7f2140cd6790>
2021-05-27 03:03:26,148 - MainThread - botocore.hooks - DEBUG - Event before-parameter-build.codeartifact.GetRepositoryEndpoint: calling handler <function generate_idempotent_uuid at 0x7f2143102160>
2021-05-27 03:03:26,148 - MainThread - botocore.hooks - DEBUG - Event before-call.codeartifact.GetRepositoryEndpoint: calling handler <function inject_api_version_header_if_needed at 0x7f21430859d0>
2021-05-27 03:03:26,149 - MainThread - botocore.endpoint - DEBUG - Making request for OperationModel(name=GetRepositoryEndpoint) with params: {'url_path': '/v1/repository/endpoint', 'query_string': {'domain': '****', 'repository': 'dotnet', 'format': 'nuget', 'domain-owner': '******'}, 'method': 'GET', 'headers': {'User-Agent': 'aws-cli/2.2.6 Python/3.8.8 Linux/4.15.0-1102-aws exe/x86_64.ubuntu.20 prompt/off command/codeartifact.login'}, 'body': b'', 'url': 'https://codeartifact.**************.amazonaws.com/v1/repository/endpoint?domain=*&repository=dotnet&format=nuget&domain-owner=********', 'context': {'client_region': '**************', 'client_config': <botocore.config.Config object at 0x7f2140139490>, 'has_streaming_input': False, 'auth_type': None}}
2021-05-27 03:03:26,149 - MainThread - botocore.hooks - DEBUG - Event request-created.codeartifact.GetRepositoryEndpoint: calling handler <bound method RequestSigner.handler of <botocore.signers.RequestSigner object at 0x7f2140139550>>
2021-05-27 03:03:26,149 - MainThread - botocore.hooks - DEBUG - Event choose-signer.codeartifact.GetRepositoryEndpoint: calling handler <function set_operation_specific_signer at 0x7f2143102040>
2021-05-27 03:03:26,149 - MainThread - botocore.auth - DEBUG - Calculating signature using v4 auth.
2021-05-27 03:03:26,149 - MainThread - botocore.auth - DEBUG - CanonicalRequest:
GET
/v1/repository/endpoint
domain=*****&domain-owner=***********&format=nuget&repository=dotnet
host:codeartifact.**************.amazonaws.com
x-amz-date:20210527T030326Z

host;x-amz-date
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
2021-05-27 03:03:26,149 - MainThread - botocore.auth - DEBUG - StringToSign:
AWS4-HMAC-SHA256
20210527T030326Z
20210527/**************/codeartifact/aws4_request
6391eccb49eeb4c009deb1dec05f319d84dd9517ceaafeabc14e9b17df887ad1
2021-05-27 03:03:26,149 - MainThread - botocore.auth - DEBUG - Signature:
01f49e15d304156eaba18ca2fe13d06f8865796a30470c573c2335bd02a648f9
2021-05-27 03:03:26,149 - MainThread - botocore.endpoint - DEBUG - Sending http request: <AWSPreparedRequest stream_output=False, method=GET, url=https://codeartifact.**************.amazonaws.com/v1/repository/endpoint?domain=****&repository=dotnet&format=nuget&domain-owner=**********, headers={'User-Agent': b'aws-cli/2.2.6 Python/3.8.8 Linux/4.15.0-1102-aws exe/x86_64.ubuntu.20 prompt/off command/codeartifact.login', 'X-Amz-Date': b'20210527T030326Z', 'Authorization': b'AWS4-HMAC-SHA256 Credential=********************/20210527/**************/codeartifact/aws4_request, SignedHeaders=host;x-amz-date, Signature=01f49e15d304156eaba18ca2fe13d06f8865796a30470c573c2335bd02a648f9'}>
2021-05-27 03:03:26,150 - MainThread - botocore.httpsession - DEBUG - Certificate path: /usr/local/aws-cli/v2/2.2.6/dist/botocore/cacert.pem
2021-05-27 03:03:26,431 - MainThread - urllib3.connectionpool - DEBUG - https://codeartifact.**************.amazonaws.com:443 "GET /v1/repository/endpoint?domain=****&repository=dotnet&format=nuget&domain-owner=********* HTTP/1.1" 200 108
2021-05-27 03:03:26,432 - MainThread - botocore.parsers - DEBUG - Response headers: {'Date': 'Thu, 27 May 2021 03:03:26 GMT', 'Content-Type': 'application/json', 'Content-Length': '108', 'Connection': 'keep-alive', 'x-amzn-RequestId': '1638397d-b2ee-401a-aba6-8c169c9be5ac'}
2021-05-27 03:03:26,432 - MainThread - botocore.parsers - DEBUG - Response body:
b'{"repositoryEndpoint":"https://******.d.codeartifact.**************.amazonaws.com/nuget/dotnet/"}'
2021-05-27 03:03:26,432 - MainThread - botocore.hooks - DEBUG - Event needs-retry.codeartifact.GetRepositoryEndpoint: calling handler <bound method RetryHandler.needs_retry of <botocore.retries.standard.RetryHandler object at 0x7f2140139fa0>>
2021-05-27 03:03:26,432 - MainThread - botocore.retries.standard - DEBUG - Not retrying request.
2021-05-27 03:03:26,432 - MainThread - botocore.hooks - DEBUG - Event after-call.codeartifact.GetRepositoryEndpoint: calling handler <bound method RetryQuotaChecker.release_retry_quota of <botocore.retries.standard.RetryQuotaChecker object at 0x7f2140139b20>>
2021-05-27 03:03:26,965 - MainThread - awscli.clidriver - DEBUG - Exception caught in main()
Traceback (most recent call last):
  File "awscli/clidriver.py", line 459, in main
  File "awscli/clidriver.py", line 594, in __call__
  File "awscli/customizations/commands.py", line 191, in __call__
  File "awscli/customizations/codeartifact/login.py", line 663, in _run_main
  File "awscli/customizations/codeartifact/login.py", line 122, in login
  File "awscli/customizations/codeartifact/login.py", line 200, in _get_source_to_url_dict
  File "awscli/customizations/codeartifact/login.py", line 213, in _parse_source_name
IndexError: list index out of range

list index out of range

Exited with code exit status 255
```

**Additional context**
Add any other context about the problem here.



Discussion:
Hi @coherent-andyaaz,

Sorry to hear about the issues.  Taking a further look! 
Hi again @coherent-andyaaz,

I was looking at the customization for this command (specifically [`parse_source_name`](https://github.com/aws/aws-cli/blob/develop/awscli/customizations/codeartifact/login.py#L197,L205)) and it looks like the `line` argument is in a different format than expected.  The codeartifact team wrote this customization, so I'll have to reach out to them for a fix— I'm not aware of any CLI workarounds you can use for the time being, but I'll get this submitted to the team right away!
P48141609
Hi @coherent-andyaaz,

I heard back from the efs team and wanted to provide an update: They suspect that your sources may not have an `enabled` or `disabled` tag.  Adding sources through the dotnet commands, or through our login command, _should_ have added those tags, but you can list them by running the following: 

`dotnet nuget list source --format detailed`

and remove (or enable) any source that doesn't have [Enabled] or [Disabled] tag with

`dotnet nuget remove source <SOURCE_NAME>`

or 

`dotnet nuget enable source <SOURCE_NAME>`

Feel free to let us know if that happens to resolve this for you!  


Hey @stobrien89, thanks for your advise. I think I figured out what went wrong. The first time you run a dotnet command, it gives you a welcome message and aws cli probably isn't expecting it. That might be why every time I sshed into the CircleCI instance and tried to run `aws codeartifact login` again it succeeded. I added a `dotnet nuget list source --format detailed`(could be any random dotnet command probably) before `aws codeartifact login` command the error went away. 
![image](https://user-images.githubusercontent.com/83568880/120734556-a81a0b00-c51b-11eb-9039-300f714e613e.png)

Hi @coherent-andyaaz,

Glad you were able to figure it out!  I know the codeartifact team will want to improve the error handling here, so I'll leave this open for tracking purposes.  I'll let you know as soon as I receive an update.

Resolving patch:
diff --git a/awscli/customizations/codeartifact/login.py b/awscli/customizations/codeartifact/login.py
--- a/awscli/customizations/codeartifact/login.py
+++ b/awscli/customizations/codeartifact/login.py
@@ -116,6 +116,9 @@ class NuGetBaseLogin(BaseLogin):
     # source in whichever NuGet.Config file the source was found.
     _SOURCE_ADDED_MESSAGE = 'Added source %s to the user level NuGet.Config\n'
     _SOURCE_UPDATED_MESSAGE = 'Updated source %s in the NuGet.Config\n'
+    # Example line the below regex should match:
+    # 1.  nuget.org [Enabled]
+    _SOURCE_REGEX = re.compile(r'^\d+\.\s+(?P<source_name>.*)\s+\[.*\]')
 
     def login(self, dry_run=False):
         try:
@@ -162,59 +165,43 @@ def login(self, dry_run=False):
         self._write_success_message('nuget')
 
     def _get_source_to_url_dict(self):
-        # The response from listing sources takes the following form:
-        #
-        # Registered Sources:
-        #   1.  Source Name 1 [Enabled]
-        #       https://source1.com/index.json
-        #   2.  Source Name 2 [Disabled]
-        #       https://source2.com/index.json
-        # ...
-        #   100. Source Name 100
-        #       https://source100.com/index.json
-
-       # Or it can be (blank line after Registered Sources:)
-
-       # Registered Sources:
-
-       #   1.  Source Name 1 [Enabled]
-       #       https://source1.com/index.json
-       #   2.  Source Name 2 [Disabled]
-       #       https://source2.com/index.json
-       # ...
-       #   100. Source Name 100
-       #       https://source100.com/index.json
+        """
+        Parses the output of the nuget sources list command.
 
+        A dict is created where the keys are the source names
+        and the values the corresponding URL.
+
+        The output of the command can contain header and footer information
+        around the 'Registered Sources' section, which is ignored.
+
+        Example output that is parsed:
+
+        Registered Sources:
+
+        1. Source Name 1 [Enabled]
+           https://source1.com/index.json
+        2. Source Name 2 [Disabled]
+           https://source2.com/index.json
+        100. Source Name 100 [Activé]
+             https://source100.com/index.json
+        """
         response = self.subprocess_utils.check_output(
             self._get_list_command(),
             stderr=self.subprocess_utils.PIPE
         )
 
-        lines = response.decode("utf-8").splitlines()
+        lines = response.decode(os.device_encoding(1) or "utf-8").splitlines()
         lines = [line for line in lines if line.strip() != '']
 
         source_to_url_dict = {}
-        for i in range(1, len(lines), 2):
-            source_to_url_dict[self._parse_source_name(lines[i])] = \
-                self._parse_source_url(lines[i + 1])
+        for i in range(len(lines)):
+            result = self._SOURCE_REGEX.match(lines[i].strip())
+            if result:
+                source_to_url_dict[result["source_name"]] = \
+                    lines[i + 1].strip()
 
         return source_to_url_dict
 
-    def _parse_source_name(self, line):
-        # A source name line takes the following form:
-        #   1.  NuGet Source [Enabled]
-
-        # Remove the Enabled/Disabled tag.
-        line_without_tag = line.strip().rsplit(' [', 1)[0]
-
-        # Remove the leading number.
-        return line_without_tag.split(None, 1)[1]
-
-    def _parse_source_url(self, line):
-        # A source url line takes the following form:
-        #       https://source.com/index.json
-        return line.strip()
-
     def _get_source_name(self, codeartifact_url, source_dict):
         default_name = '{}/{}'.format(self.domain, self.repository)
 


Test patch:
diff --git a/tests/functional/codeartifact/test_codeartifact_login.py b/tests/functional/codeartifact/test_codeartifact_login.py
--- a/tests/functional/codeartifact/test_codeartifact_login.py
+++ b/tests/functional/codeartifact/test_codeartifact_login.py
@@ -572,6 +572,34 @@ def test_dotnet_login_with_domain_owner_duration_seconds_dry_run(self):
             result.stdout
         )
 
+    _NUGET_SOURCES_LIST_RESPONSE_WITH_EXTRA_NON_LIST_TEXT = b"""\
+Welcome to dotnet 2.0!
+
+Registered Sources:
+  1. Source Name 1 [Enabled]
+     https://source1.com/index.json
+  2. ati-nugetserver [Disabled]
+     http://atinugetserver-env.elasticbeanstalk.com/nuget
+warn : You are running the 'list source' operation with an 'HTTP' source,
+'ati-nugetserver' [http://atinugetserver-env..elasticbeanstalk.com/nuget]'.
+Non-HTTPS access will be removed in a future version. Consider migrating
+to an 'HTTPS' source."""
+
+    @mock.patch('awscli.customizations.codeartifact.login.is_windows', True)
+    def test_dotnet_login_sources_listed_with_extra_non_list_text(self):
+
+        self.subprocess_check_output_patch.return_value = \
+            self._NUGET_SOURCES_LIST_RESPONSE_WITH_EXTRA_NON_LIST_TEXT
+
+        cmdline = self._setup_cmd(tool='dotnet')
+        result = self.cli_runner.run(cmdline)
+        self.assertEqual(result.rc, 0)
+        self._assert_operations_called(package_format='nuget', result=result)
+        commands = [[
+            'dotnet', 'nuget', 'list', 'source', '--format', 'detailed'
+        ]]
+        self._assert_subprocess_check_output_execution(commands)
+
     def test_npm_login_without_domain_owner(self):
         cmdline = self._setup_cmd(tool='npm')
         result = self.cli_runner.run(cmdline)
diff --git a/tests/unit/customizations/codeartifact/test_adapter_login.py b/tests/unit/customizations/codeartifact/test_adapter_login.py
--- a/tests/unit/customizations/codeartifact/test_adapter_login.py
+++ b/tests/unit/customizations/codeartifact/test_adapter_login.py
@@ -243,6 +243,19 @@ class TestDotNetLogin(unittest.TestCase):
   2. Ab[.d7  $#!],   [Disabled]
      https://source2.com/index.json"""
 
+    _NUGET_SOURCES_LIST_RESPONSE_WITH_EXTRA_NON_LIST_TEXT = b"""\
+Welcome to dotnet 2.0!
+
+Registered Sources:
+  1. Source Name 1 [Enabled]
+     https://source1.com/index.json
+  2. ati-nugetserver [Disabled]
+     http://atinugetserver-env.elasticbeanstalk.com/nuget
+warn : You are running the 'list source' operation with an 'HTTP' source,
+'ati-nugetserver' [http://atinugetserver-env..elasticbeanstalk.com/nuget]'.
+Non-HTTPS access will be removed in a future version. Consider migrating
+to an 'HTTPS' source."""
+
     def setUp(self):
         self.domain = 'domain'
         self.domain_owner = 'domain-owner'
@@ -337,6 +350,43 @@ def test_login_dry_run(self):
             stderr=self.subprocess_utils.PIPE
         )
 
+    @mock.patch('awscli.customizations.codeartifact.login.is_windows', False)
+    def test_login_sources_listed_with_extra_non_list_text(self):
+        self.subprocess_utils.check_output.return_value = \
+            self._NUGET_SOURCES_LIST_RESPONSE_WITH_EXTRA_NON_LIST_TEXT
+        self.test_subject.login()
+        self.subprocess_utils.check_output.assert_any_call(
+            self.list_operation_command,
+            stderr=self.subprocess_utils.PIPE
+        )
+        self.subprocess_utils.check_output.assert_called_with(
+            self.add_operation_command_non_windows,
+            stderr=self.subprocess_utils.PIPE
+        )
+
+    @mock.patch('awscli.customizations.codeartifact.login.is_windows', True)
+    def test_login_sources_listed_with_extra_non_list_text_on_windows(self):
+        self.subprocess_utils.check_output.return_value = \
+            self._NUGET_SOURCES_LIST_RESPONSE_WITH_EXTRA_NON_LIST_TEXT
+        self.test_subject.login()
+        self.subprocess_utils.check_output.assert_any_call(
+            self.list_operation_command,
+            stderr=self.subprocess_utils.PIPE
+        )
+        self.subprocess_utils.check_output.assert_called_with(
+            self.add_operation_command_windows,
+            stderr=self.subprocess_utils.PIPE
+        )
+
+    def test_login_sources_listed_with_extra_non_list_text_dry_run(self):
+        self.subprocess_utils.check_output.return_value = \
+                self._NUGET_SOURCES_LIST_RESPONSE_WITH_EXTRA_NON_LIST_TEXT
+        self.test_subject.login(dry_run=True)
+        self.subprocess_utils.check_output.assert_called_once_with(
+            self.list_operation_command,
+            stderr=self.subprocess_utils.PIPE
+        )
+
     @mock.patch('awscli.customizations.codeartifact.login.is_windows', False)
     def test_login_source_name_already_exists(self):
         list_response = 'Registered Sources:\n' \