0

I am facing this issue where I am unable to fetch the input that I am passing to the Map state in the underlying lambda function.

Some context of what is happening: I defined two Lambdas, the first lambda takes the input from user and passes to next state, which is mapped_task in the below example.

The Map task is reading the rows from a csv file present in s3 bucket. The problem is the second lambda receives this row as input, but I also need the input that was being passed to the map state from first lambda, which here is bucket_name and processable_key_name

I am unable to get this parameters in the lambda inside the Map state.

 "Comment": "This is my first step functions state machine",
 "StartAt": "InitialState",
 "States": {
   "InitialState": {
     "Type": "Task",
     "Resource": "arn:aws:lambda:us-east-1:1234566632:function:stepfunctions-serverless-framework-dev-firstFunction",
     "Next": "mapped_task"
   },
   "mapped_task": {
     "Comment": "This state will be handling the payout of each event",
     "Type": "Map",
     "ItemReader": {
       "Resource": "arn:aws:states:::s3:getObject",
       "ReaderConfig": {
         "InputType": "CSV",
         "CSVHeaderLocation": "FIRST_ROW"
       },
       "Parameters": {
         "Bucket.$": "$.bucket_name",
         "Key.$": "$.processable_key_name"
       }
     },
     "ItemProcessor": {
       "ProcessorConfig": {
         "Mode": "DISTRIBUTED",
         "ExecutionType": "STANDARD"
       },
       "StartAt": "FirstMapTask",
       "States": {
         "FirstMapTask": {
           "Type": "Task",
           "Resource": "arn:aws:states:::lambda:invoke",
           "ResultSelector": {
             "name.$": "$.Payload.name",
             "email.$": "$.Payload.email"
           },
           "ResultPath": "$.output",
           "Parameters": {
             "Payload.$": "$",
             "FunctionName": "arn:aws:lambda:us-east-1:1234566632:function:stepfunctions-serverless-framework-dev-secondFunction"
           },
           "End": true
         }
       }
     },
     "Label": "Processabledata",
     "MaxConcurrency": 40,
     "ToleratedFailurePercentage": 100,
     "End": true
   }
 }
}

I tried a few things such as trying to fetch data like this $$.Map.Item.Value from context and also tried to get map_input from lambda but it's not working.

1 Answer 1

0

Can you try something like manual payload for your second lambda? and reference your inputs with variable? like this:

    "Parameters": {
      "FunctionName": "your-lambda-arn",
      "Payload": {
        "sampleKey1": "sampleValue1",
        "key2.$": "$.myStateInput.key",
        "key3": 100
      }
    }

passing parameters example https://docs.aws.amazon.com/step-functions/latest/dg/connect-parameters.html

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

1 Comment

Hey, thanks for the response, I didn't try this but I got the desired results by adding this to my mapped_state "ItemSelector": { "bucket.$": "$.bucket_name", "key_name.$": "$.key_name", "input.$": "$$.Map.Item.Value" }

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.