3
votes

I am creating StepFunctions which reference a Lambda function created in separate cloudformation stack. I exported the Lambda arn to CloudFormation export. And I would like to achieve to reference that Lambda function from the StepFunctions by importing exported value.

Here is my cloudformation snippet.

  StepFunction:
    Type: 'AWS::StepFunctions::StateMachine'
    Properties:
      RoleArn: !GetAtt IamRole.Arn
      DefinitionString: 
        Fn::Sub:
          - |-
            {
              "StartAt": "MessageGenerator",
              "States": {
                "MessageGenerator": {
                  "Comment": "generate queue message.",
                  "Type": "Task",
                  "Resource": "${LambdaMessageGenerator}",
                  "ResultPath": "$",
                  "OutputPath": "$",
                  "Next": "WaitSeconds"
                },
                ...
              }
            }
          - LambdaMessageGenerator:
              Fn::ImportValue: some-export-name

I made this by following the answer bellow. Cloudformation - Unable to Import resource

However, aws cloudformation deploy command failed and I got the following error.

Invalid State Machine Definition: 'SCHEMA_VALIDATION_FAILED: Value is not a valid resource ARN at /States/MessageGenerator/Resource' (Service: AWSStepFunctions; Status Code: 400; Error Code: InvalidDefinition; Request ID: 01713d53-4605-11e9-9cf3-c15ff9ce09ae)

Could someone please help me?

2
Can you also share your export configuration? - Kalev
Have you tried removing the Sub and hardcoding the Lambda ARN to make sure it's not related to anything else in your DefinitionString? - Laurent Jalbert Simard
solution please ? Im even stuck on this - Naveen

2 Answers

2
votes

Try using this line: "Resource": "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${LambdaFunctionName}"

In this case you only have to pass the name of the lambda function.

1
votes

Why don't you just use the short form of the ImportValue function?

DefinitionString: 
    Fn::Sub:
      - |-
        {
          "StartAt": "MessageGenerator",
          "States": {
            "MessageGenerator": {
              "Comment": "generate queue message.",
              "Type": "Task",
              "Resource": "${LambdaMessageGenerator}",
              "ResultPath": "$",
              "OutputPath": "$",
              "Next": "WaitSeconds"
            },
            ...
          }
        }
      - LambdaMessageGenerator: !ImportValue some-export-name