Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
492 views
in Technique[技术] by (71.8m points)

amazon web services - 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!

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...