Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS step function: chosing a Resource dynamically

I would like to dynamically chose an AWS Lambda worker based on the result coming from a previous step. Something like {"Resource": "$.worker_arn"}.

"RunWorkers": {
      "Type": "Map",
      "MaxConcurrency": 0,
      "InputPath": "$.output",
      "ResultPath": "$.raw_result",
      "Iterator": {
        "StartAt": "CallWorkerLambda",
        "States": {
          "CallWorkerLambda": {
            "Type": "Task",
            "Resource": "$$.worker_arn",
            "End": true
          }
        }
      },
      "Next": "Aggregate"
    },

The input from previous step is expected as following: [{"worker_arn":..., "output":1}, {"worker_arn":..., "output":1}, ...], where worker_arn is the same among all workers.

When I write a pipeline like this, the linter complains that it expects an ARN.

Are there any options better than wrapping my worker lambda into another lambda?

like image 675
Dima Lituiev Avatar asked Sep 15 '26 09:09

Dima Lituiev


1 Answers

Using "Resource": "arm:aws:states:::lambda:invoke" you can set the "FunctionName" field in "Parameters" at runtime using a Path.

{ 
  "StartAt":"CallLambda", 
  "States":{ 
    "CallLambda":{ 
      "Type":"Task",    
      "Resource": "arn:aws:states:::lambda:invoke", 
      "Parameters":{ 
        "FunctionName.$":"$.MyFunction",
        "Payload.$": "$"
       }, 
      "End":true 
    } 
  } 
}

https://docs.aws.amazon.com/step-functions/latest/dg/connect-lambda.html

like image 112
adamwong Avatar answered Sep 18 '26 00:09

adamwong