cfn-lint: Using null in AWS::Serverless::StateMachine in the ResultPath throws incorrect E0000 error

StateMachines allow for a null value in the ResultPath Property to pass input directly to the output

Below is a minimal example of a template that is proper but flagged as invalid

AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31

Resources:
  rLambda:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: python3.6
      InlineCode: |
        def handler(event, context):
          print(event)
          return


  rTestMachine:
    Type: AWS::Serverless::StateMachine
    Properties:
      Definition: 
        StartAt: myState
        States:
          myState:
            Type: Task
            Resource:  !GetAtt rLambda.Arn
            ResultPath: null
            End: true
      Policies:
      - Statement:
        - Sid: Test
          Effect: Allow
          Action:
          - lambda:Invoke*
          Resource: !GetAtt rLambda.Arn

Adding quotes around null does not resolve the issue as the value of the property needs to evaluate to null. An exception for null checking should be added for this Parameter

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 14
  • Comments: 22 (11 by maintainers)

Most upvoted comments

Where are we at with this? It’s 2022 and the problem still persists in CloudFormation with YAML.

that is useful and I wonder if its a bug in how the AWS::LanguageExtensions works.

I misread the question, ignore my previous comment 🤦

Hey, you solved it for me, I swapped to the serverless version, thanks for that.

@niokolra I don’t think the deployment error is related to cfn-lint.

CloudFormation will throw an error if it detects null values in YAML. You can get around that by switching from AWS::StepFunctions::StateMachine to AWS::Serverless::StateMachine and using the serverless transform in your CloudFormation template.

This gets around the issue because behind the scenes the Serverless Transform converts the YAML specified in theAWS::Serverless::StateMachine to stringified JSON before attempting to deploy the template

@kddejong Thank you very much again for your quick response

After your response, I checked every tiny thing that might be causing this and voilà 🥳

My template uses two transformations:

---
AWSTemplateFormatVersion: 2010-09-09
Transform: 
  - 'AWS::LanguageExtensions'
  - 'AWS::Serverless-2016-10-31'

They are in the correct order as stated here: Introducing new language extensions in AWS CloudFormation

Once I removed the AWS::LanguageExtensions (as it is not used in my AWS::Serverless::StateMachineresources), the transformation of SAM works perfectly:

              "     },",
              "     \"Resource\": \"arn:aws:states:::aws-sdk:s3:putObject\",",
              "     \"ResultPath\": null,",
              "     \"Retry\": [",
              "     {",

I hope this is useful for someone else.

Any ETA as to when this will be fixed? it’s forcing our step after our map to handle our incoming input in a remarkably awkward way

Hi,

With SAM v1.36.0 and SAM CLI v1.24.0 versions, we now support adding Metadata to the serverless resources.

Can you verify if that will help with your use case?

Thanks!

If this remained as yaml or json (not as a string) and wasn’t translated by SAM there would be a [/Resources/rTestMachine/Type/DefinitionString/States/myState/ResultPath] 'null' values are not allowed in templates error.