2

I'm trying to use AWS CLI to query S3 objects owned by a specific account AND only if the object has a specific size. Is there any way to do an AND query? These are some of the hundreds of alternatives I've already tried but none of them worked:

aws s3api list-objects-v2 --bucket bucket-name --fetch-owner  --output json --query "'Contents[?Size==`0`].[Key,Owner.ID,Size]' || [?Owner.ID=='00000000111111122222222aaabbbcccdddeeefff']"
aws s3api list-objects-v2 --bucket bucket-name --fetch-owner --output json --query "Contents[?Owner.ID=='00000000111111122222222aaabbbcccdddeeefff']||[?Size==`0`].[Key,Size]"

Any help is welcome!

Thanks in advance!

Ersoy
  • 8,816
  • 6
  • 34
  • 48
Marçal
  • 71
  • 7
  • Have you looked at https://stackoverflow.com/questions/47163478/querying-multiple-values and if so did this help? – Uberhumus Jun 03 '20 at 15:25
  • Excellent. Now answer your own question with what you've learned. :) – Uberhumus Jun 04 '20 at 09:52
  • 1
    @Uberhumus that certainly helped! I couldn't find it, many thanks. For future references, this is the final command: > aws s3api list-objects-v2 --bucket bucket-name --fetch-owner --output json --query 'Contents[?(Owner.ID==`00000000111111122222222aaabbbcccdddeeefff` && Size==0)].[Key,Size,Owner.ID]' – Marçal Jun 04 '20 at 10:00

1 Answers1

5

For future references, this is the final command:

aws s3api list-objects-v2 --bucket bucket-name --fetch-owner --output json --query 'Contents[?(Owner.ID==`00000000111111122222222aaabbbcccdddeeefff` && Size==`0`)].[Key,Size,Owner.ID]'

Thanks a lot @Uberhumus

Marçal
  • 71
  • 7