0

Is thegre anyway for me to pass custom variables as an input to AWS step function ?


    processData:
      name: ingest-data
        StartAt: Execute
        States:
          Execute:
            Type: Task
            Resource: "arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:#{AWS::StackName}-ingestIntnlData"
            Next: Check
          Check:
            Type: Choice
            Choices:
              - Variable: "$.results['finished']"
                BooleanEquals: false 
                Next: Wait
              - Variable: "$.results['finished']"
                BooleanEquals: true
                Next: Notify
          Wait:
            Type: Wait
            SecondsPath: "$.waitInSeconds"
            Next: Execute
          Notify:
            Type: Task
            Resource: "arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:#{AWS::StackName}-sendEMail"
            End: true

I have two different stepfunctions which call the same lambda. I'm looking to pass a custom variable to the lambda to differentiate the calls made from the two step functions.

Something like a flag variable or if even there is a way to find out the name of the function which is invoking the lambda, that should also suffice.

Please help me out

3 Answers 3

1

We can build an object in Pass state and pass as input to lambda "Payload.$":"$" simply passes through all the input

{
   "StartAt":"Dummy Step 1 Output",
   "States":{
      "Dummy Step 1 Output":{
         "Type":"Pass",
         "Result":{
            "name":"xyz",
            "testNumber":1
         },
         "ResultPath":"$.inputForMap",
         "Next":"invoke-lambda"
      },
      "invoke-lambda":{
         "End":true,
         "Retry":[
            {
               "ErrorEquals":[
                  "Lambda.ServiceException",
                  "Lambda.AWSLambdaException",
                  "Lambda.SdkClientException"
               ],
               "IntervalSeconds":2,
               "MaxAttempts":6,
               "BackoffRate":2
            }
         ],
         "Type":"Task",
         "Resource":"arn:aws:states:::lambda:invoke",
         "Parameters":{
            "FunctionName":"arn:aws:lambda:us-east-1:111122223333:function:my-lambda",
            "Payload.$":"$"
         }
      }
   }
}

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

You can use the context object and pass the ExecutionId like

    {
    "Comment": "A Catch example of the Amazon States Language using an AWS Lambda Function",
    "StartAt": "nextstep",
    "States": {
        "nextstep": {
        "Type": "Task",
        "Resource": "arn:aws:lambda:eu-central-1:1234567890:function:catcherror",
        "Parameters": {
                        "executionId.$": "$$.Execution.Id"
        },
        "End": true
        }
    }
    }

This give you

arn:aws:states:us-east-1:123456789012:execution:stateMachineName:executionName

As you can see it contains your state machine name.

You can take decisions on them

Comments

0

You can create Lambda functions to use as steps within an workflow created by using AWS Step Functions. For your first step (the Lambda function you use as the first step), you can pass values to it to meet your needs:

https://www.c-sharpcorner.com/article/passing-data-to-aws-lambda-function-and-invoking-it-using-aws-cli/

Then you can pass data between steps using Lambda functions as discussed here:

https://medium.com/@tturnbull/passing-data-between-lambdas-with-aws-step-functions-6f8d45f717c3

You can create Lambda functions in other supported programming languages as well such as Java, as discussed here:

https://github.com/awsdocs/aws-doc-sdk-examples/tree/master/javav2/usecases/creating_workflows_stepfunctions

AS you can see, there is a lot of development options when using Lambda and AWS Step Functions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.