Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CloudFormation - Unable to import lambda arn in DefinitionString for StepFunctions StateMachine

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?

like image 309
Yasuo Saito Avatar asked Sep 12 '26 15:09

Yasuo Saito


1 Answers

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.

like image 168
Miguel Conde Avatar answered Sep 18 '26 03:09

Miguel Conde