筛选S3列表对象结果以找到与模式匹配的键 [英] Filter S3 list-objects results to find a key matching a pattern

查看:87
本文介绍了筛选S3列表对象结果以找到与模式匹配的键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用AWS CLI查询存储桶的内容,查看是否存在特定文件,但是存储桶包含数千个文件.如何过滤结果以仅显示与模式匹配的键名?例如:

aws s3api list-objects --bucket myBucketName --query "Contents[?Key==*mySearchPattern*]"

解决方案

--query参数使用JMESPath表达式. JMESPath具有内部功能contains ,该功能可让您搜索字符串模式.

这应该得到预期的结果:

aws s3api list-objects --bucket myBucketName --query "Contents[?contains(Key, `mySearchPattern`)]"

(在Linux中,我需要使用单引号',而不是在mySearchPattern周围使用反引号`.)

如果要搜索带有某些字符的键开头,还可以使用--prefix参数:

aws s3api list-objects --bucket myBucketName --prefix "myPrefixToSearchFor"

I would like to use the AWS CLI to query the contents of a bucket and see if a particular file exists, but the bucket contains thousands of files. How can I filter the results to only show key names that match a pattern? For example:

aws s3api list-objects --bucket myBucketName --query "Contents[?Key==*mySearchPattern*]"

解决方案

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"

这篇关于筛选S3列表对象结果以找到与模式匹配的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆