AWS CloudFormation模板中布尔值为何在请求中转为字符串?
Negated value in my CloudFormation template become a string in the actual API request? Nice catch! This is a common quirk of how AWS CloudFormation interacts with certain service APIs, and it’s totally normal—here’s what’s going on:
CloudFormation’s serialization behavior: Even when you define a boolean value (
false) in your CloudFormation template, CloudFormation sometimes converts it to a string ("false") when sending requests to the underlying AWS service. This usually happens when the service’s API accepts both boolean and string representations of true/false values, and CloudFormation opts for the string format to ensure broad compatibility.WAF API flexibility: The AWS WAF API (the one handling your
Predicatesconfiguration) accepts both boolean (true/false) and string ("true"/"false") inputs for theNegatedparameter. So even though the request sends a string, WAF will interpret"false"exactly the same way as the booleanfalse—your rule will work as intended.Template validation vs. API calls: CloudFormation still validates that you provided a valid boolean value in your template during the initial parsing step. The conversion to a string only happens when it’s constructing the actual API request to WAF. This isn’t an error in your template; it’s just how CloudFormation bridges the gap between template syntax and service API requirements.
If you check the WAF API docs, you’ll see that Negated is officially documented as a boolean, but the API is designed to be lenient with string inputs. Your template is perfectly correct, and this conversion won’t impact your WAF rule’s functionality.
内容的提问来源于stack exchange,提问作者Rudziankoŭ

