Search code examples
serverless-frameworkaws-serverless

How to eliminate serverless framework error Template format error


Testing, learning serverless framework. I'm trying to deploy simple/basic state machine with two simple lambda functions. Serverless definition as follows:

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

During deploy, sls is saying my state machine definition is ok: State machine "TransactionChoiceMachine" definition is valid

My environment information:

  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

Setup SLS_DEBUG=* is not helping me much as I do not know js unfortunately.

After serverless deploy command, I'm getting error:

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


Solution

  • Looks like you are referencing something called CustomIamRole in your state machine creation but I cannot see it being created anywhere in the yaml file. Either create the role and use it in creation or remove the depends on part.