有没有一种方法可以通过标签列出CloudFront分配,而无需使用ListDistributions全部下载它们? [英] Is there a way to list CloudFront distributions by tag without downloading them all using ListDistributions?
问题描述
这个问题类似,但是唯一的答案是得到所有发行版列表并在本地对其进行过滤,这不是我想要的.
This question is similar, but the only answer there is to get the list of all distributions and filter them locally, which is not what I am looking for.
此页面暗示可能按标签过滤(您可以根据添加的标签搜索和过滤资源" ),但我只是不知道如何!
This page hints that it might be possible to filter by tag ("You can search and filter your resources based on the tags you add"), but I just cannot figure out how!
推荐答案
我只能想到一种方法,因为 aws cloudfront
不直接支持按标签进行get分发.我们可以使用 resourcegroupstaggingapi
cli获取所有云端的ResourceARN,并使用 jq
和 sed
提取DistributionIds
I can only think of one way, since aws cloudfront
doesn't directly support get distributions by tag.
we can use resourcegroupstaggingapi
cli , to get ResourceARNs of all cloudfront and using jq
and sed
extract DistributionIds
例如:标记ApplicationID = APP1111
Ex: Tag ApplicationID=APP1111
aws resourcegroupstaggingapi get-resources --tag-filters Key=ApplicationID,Values=APP1111 --resource-type-filters 'cloudfront' --tags-per-page 100 | jq -r ".ResourceTagMappingList[].ResourceARN" | sed 's:.*/::'
我们可以进一步使用xargs并为每个ID执行get-distribution.
we can further use xargs and execute get-distribution for each Id.
aws resourcegroupstaggingapi get-resources --tag-filters Key=ApplicationID,Values=APP1111 --resource-type-filters 'cloudfront' --tags-per-page 100 | jq -r ".ResourceTagMappingList[].ResourceARN" | sed 's:.*/::' | xargs -I {} aws cloudfront get-distribution --id {}
这篇关于有没有一种方法可以通过标签列出CloudFront分配,而无需使用ListDistributions全部下载它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!