Filter S3 list-objects results to find a key matching a pattern

流过昼夜 提交于 2019-11-30 06:43:21

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"

I tried on Ubuntu 14, awscli 1.2 --query "Contents[?contains(Key,'stati')].Key" --query "Contents[?contains(Key,\'stati\')].Key" --query "Contents[?contains(Key,stati)].Key"

Illegal token value '?contains(Key,'stati')].Key'

After upgraded the aws version to 1.16 , worked with

--query "Contents[?contains(Key,'stati')].Key"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!