Is there a way to list CloudFront distributions by tag without downloading them all using ListDistributions?

青春壹個敷衍的年華 提交于 2021-01-28 07:20:40

问题


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!


回答1:


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

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:.*/::'

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 {}


来源:https://stackoverflow.com/questions/65873489/is-there-a-way-to-list-cloudfront-distributions-by-tag-without-downloading-them

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