Invoke Multiple Lambdas using AWS step functions

Viewed 428

I have two lambdas L1 and L2. Iam starting state machine in L1. I have environment variable for L1 i.e.,E1. Basically E1 is list of space separated values for which I need to do some Hashfunction in L1 and for each value I need to trigger a separate instance of Lambda L2 with that value and Hash(value) as input

eg: E1 - "1 2 3" and hash(1) = stack, hash(2) = over, hash(3) = flow Three instances of L2 should be triggered with (i, hash(i)) as input/payload to L2

How to achieve this using step functions

1 Answers

You can do this by using a Map state. The easiest way would be to have the output of the first function be an array of the inputs to the second. So something like this:

[
  {
    i: 1,
    iHash: 'hashed 1'
  },
  {
    i: 2,
    iHash: 'hashed 2'
  }
  .
  .
  .
]

In the Map state you set the iterator value to the array from the output. The value of each element of the array will be the input to the first state inside the Map state. Inside the Map state you just need to have another Task state that is your second Lambda function, and pass in $ to the Payload.

Related