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

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: 
      # 你的函数配置...

验证说明

  1. !Not [ !Condition IsLocalExecution ]:通过!Condition将条件名称转换为CloudFormation可识别的表达式,符合!Not函数的参数要求。
  2. 重命名Lambda资源:确保参数和资源名称唯一,消除命名冲突导致的解析问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.27 01:34:53