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

执行AWS CLI put-config-rule时报JSON无效控制字符错误如何解决

问题根因

JSON 标准不允许字符串值内部包含未转义的换行控制字符,你生成的配置文件中Description字段的内容在S3后插入了一个实际换行,触发了格式校验报错。

解决步骤
  • 修正JSON文件的Description字段格式,删除字段内部的实际换行,整段描述放在同一行,如有换行展示需求可使用转义符\n代替实际换行。修正后的配置文件生成命令如下:
cat <<EOF > S3ProhibitPublicReadAccess.json 
{
"ConfigRuleName": "S3PublicReadProhibited",
"Description": "Checks that your S3 buckets do not allow public read access. If an S3 bucket policy or bucket ACL allows public read access, the bucket is noncompliant.",
"Scope": { 
"ComplianceResourceTypes": [ 
 "AWS::S3::Bucket"
] 
}, 
"Source": { 
"Owner": "AWS", 
"SourceIdentifier": "S3_BUCKET_PUBLIC_READ_PROHIBITED"
} 
}
EOF
  • 验证JSON合法性,确认没有格式问题:
# Linux 环境验证
python3 -m json.tool S3ProhibitPublicReadAccess.json

# Windows PowerShell 环境验证
Get-Content S3ProhibitPublicReadAccess.json | ConvertFrom-Json

验证无报错即可继续操作,如有报错可根据提示定位其他格式问题。

  • 重新执行配置规则上传命令:
aws configservice put-config-rule --config-rule file://S3ProhibitPublicReadAccess.json

内容的提问来源于stack exchange,提问作者Alex Ronde

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.26 08:54:06