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

SAM模板中Step Function的DefinitionSubstitutions验证失败求助

修复AWS SAM模板中Step Function DefinitionSubstitutions的验证错误

我在AWS SAM模板中定义了名为SfdcOrderEventsStepFunction的Step Function,使用CloudFormation内置函数获取伪参数配置DefinitionSubstitutions,部署时出现模板验证错误,但最终部署成功,所有组件运行正常,需要修复该验证问题。

验证错误信息

资源SfdcOrderEventsStepFunction的模板验证失败,属性无效。请参考资源文档修复模板。属性验证失败信息:
#/DefinitionSubstitutions/AccountId: 2个子模式匹配而非一个
#/DefinitionSubstitutions/AccountId: 预期类型:Boolean,实际类型:String

原SAM模板代码

SfdcOrderEventsStepFunction:
Type: AWS::Serverless::StateMachine
Properties:
  DefinitionSubstitutions:
    Region: !Ref "AWS::Region"
    AccountId: !Ref "AWS::AccountId"
    EventBusPublishTarget: "order-events"
  DefinitionUri: sfn-definition.asl.yml
  Events:
    EventBridgeEvent:
      Type: EventBridgeRule
      Properties:
        EventBusName: sfdc-events
        Pattern:
          # TODO: Update pattern when the salesforce service is ready
          source:
            - prefix: salesforce.com
          detail-type:
            - Order
          detail:
            Payload__c:
              attributes:
                type:
                  - order
        InputPath: $.detail
  Name: sfdc-order-events
  Role: !Sub 'arn:aws:iam::${AWS::AccountId}:role/stepfunction_execution_role'
  Tracing:
    Enabled: true

修复方案

问题原因

SAM的Schema定义中,DefinitionSubstitutions的键值同时支持布尔类型和字符串类型,而!Ref返回的伪参数是字符串类型,触发了Schema的多类型匹配冲突,导致验证报错。

具体修复

将DefinitionSubstitutions中的伪参数引用从!Ref改为!Sub,强制将结果转为明确的字符串类型,消除Schema验证的歧义:

DefinitionSubstitutions:
  Region: !Sub "${AWS::Region}"
  AccountId: !Sub "${AWS::AccountId}"
  EventBusPublishTarget: "order-events"

原理说明

!Sub函数会将伪参数解析为字符串并返回,让SAM的Schema验证明确识别该值为字符串类型,既解决了验证报错问题,又不会影响实际部署后的功能运行。

内容的提问来源于stack exchange,提问作者Santiago Ortiz Ceballos

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.23 04:54:16