AWS CloudFormation InvalidTemplateException错误求助:条件成员需为字符串
解决CloudFormation模板InvalidTemplateException错误:
Every Condition member must be a string. 错误根源分析
你的模板存在两个关键问题:
!Not函数使用错误:CloudFormation的!Not条件函数要求内部传入的是一个条件表达式,而非直接引用条件名称。你写的!Not [ IsLocalExecution ]中,IsLocalExecution是字符串,但!Not需要的是通过!Condition引用的条件逻辑,而非纯字符串名称。- 资源与参数重名:参数
LocalExecution和Lambda资源LocalExecution名称重复,CloudFormation会出现解析冲突,这也可能间接导致模板验证失败。
修正后的模板代码
Parameters: LocalExecution: Type: String Default: "false" Conditions: IsLocalExecution: !Equals [ !Ref LocalExecution, 'true' ] Resources: ProductionDeploy: Type: AWS::Serverless::Function # 修正!Not的用法:用!Condition引用条件 Condition: !Not [ !Condition IsLocalExecution ] Properties: # 你的函数配置... # 修改资源名称,避免和参数重名 LocalExecutionFunction: Type: AWS::Serverless::Function Condition: IsLocalExecution Properties: # 你的函数配置...
验证说明
!Not [ !Condition IsLocalExecution ]:通过!Condition将条件名称转换为CloudFormation可识别的表达式,符合!Not函数的参数要求。- 重命名Lambda资源:确保参数和资源名称唯一,消除命名冲突导致的解析问题。
内容的提问来源于stack exchange,提问作者DarkTrick
相关产品推荐
相关产品推荐

