How to communicate between lambdas, so that a lambda's input comes from multiple lambdas ?

I’m doing an operation on a huge data file.

Each lambda in the first group of n lambdas work on a section of a file. Then they each have data to send to each lambda of a second group of n lambdas.

How to do this communication ? If I put all n² data in different files on S3, the pricing is quadratic in n. Is there a way to solve this with a linear pricing ?

SNS-SQS fanout?

An alternative is AWS Step Functions. Add lambda as step. 2nd group of lambdas can read the output of earlier lambdas added in the step function.

In the fanout scenario, each lambda invocation receives only one data as input, doesn’t it ?

In my scenario, each lambda invocation of the second group has to receive specific data from each lambda invocation of the first group.

edit: (I’m OP, just on my work computer now.)

Eventbridge

How ? I don’t see how it can make a single lambda invocation receive data from multiple sources.

I did something similar with step functions. I feed the data into it via api gateway and the data goes through 11-15 lambdas in a step function.

Is each invocation in the first batch spawning another n lambdas (so n^2 total invocations) which don’t depend on input from others in the first batch, or are you waiting for them all to finish before running a second batch of n invocations (so 2n in total) where each lambda in the second iteration requires input from all of the invocations in the first batch?

If it’s the first scenario then it seems like a good use case for SQS+SNS, if it’s the second then you might be able to use something like S3 Select, so that each lambda in the first batch can output a single file to s3 and invocations in the second batch can pull out only the sections which are relevant to them.

Second scenario. But the number of S3 Select will be quadratic, isn’t it ?

Sounds like Spark on EMR with extra steps tbh.

Are you sure ? I’m looking through the documentation, and I see nowhere how a lambda invocation can have data fed from multiple sources.

I’ve done this using step functions.

You should investigate Step Functions. They’ll orchestrate everything and you should be able to use the Map state to process in parallel

In the examples, I see parallel flow, but is a many-to-many flow really possible ?

Yes,

Lamda 1 takes in data and checks it against format, outputs same json or error. Next lambda is 1 of 3 enrichment processes, input json comes in, new data is added, forwarded to the next json.

The entire process works with a json data that is fed in and the outputted. During each lambda it adds data or does something with the data.

You control what data is supplied when you invoke the step function via the input. No reason you can’t supply multiple files that are read in parallel as a first step with outputs from each file passed to the next step.

Take a look at Step functions. Entry lambda creates list of entries, then “map” step feeds the lambdas from that list.

https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-map-state.html

I would need something like transpose. Because my lambdas would map each item into a list, and then I need to run the next step on the transpose of the result.

Think of it like a matrix. I want to run the same lambda function on all rows, then a different one on all the columns.

It sounds like you want EMR. You need to split the data up into multiple executors and then coalesce it.

Exactly