Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I am trying to list items of a large bucket while using pagination. I have two separate commands that work but I am having trouble merging them into one such that I can page through responses.
Command 1:
aws s3api list-objects-v2 --bucket <my bucket> --max-items 100
This returns a json with keys "Contents"
and "NextToken"
. Unfortunately I cannot query/filter.
Command 2:
aws s3api list-objects-v2 --bucket <my bucket> --query "<my query>"
This returns a json with a list of my results, which appears to return everything (as described by this question which says the page size is 1000 but the CLI automatically handles paging to return all results).
How can I form a command that lets me --query
while also specifying a --max-items
size limit, and be provided with a NextToken
? The following command returned an empty list:
aws s3api list-objects-v2 --bucket <my bucket> --max-items 100 --query "<my query>"
–
The issue is that NextToken
occurs once in the result set, while Contents
is a list with multiple items.
This command will return both values:
aws s3api list-objects-v2 --bucket my-bucket --max-items 10 --query [NextToken,Contents[].Key]
The output is:
"eyJDb250aW51YXRpb25Ub2tlbiI6IG51bGwsICJib3RvX3RydW5jYXRlX2Ftb3VudCI6IDEwfQ==",
"foo1.docx",
"foo2.jpg",
"2019/06/02/foo3.txt",
"2019/06/02/foo4.js",
"2019/06/02/foo5.py",
"2019/06/02/foo6.html",
"foo7.pdf",
"CreateThumbnail.zip",
"Jbookmarks.html",
"basepart/20191222_1114/foo9.csv"
The first part is the Token, plus a list of object keys.
–
–
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.