如何使用 cli 列出带有特定标签的所有 S3 存储桶? [英] How can i list all the S3 buckets with some specific tag using cli?
问题描述
我正在尝试使用环境和服务标签获取所有 S3 存储桶.我有将近 200 个存储桶...我该怎么做...请帮助我
Am trying to get all the S3 buckets with the environment and service tag. I have almost 200 buckets...How can i do that...Pls help me
aws s3api list-buckets
上面的命令列出了所有带有创建日期的存储桶名称...如何列出所有带有特定标签的存储桶.我搜索了很多博客,但我无法获得获取带有标签的存储桶的确切命令.我尝试使用 jq 命令,例如
The above command listing all the bucket name with the creation date...How can i list all the bucket with the specific tags. I searched so many blogs but i couldn't get the exact command to get the bucket with the tags.I tried using with the jq command like
aws s3api list-buckets | jq .Buckets[].Name
我收到以下错误:
Invalid numeric literal at line 2, column 0
我的 aws s3api list-buckets 输出
My output for aws s3api list-buckets
2019-01-24T04:53:07.000Z | aws-xxx ||
|| 2019-02-18T18:33:15.000Z | aws-yyy
推荐答案
您应该使用get-bucket-tagging"api 来获取与您的存储桶关联的标签.
You should be using the "get-bucket-tagging" api to get the tags associated with your bucket.
https://docs.aws.amazon.com/cli/latest/reference/s3api/get-bucket-tagging.html
我在 github 中找到了一个简单的脚本来完成这项工作.我希望这对你有用.
I've found a simple script in github for doing this job . I hope this works for you.
https://gist.github.com/filipenf/0528d26f0dba78b72b39
这篇关于如何使用 cli 列出带有特定标签的所有 S3 存储桶?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!