Filter S3 list-objects results to find a key matching a pattern
The --query
argument uses JMESPath expressions. JMESPath has an internal function contains
that allows you to search for a string pattern.
This should give the desired results:
aws s3api list-objects --bucket myBucketName --query "Contents[?contains(Key, `mySearchPattern`)]"
(With Linux I needed to use single quotes '
rather than back ticks `
around mySearchPattern
.)
If you want to search for keys starting with certain characters, you can also use the --prefix
argument:
aws s3api list-objects --bucket myBucketName --prefix "myPrefixToSearchFor"