aws-cli icon indicating copy to clipboard operation
aws-cli copied to clipboard

Unable to get JSON output from `aws s3 ls` command

Open boosh opened this issue 12 years ago • 28 comments

Output from aws s3 ls is always returned as text regardless of the value of the --output parameter.

boosh avatar Mar 20 '14 15:03 boosh

I can confirm that this does not work as expected. If you are looking for JSON output from a specific S3 command, you can however use the low level API:

$ aws s3api list-buckets --output json
...
$ aws s3api list-buckets --output table
...

danielgtaylor avatar Mar 20 '14 18:03 danielgtaylor

The --output parameter is not intended to work with the aws s3 commands. You'll need to use the s3api commands to get different output. Given that --output is a global argument, the only real option we have is to document this.

jamesls avatar Mar 21 '14 01:03 jamesls

this is a mess. S3 is able to sync and to ls but not to output the result as JSON string. S3api is able to output in JSON strings but not able to use sync command or ls. Many different tools and non of them is able to provide this simple featureset.

bes1002t avatar Jun 19 '18 09:06 bes1002t

@bes1002t This works for me

$ aws --output json s3api list-objects --bucket your-bucket --prefix 'some/path/'

As an alternative to:

$ aws --output json s3 ls s3://your-bucket/some/path/

However, I do not see a good reason why JSON output would not be supported by aws s3 ls.

@jamesls Would a PR to add this be accepted?

dagwieers avatar Jul 10 '20 09:07 dagwieers

Perhaps if it's not supported, the command should output a message stating that the output format isn't supported, and at a stretch, suggest an alternative that is supported? Kind of in the way git has the "did you mean" suggestions.

dannystaple avatar Jul 10 '20 13:07 dannystaple

@dagwiers list-objects prefix could be a solution. When I posted my rant I did not know about that command. :P

How about the performance of list-objects vs ls? I experienced some performance issues using list-objects because with large buckets it compares the prefix with EACH file in bucket, which needs a huge amount of time for many files.

bes1002t avatar Jul 13 '20 10:07 bes1002t

@bes1002t That is why I asked if a PR would be accepted. Now it looks like this was by design and will not be improved/fixed.

dagwieers avatar Jul 13 '20 11:07 dagwieers

Yes. On large buckets s3api takes forever. So what is solution really ? Besides using external DB to index s3 objects :)

@nikolai-derzhak-distillery it seems there is no real solution so far. I tried several ways and none of them was a good solution for large buckets. I don't understand why nobody cares about such an performance issue.

bes1002t avatar Jul 27 '20 13:07 bes1002t

Where in the docs does it state aws s3 sync has opted out of the global parameters?

Not on the sync docs. Not on the global docs. 🤢 🤮 🤬

Just spent the past hour+ trying to figure out why no json output; this is about the only real reference confirming the entire --output option is disabled with s3.

nCubed avatar Oct 24 '21 00:10 nCubed

@jamesls Why was this closed as "Completed". The bug still exists and cost me a couple hours trying to figure out why

randomanderson avatar Oct 20 '22 19:10 randomanderson

It's still present:

aws --version
aws-cli/2.9.7

There is not any other type can be picked, but it listed in aws s3 ls help as available, but marked as ignored, why?

DESCRIPTION
       List  S3  objects and common prefixes under a prefix or all S3 buckets.
       Note that the --output and --no-paginate arguments are ignored for this
       command.

and

aws s3 ls help | grep output
       Note that the --output and --no-paginate arguments are ignored for this
          [--output <value>]
       The formatting style for command output.
       Turn on/off color output.
       Disable cli pager for output.
       Rather than showing PRE dirname/ in the output, all the  content  in  a

Hellseher avatar Dec 29 '22 13:12 Hellseher

not working for me either

landsman avatar Feb 02 '23 23:02 landsman

if --output is not supported on aws s3 ls command, then why is it documented? aws s3 ls see: Synopsis [--output <value>]

DonBower avatar Feb 09 '23 20:02 DonBower

There should be a warning printed when an ignored option is used.

Also, it would be nice if this could be documented under GLOBAL OPTIONS, which is where I found the --output option. I didn't notice the note at the top under DESCRIPTION until after reading this issue.

$ aws s3 ls help
GLOBAL OPTIONS
       --debug (boolean)

       Turn on debug logging.

       --endpoint-url (string)

       Override command's default URL with the given URL.

       --no-verify-ssl (boolean)

       By  default, the AWS CLI uses SSL when communicating with AWS services.
       For each SSL connection, the AWS CLI will verify SSL certificates. This
       option overrides the default behavior of verifying SSL certificates.

       --no-paginate (boolean)

       Disable automatic pagination.

       --output (string)

       The formatting style for command output.

       o json

       o text

       o table

       o yaml

       o yaml-stream

       --query (string)

       A JMESPath query to use in filtering the response data.

       --profile (string)

       Use a specific profile from your credential file.

       --region (string)

       The region to use. Overrides config/env settings.
...

P.S. please also printout about using aws <command> help when someone types aws <command> --help

$ aws s3 ls --help
usage: aws [-h] [--profile PROFILE] [--debug]

optional arguments:
  -h, --help         show this help message and exit
  --profile PROFILE
  --debug

I didn't realise that help was an option until reading this issue.

jamest-gaia avatar Jun 09 '23 04:06 jamest-gaia

the issue is still there. No warnings, just a silent ignore of the option.

aws s3 ls --output json

my aws cli version is: 2.12.6

taras-sereda avatar Jul 03 '23 11:07 taras-sereda

13 years later and still not fixed. Unbelievable.

fenixnet-net avatar Aug 22 '23 04:08 fenixnet-net

Guys, can you recheck this, please? It's weird behavior. For example, in Google Cloud CLI I can do this just fine...

cc @kyleknap, @jamesls, @elysahall, @aws-sdk-python-automation, @kdaily

landsman avatar Aug 22 '23 08:08 landsman

I'm still seeing this on current aws CLI tools. In fact, it was searching for issues with the --output global option that brought me here.

It's ludicrous to me that the global option for choosing format exists, and yet fails silently. I'm stuck using awk to parse s3 ls output, which is brittle at best.

AWS runs something like 1/4 of the content on the Internet. How is it that 13 years on this issue has never been sorted out?

fenixnet-net avatar Aug 22 '23 11:08 fenixnet-net

Same.

nkirsch avatar Oct 15 '23 18:10 nkirsch