serverless framework错误模板格式错误如何排除

How to eliminate serverless framework error Template format error

测试,学习无服务器框架。我正在尝试使用两个简单的 lambda 函数部署 simple/basic 状态机。 Serverless定义如下:

frameworkVersion: '2'

app: state-machine
org: macdrorepo

service: state-machine

plugins:
  - serverless-python-requirements
  - serverless-iam-roles-per-function
  - serverless-step-functions
  - serverless-pseudo-parameters

custom:
  pythonRequirements:
    dockerizePip: non-linux
    slim: true
    zip: true

provider:
  name: aws
  runtime: python3.8
  region: eu-central-1
  stage: ${opt:stage, 'testing'}
  timeout: 30

package:
  individually: true
  exclude:
    - node_modules/**
    - .git/**
    - .venv/**

functions:
  processpurchase:
    module: state-machine
    memorySize: 128
    stages:
      - testing
      - dev
    handler: ProcessPurchase.process_purchase

  processrefund:
    module: state-machine
    memorySize: 128
    stages:
      - testing
      - dev
    handler: ProcessRefund.process_refund

stepFunctions:
  validate: true
  stateMachines:
    TransactionChoiceMachine:
      name: ChoiceMachineTest-${self:provider.stage}
      dependsOn: CustomIamRole
      definition:
        Comment: "Purchase refund choice"
        StartAt: ProcessTransaction
        States:
          ProcessTransaction:
            Type: Choice
            Choices:
              - Variable: "$.TransactionType"
                StringEquals: PURCHASE
                Next: PurchaseState
              - Variable: "$.TransactionType"
                StringEquals: REFUND
                Next: RefundState
          PurchaseState:
            Type: Task
            Resource:
              Fn::GetAtt: [processpurchase, Arn]
            End: true
          RefundState:
            Type: Task
            Resource:
              Fn::GetAtt: [processrefund, Arn]
            End: true

在部署期间,sls 说我的状态机定义没问题:State machine "TransactionChoiceMachine" definition is valid

我的环境信息:

  Your Environment Information ---------------------------
     Operating System:          linux
     Node Version:              12.20.0
     Framework Version:         2.14.0
     Plugin Version:            4.1.2
     SDK Version:               2.3.2
     Components Version:        3.4.3

设置 SLS_DEBUG=* 对我帮助不大,因为不幸的是我不懂 js。

执行无服务器部署命令后,出现错误:

Error: The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [CustomIamRole] in the Resources block of the template

看起来你在创建状态机时引用了一个叫做 CustomIamRole 的东西,但我在 yaml 文件的任何地方都看不到它被创建。创建角色并在创建中使用它或删除依赖部分。