简体   繁体   中英

AWS CLI: Error parsing parameter '--config-rule': Invalid JSON:

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
aws configservice put-config-rule --config-rule file://S3ProhibitPublicReadAccess.json

When I go upload my config rule after configuring it gives me the error below of Error parsing parameter '--config-rule': Invalid JSON: Invalid control character at: line 3 column 87 (char 132) JSON received: I first tried this on Windows Powershell to start but then went to try on Linux to see if I would get a different result but am still getting the same error on both machines.

Error:

Error parsing parameter '--config-rule': Invalid JSON: Invalid control character at: line 3 column 87 (char 132)
JSON received: {
"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"
}
}

The answer is right there, this is how i read the error message...

 Invalid JSON: Invalid control character at: line 3 column 87 (char 132)

"Invalid control character" - ie characters like new-lines and line-feeds - ie invisible "control" characters.

"line 3 column 87" - tells you where it thinks the error is (this is not always totally accurate, but its normally close to the error). In this case line 3 column 87 is the end of the below line:

"Description": "Checks that your S3 buckets do not allow public read access. If an S3

"char 132" - this is the ASCII code for the character (its the " character btw) which is what it was expecting to find at the end of the line.

So, what does all the mean, basically it was expecting a " and it found a line ending control character instead.

The fix is to make the description key and value into a single line, so:

"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.",

becomes:

"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.",

I used https://jsonlint.com/ to quickly validate the JSON, and i was able to tweak it and re-validate it until it was correct.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM