Avi Zloof
Avi Zloof

Reputation: 2973

Lambda function calling another Lambda function

I want to create a Lambda function that runs through S3 files and if needed triggers other Lambda functions to parse the files in parallel. Is this possible?

Upvotes: 1

Views: 2667

Answers (2)

baggero
baggero

Reputation: 106

If I understand your problem correctly you want one lambda that goes through a list of files in a S3-bucket. Some condition will decide whether a file should be parsed or not. For the files that should be parsed you want another 'file-parsing' lambda to parse those files.

To do this you will need two lambdas - one 'S3 reader' and one 'S3 file parser'.

For triggering the 'S3 file parser' lambda you have many few different options. Here are a two:

  1. Trigger it using a SNS topic. (Here is an article on how to do that). If you have a very long list of files this might be an issue, as you most likely will surpass the number of instances of a lambda that can run in parallel.
  2. Trigger it by invoking it with the AWS SDK. (See the article 'Leon' posted as comment to see how to do that.) What you need to consider here is that a long list of files might cause the 'S3 reader' lambda that controls the invocation to timeout since there is a 5 min runtime limit for a lambda.

Depending on the actual use case another potential solution is to just have one lambda that gets triggered when a file gets uploaded to the S3 bucket and let it decide whether it should get parsed or not and then parse it if needed. More info about how to do that can be found in this article and this tutorial.

Upvotes: 1

Mark B
Mark B

Reputation: 201008

Yes it's possible. You would use the AWS SDK (which is included in the Lambda runtime environment for you) to invoke other Lambda functions, just like you would do in code running anywhere else.

You'll have to specify which language you are writing the Lambda function in if you want a more detailed answer.

Upvotes: 2

Related Questions