CLI not parsing S3 response when --endpoint-url option used with 'aws s3 ls'
Describe the bug When I specify --endpoint-url with an "aws s3 ls" command, I can see that the CLI is receiving the expected XML response from AWS S3, however it fails with KeyError: 'Buckets'.
CLI version number aws-cli/2.2.18 Python/3.8.8 Windows/10 exe/AMD64 prompt/off
Expected behavior The CLI would parse and display the information from AWS S3.
Other information I've tried many different combinations of arguments, but have not been able to get this to work. I am behind a corporate web proxy, with firewall restrictions that mean I cannot test without having to specify an --endpoint-url. The HTTP_PROXY and HTTPS_PROXY environment variables are correctly set.
Logs/output
> aws --endpoint-url https://bucket-eu-west-1-430747123456-model-operations-user.s3-eu-west-1.amazonaws.com s3 ls --debug
2021-07-20 17:43:23,553 - MainThread - awscli.clidriver - DEBUG - CLI version: aws-cli/2.2.18 Python/3.8.8 Windows/10 exe/AMD64
2021-07-20 17:43:23,554 - MainThread - awscli.clidriver - DEBUG - Arguments entered to CLI: ['--endpoint-url', 'https://bucket-eu-west-1-430747123456-model-operations-user.s3-eu-west-1.amazonaws.com', 's3', 'ls', '--debug']
2021-07-20 17:43:23,728 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler <function add_s3 at 0x000002169FA4C940>
2021-07-20 17:43:23,729 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler <function add_ddb at 0x000002169F88E040>
2021-07-20 17:43:23,729 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler <bound method BasicCommand.add_command of <class 'awscli.customizations.configure.configure.ConfigureCommand'>>
2021-07-20 17:43:23,730 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler <function change_name at 0x000002169F82D9D0>
2021-07-20 17:43:23,730 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler <function change_name at 0x000002169F8379D0>
2021-07-20 17:43:23,730 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler <function alias_opsworks_cm at 0x000002169FA5D3A0>
2021-07-20 17:43:23,731 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler <function add_history_commands at 0x000002169F8D4DC0>
2021-07-20 17:43:23,731 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler <bound method BasicCommand.add_command of <class 'awscli.customizations.devcommands.CLIDevCommand'>>
2021-07-20 17:43:23,732 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler <function add_waiters at 0x000002169FA585E0>
2021-07-20 17:43:23,733 - MainThread - botocore.loaders - DEBUG - Loading JSON file: c:\dev\tools\AWSCLIV2\awscli\data\cli.json
2021-07-20 17:43:23,739 - MainThread - botocore.hooks - DEBUG - Event top-level-args-parsed: calling handler <function resolve_types at 0x000002169F9888B0>
2021-07-20 17:43:23,740 - MainThread - botocore.hooks - DEBUG - Event top-level-args-parsed: calling handler <function no_sign_request at 0x000002169F989430>
2021-07-20 17:43:23,741 - MainThread - botocore.hooks - DEBUG - Event top-level-args-parsed: calling handler <function resolve_verify_ssl at 0x000002169F9893A0>
2021-07-20 17:43:23,741 - MainThread - botocore.hooks - DEBUG - Event top-level-args-parsed: calling handler <function resolve_cli_read_timeout at 0x000002169F989550>
2021-07-20 17:43:23,742 - MainThread - botocore.hooks - DEBUG - Event top-level-args-parsed: calling handler <function resolve_cli_connect_timeout at 0x000002169F9894C0>
2021-07-20 17:43:23,742 - MainThread - botocore.hooks - DEBUG - Event top-level-args-parsed: calling handler <built-in method update of dict object at 0x000002169FAEFB80>
2021-07-20 17:43:23,743 - MainThread - awscli.clidriver - DEBUG - CLI version: aws-cli/2.2.18 Python/3.8.8 Windows/10 exe/AMD64 prompt/off
2021-07-20 17:43:23,744 - MainThread - awscli.clidriver - DEBUG - Arguments entered to CLI: ['--endpoint-url', 'https://bucket-eu-west-1-430747123456-model-operations-user.s3-eu-west-1.amazonaws.com', 's3', 'ls', '--debug']
2021-07-20 17:43:23,744 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function add_timestamp_parser at 0x000002169FA4CF70>
2021-07-20 17:43:23,744 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function register_uri_param_handler at 0x000002169F5D13A0>
2021-07-20 17:43:23,745 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function add_binary_formatter at 0x000002169FAB7A60>
2021-07-20 17:43:23,745 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function no_pager_handler at 0x000002169EDCB790>
2021-07-20 17:43:23,746 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function inject_assume_role_provider_cache at 0x000002169F627D30>
2021-07-20 17:43:23,749 - MainThread - botocore.utils - DEBUG - IMDS ENDPOINT: http://169.254.169.254/
2021-07-20 17:43:23,753 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function attach_history_handler at 0x000002169F8D4CA0>
2021-07-20 17:43:23,754 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function inject_json_file_cache at 0x000002169F886EE0>
2021-07-20 17:43:23,754 - MainThread - botocore.hooks - DEBUG - Event building-command-table.s3: calling handler <function add_waiters at 0x000002169FA585E0>
2021-07-20 17:43:23,755 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.custom.s3.anonymous: calling handler <awscli.paramfile.URIArgumentHandler object at 0x00000216A0DFD8B0>
2021-07-20 17:43:23,755 - MainThread - botocore.hooks - DEBUG - Event building-command-table.s3_ls: calling handler <function add_waiters at 0x000002169FA585E0>
2021-07-20 17:43:23,756 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.custom.ls.paths: calling handler <awscli.paramfile.URIArgumentHandler object at 0x00000216A0DFD8B0>
2021-07-20 17:43:23,757 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.custom.ls.anonymous: calling handler <awscli.paramfile.URIArgumentHandler object at 0x00000216A0DFD8B0>
2021-07-20 17:43:23,759 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.custom.ls.page-size: calling handler <awscli.paramfile.URIArgumentHandler object at 0x00000216A0DFD8B0>
2021-07-20 17:43:23,760 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.custom.ls.human-readable: calling handler <awscli.paramfile.URIArgumentHandler object at 0x00000216A0DFD8B0>
2021-07-20 17:43:23,760 - MainThread - botocore.hooks - DEBUG - Event process-cli-arg.custom.ls: calling handler <awscli.argprocess.ParamShorthandParser object at 0x000002169F5F6A30>
2021-07-20 17:43:23,761 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.custom.ls.summarize: calling handler <awscli.paramfile.URIArgumentHandler object at 0x00000216A0DFD8B0>
2021-07-20 17:43:23,762 - MainThread - botocore.hooks - DEBUG - Event process-cli-arg.custom.ls: calling handler <awscli.argprocess.ParamShorthandParser object at 0x000002169F5F6A30>
2021-07-20 17:43:23,763 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.custom.ls.request-payer: calling handler <awscli.paramfile.URIArgumentHandler object at 0x00000216A0DFD8B0>
2021-07-20 17:43:23,764 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: env
2021-07-20 17:43:23,764 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: assume-role
2021-07-20 17:43:23,765 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: assume-role-with-web-identity
2021-07-20 17:43:23,765 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: sso
2021-07-20 17:43:23,766 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: shared-credentials-file
2021-07-20 17:43:23,770 - MainThread - botocore.credentials - INFO - Found credentials in shared credentials file: ~/.aws/credentials
2021-07-20 17:43:23,772 - MainThread - botocore.loaders - DEBUG - Loading JSON file: c:\dev\tools\AWSCLIV2\botocore\data\endpoints.json
2021-07-20 17:43:23,781 - MainThread - botocore.hooks - DEBUG - Event choose-service-name: calling handler <function handle_service_name_alias at 0x000002169E5E75E0>
2021-07-20 17:43:23,978 - MainThread - botocore.loaders - DEBUG - Loading JSON file: c:\dev\tools\AWSCLIV2\botocore\data\s3\2006-03-01\service-2.json
2021-07-20 17:43:23,991 - MainThread - botocore.hooks - DEBUG - Event creating-client-class.s3: calling handler <function add_generate_presigned_post at 0x000002169E594A60>
2021-07-20 17:43:23,991 - MainThread - botocore.hooks - DEBUG - Event creating-client-class.s3: calling handler <function add_generate_presigned_url at 0x000002169E594820>
2021-07-20 17:43:23,994 - MainThread - botocore.endpoint - DEBUG - Setting s3 timeout as (60, 60)
2021-07-20 17:43:23,996 - MainThread - botocore.hooks - DEBUG - Event provide-client-params.s3.ListBuckets: calling handler <function base64_decode_input_blobs at 0x000002169FAB91F0>
2021-07-20 17:43:23,996 - MainThread - botocore.hooks - DEBUG - Event before-parameter-build.s3.ListBuckets: calling handler <function validate_bucket_name at 0x000002169E604790>
2021-07-20 17:43:23,997 - MainThread - botocore.hooks - DEBUG - Event before-parameter-build.s3.ListBuckets: calling handler <bound method S3RegionRedirector.redirect_from_cache of <botocore.utils.S3RegionRedirector object at 0x00000216A10E8220>>
2021-07-20 17:43:23,998 - MainThread - botocore.hooks - DEBUG - Event before-parameter-build.s3.ListBuckets: calling handler <bound method S3ArnParamHandler.handle_arn of <botocore.utils.S3ArnParamHandler object at 0x00000216A10E82E0>>
2021-07-20 17:43:23,999 - MainThread - botocore.hooks - DEBUG - Event before-parameter-build.s3.ListBuckets: calling handler <function generate_idempotent_uuid at 0x000002169E6045E0>
2021-07-20 17:43:23,999 - MainThread - botocore.hooks - DEBUG - Event before-call.s3.ListBuckets: calling handler <function add_expect_header at 0x000002169E604AF0>
2021-07-20 17:43:24,000 - MainThread - botocore.hooks - DEBUG - Event before-call.s3.ListBuckets: calling handler <bound method S3RegionRedirector.set_request_url of <botocore.utils.S3RegionRedirector object at 0x00000216A10E8220>>
2021-07-20 17:43:24,000 - MainThread - botocore.hooks - DEBUG - Event before-call.s3.ListBuckets: calling handler <function inject_api_version_header_if_needed at 0x000002169E606E50>
2021-07-20 17:43:24,001 - MainThread - botocore.endpoint - DEBUG - Making request for OperationModel(name=ListBuckets) with params: {'url_path': '/', 'query_string': '', 'method': 'GET', 'headers': {'User-Agent': 'aws-cli/2.2.18 Python/3.8.8 Windows/10 exe/AMD64 prompt/off command/s3.ls'}, 'body': b'', 'url': 'https://bucket-eu-west-1-430747123456-model-operations-user.s3-eu-west-1.amazonaws.com/', 'context': {'client_region': 'eu-west-1', 'client_config': <botocore.config.Config object at 0x00000216A13D1640>, 'has_streaming_input': False, 'auth_type': None, 'signing': {'bucket': None}}}
2021-07-20 17:43:24,002 - MainThread - botocore.hooks - DEBUG - Event request-created.s3.ListBuckets: calling handler <bound method RequestSigner.handler of <botocore.signers.RequestSigner object at 0x00000216A13D1610>>
2021-07-20 17:43:24,003 - MainThread - botocore.hooks - DEBUG - Event choose-signer.s3.ListBuckets: calling handler <function set_operation_specific_signer at 0x000002169E6044C0>
2021-07-20 17:43:24,004 - MainThread - botocore.hooks - DEBUG - Event before-sign.s3.ListBuckets: calling handler <bound method S3EndpointSetter.set_endpoint of <botocore.utils.S3EndpointSetter object at 0x00000216A10E8370>>
2021-07-20 17:43:24,005 - MainThread - botocore.utils - DEBUG - Using S3 path style addressing.
2021-07-20 17:43:24,008 - MainThread - botocore.auth - DEBUG - Calculating signature using v4 auth.
2021-07-20 17:43:24,008 - MainThread - botocore.auth - DEBUG - CanonicalRequest:
GET
/
host:bucket-eu-west-1-430747123456-model-operations-user.s3-eu-west-1.amazonaws.com
x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
x-amz-date:20210720T164324Z
host;x-amz-content-sha256;x-amz-date
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
2021-07-20 17:43:24,010 - MainThread - botocore.auth - DEBUG - StringToSign:
AWS4-HMAC-SHA256
20210720T164324Z
20210720/eu-west-1/s3/aws4_request
5879ca489f83eab9cc46e5189be558142b171c0da20827ddfa1c1a354a6fdf0c
2021-07-20 17:43:24,012 - MainThread - botocore.auth - DEBUG - Signature:
1227234163dab9d79fc412e54b414e1764f78c36ae66b6f4ea4fac4e19c2c4d6
2021-07-20 17:43:24,012 - MainThread - botocore.endpoint - DEBUG - Sending http request: <AWSPreparedRequest stream_output=False, method=GET, url=https://bucket-eu-west-1-430747123456-model-operations-user.s3-eu-west-1.amazonaws.com/, headers={'User-Agent': b'aws-cli/2.2.18 Python/3.8.8 Windows/10 exe/AMD64 prompt/off command/s3.ls', 'X-Amz-Date': b'20210720T164324Z', 'X-Amz-Content-SHA256': b'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 'Authorization': b'AWS4-HMAC-SHA256 Credential=AKIAWISUUDZRKDAIJ2OY/20210720/eu-west-1/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=1227234163dab9d79fc412e54b414e1764f78c36ae66b6f4ea4fac4e19c2c4d6'}>
2021-07-20 17:43:24,014 - MainThread - botocore.httpsession - DEBUG - Certificate path: c:\dev\tools\AWSCLIV2\botocore\cacert.pem
2021-07-20 17:43:24,015 - MainThread - urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): bucket-eu-west-1-430747123456-model-operations-user.s3-eu-west-1.amazonaws.com:443
2021-07-20 17:43:24,268 - MainThread - urllib3.connectionpool - DEBUG - https://bucket-eu-west-1-430747123456-model-operations-user.s3-eu-west-1.amazonaws.com:443 "GET / HTTP/1.1" 200 None
2021-07-20 17:43:24,269 - MainThread - botocore.parsers - DEBUG - Response headers: {'x-amz-id-2': 'lvmM8e/RRZIphNtlkhEUfPev8dxn4wqHcbVJtu31fAPl2R6C2UBXwh440SNsOx0tH20gArGwVJA=', 'x-amz-request-id': '3H96E5V29BGXNVBX', 'Date': 'Tue, 20 Jul 2021 16:43:25 GMT', 'x-amz-bucket-region': 'eu-west-1', 'Content-Type': 'application/xml', 'Transfer-Encoding': 'chunked', 'Server': 'AmazonS3'}
2021-07-20 17:43:24,270 - MainThread - botocore.parsers - DEBUG - Response body:
b'<?xml version="1.0" encoding="UTF-8"?>\n<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Name>bucket-eu-west-1-430747123456-model-operations-user</Name><Prefix></Prefix><Marker></Marker><MaxKeys>1000</MaxKeys><IsTruncated>false</IsTruncated><Contents><Key>containers/</Key><LastModified>2021-07-05T17:43:11.000Z</LastModified><ETag>"a40b51ba1a40d657885f0261ab32505e"</ETag><Size>0</Size><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>containers/java-8-container-1.gz</Key><LastModified>2021-07-05T17:43:43.000Z</LastModified><ETag>"76c12bc61d460462ac5adcaabef49006-17"</ETag><Size>135815235</Size><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>containers/java-8-container-2.gz</Key><LastModified>2021-07-05T17:44:06.000Z</LastModified><ETag>"f12853ab3f99c2a574a4841a838846bc-17"</ETag><Size>136003198</Size><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>containers/java-8-container-3.gz</Key><LastModified>2021-07-05T17:44:34.000Z</LastModified><ETag>"09f56703029a120fa7e985e1209526da-17"</ETag><Size>136038204</Size><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>deployments/</Key><LastModified>2021-06-15T08:57:04.000Z</LastModified><ETag>"0cb62a7c94f01da2a648fdaf80bc9758"</ETag><Size>0</Size><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>deployments/local-1387481-1626795609722/java-calculator/test-test-calculator-0.1-SNAPSHOT.jar</Key><LastModified>2021-07-20T15:40:11.000Z</LastModified><ETag>"c1ab11c0dec996b5ec2054f3e965eee5"</ETag><Size>3722</Size><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>deployments/local-1387481-1626795609722/java-flow/test-test-flow-0.1-SNAPSHOT.jar</Key><LastModified>2021-07-20T15:40:11.000Z</LastModified><ETag>"277ab57a3304689b0ca38b91aee0e125"</ETag><Size>5989</Size><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>deployments/local-481016-1626795500419/java-calculator/test-test-calculator-0.1-SNAPSHOT.jar</Key><LastModified>2021-07-20T15:38:22.000Z</LastModified><ETag>"876a2f2e00b33f5c9b817633211979a0"</ETag><Size>3722</Size><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>deployments/local-481016-1626795500419/java-flow/test-test-flow-0.1-SNAPSHOT.jar</Key><LastModified>2021-07-20T15:38:22.000Z</LastModified><ETag>"3c616c44e236c50ad3eb7777fc1845fa"</ETag><Size>5989</Size><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>deployments/local-5019082-1623765306908/java-calculator/test-test-calculator-0.1-SNAPSHOT.jar</Key><LastModified>2021-06-15T13:55:08.000Z</LastModified><ETag>"63747c3677ddfa641e8be49404cad343"</ETag><Size>3721</Size><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>deployments/local-5019082-1623765306908/java-flow/test-test-flow-0.1-SNAPSHOT.jar</Key><LastModified>2021-06-15T13:55:07.000Z</LastModified><ETag>"48307ee1188eb4eebbf4d895a14313a7"</ETag><Size>5988</Size><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>javatest/</Key><LastModified>2021-07-20T15:20:21.000Z</LastModified><ETag>"30deddecf82528601a06a5d69c35083c"</ETag><Size>0</Size><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>javatest/test-project-container-1.10.0-SNAPSHOT-executable.jar</Key><LastModified>2021-07-20T15:21:20.000Z</LastModified><ETag>"cd779b94b0e98ab91a2c5fe0bc7c1fe1-6"</ETag><Size>44083716</Size><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>tmp.txt</Key><LastModified>2021-07-13T15:44:34.000Z</LastModified><ETag>"e50a7c06572521743aaaf12b06989430"</ETag><Size>14</Size><StorageClass>STANDARD</StorageClass></Contents></ListBucketResult>'
2021-07-20 17:43:24,274 - MainThread - botocore.hooks - DEBUG - Event needs-retry.s3.ListBuckets: calling handler <bound method RetryHandler.needs_retry of <botocore.retries.standard.RetryHandler object at 0x00000216A10E81C0>>
2021-07-20 17:43:24,275 - MainThread - botocore.retries.standard - DEBUG - Not retrying request.
2021-07-20 17:43:24,275 - MainThread - botocore.hooks - DEBUG - Event needs-retry.s3.ListBuckets: calling handler <bound method S3RegionRedirector.redirect_from_error of <botocore.utils.S3RegionRedirector object at 0x00000216A10E8220>>
2021-07-20 17:43:24,276 - MainThread - botocore.hooks - DEBUG - Event after-call.s3.ListBuckets: calling handler <function enhance_error_msg at 0x000002169FA4CB80>
2021-07-20 17:43:24,276 - MainThread - botocore.hooks - DEBUG - Event after-call.s3.ListBuckets: calling handler <bound method RetryQuotaChecker.release_retry_quota of <botocore.retries.standard.RetryQuotaChecker object at 0x00000216A13D1D90>>
2021-07-20 17:43:24,277 - MainThread - awscli.clidriver - DEBUG - Exception caught in main()
Traceback (most recent call last):
File "awscli\clidriver.py", line 459, in main
File "awscli\customizations\commands.py", line 197, in __call__
File "awscli\customizations\commands.py", line 191, in __call__
File "awscli\customizations\s3\subcommands.py", line 505, in _run_main
File "awscli\customizations\s3\subcommands.py", line 571, in _list_all_buckets
KeyError: 'Buckets'
'Buckets'
c:\dev\tools\AWSCLIV2
Hi @duncanj,
Thanks for reaching out! This is expected, as you need to provide an s3 uri in order for ls to know you're attempting to list object keys and prefixes for a specific bucket rather than listing all buckets. Without one, the CLI expects the result of a ListBuckets call, which contains the Buckets key referenced in the error. Although a ListBuckets call was made by the CLI, it seems s3 converted it to a ListObjectsV2 call since a bucket url was provided. This should work if you're trying to list all objects/prefixes for a given bucket:
aws --endpoint-url https://s3-eu-west-1.amazonaws.com s3 ls s3://<bucket_name>
Hope this helps!
Hi @stobrien89,
Many thanks for the quick reply. I had tried various permutations of this, but hadn't realized that the endpoint url must not include the bucket name.
I can confirm that this example works:
aws --endpoint-url https://s3-eu-west-1.amazonaws.com s3 ls s3://bucket-eu-west-1-430747123456-model-operations-user
Thanks again,
Duncan.
⚠️COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.