You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用AWS CLI筛选含指定注释的CloudFront分发?解决查询语法报错

解决AWS CloudFront查询Comment包含指定字符串的NoneType错误

你的问题出在部分CloudFront分发的Comment字段是空值(None),直接用字符串包含判断会触发类型错误。以下是正确的语法:

基础查询命令

aws cloudfront list-distributions --query "DistributionList.Items[?Comment != null && contains(Comment, 'vanity url')]"

关键逻辑说明

  • Comment != null:先过滤掉Comment为空的分发,避免NoneType报错
  • contains(Comment, 'vanity url'):检查Comment字符串中是否包含目标子串

Jenkins流水线中使用示例

如果是在Jenkins的sh步骤里执行,用单引号包裹脚本块避免转义问题:

sh '''
aws cloudfront list-distributions --query "DistributionList.Items[?Comment != null && contains(Comment, 'vanity url')]"
'''

可选:精简输出字段

如果只需要特定信息(比如分发ID、域名),可以追加字段筛选:

aws cloudfront list-distributions --query "DistributionList.Items[?Comment != null && contains(Comment, 'vanity url')].[Id, DomainName]"

内容的提问来源于stack exchange,提问作者Chris F

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 04:26:01