Search code examples
aws-lambdaserverless-framework

Cannot parse "serverless.yml": bad indentation of a mapping entry


I am including various resources defined in external files and I also have output variables in the resources section.

resources:
  - ${file(resources/api-gateway-errors.yml)}
  - ${file(resources/dynamodb-table.yml)}
  - ${file(resources/cognito-user-pool.yml)}
  - ${file(resources/cognito-identity-pool.yml)}
  Outputs:
    CampaignStateMachine:
      Value: !Ref CreateCampaignStateFunction
    ProspectStateMachine:
      Value: !Ref ProspectCreateStateFunction

With the above code, I get the following error:

 Cannot parse "serverless.yml": bad indentation of a mapping entry in "/Users/user/serverless/outreachful-api/serverless.yml" (101:3)
  
    98 |   - ${file(resources/dynamodb-tab ...
    99 |   - ${file(resources/cognito-user ...
   100 |   - ${file(resources/cognito-iden ...
   101 |   Outputs:
  ---------^
   102 |     CampaignStateMachine:
   103 |       Value: !Ref CreateCampaignS ...

If I remove all the external files and keep only the Outputs as such, there is no error:

resources:
  Outputs:
    CampaignStateMachine:
      Value: !Ref CreateCampaignStateFunction
    ProspectStateMachine:
      Value: !Ref ProspectCreateStateFunction

How should I fix this bad indentation problem while including resources through external files as well as having the Output variables?

Thanks in advance.


Solution

  • it's a little bit hard without seeing the example files that you're trying to import, but by just looking at your configuration, it seems like you're mixing array notation and object notation in yaml configuration. I believe the Outputs should also be an item of an array, so something like this:

    resources:
      - ${file(resources/api-gateway-errors.yml)}
      - ${file(resources/dynamodb-table.yml)}
      - ${file(resources/cognito-user-pool.yml)}
      - ${file(resources/cognito-identity-pool.yml)}
      - Outputs:
          CampaignStateMachine:
            Value: !Ref CreateCampaignStateFunction
          ProspectStateMachine:
            Value: !Ref ProspectCreateStateFunction