按标签划分的 AWS Cloudfront 分配 ID [英] AWS Cloudfront distribution ID by tag
问题描述
是否可以通过 awscli 或 aws sdk for powershell 通过标签获取 aws cloudfront dist id.我只能通过资源的 ARN 编号获取 ID
is that possible to get aws cloudfront dist id by tag via awscli or aws sdk for powershell. I could only get only ID by ARN number of resource
aws cloudfront list-tags-for-resource --resource XXX
{
"Tags": {
"Items": [
{
"Value": "TEST_APP",
"Key": "CLIENT_APP"
}
]
}
}
更新
通过
cloudfrontdistids=$(aws cloudfront list-distributions | jq -r ".DistributionList.Items[].ARN")
for dist in $cloudfrontdistids
do
if [ $(aws cloudfront list-tags-for-resource --resource $dist | jq -r ".Tags.Items[].Value") == $VALUE ]
then
CLOUDFRONT_DISTRIBUTION_ID=${dist:(-14)}
fi
done
推荐答案
原发帖者提供的答案似乎几乎正确.但是 CLOUDFRONT_DISTRIBUTION_ID 并不总是 14 个字符,因此为了避免拉取附加字符,请改用它:
The answer provided by the original poster seems to be almost correct. But the CLOUDFRONT_DISTRIBUTION_ID is not always 14 characters, so in order to avoid pulling aditional characters use this instead:
CLOUDFRONT_DISTRIBUTION_ID=${dist##*/}
CLOUDFRONT_DISTRIBUTION_ID=${dist##*/}
在 bash 中,它删除了一个前缀模式.在这里,它基本上通过贪婪地删除前缀 */
In bash, it removes a prefix pattern. Here, it's basically giving you everything after the last path separator /, by greedily removing the prefix */
这篇关于按标签划分的 AWS Cloudfront 分配 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!