1

I have two AWS Lambda functions doing different things and I want to run the second Lambda only after the first one is completed. It's maybe something simple and I'd like to know how I can do that? I'm aware I can use Step Functions but I haven't used it much. Is this achievable without using Step Functions?

2
  • Step Functions is the proper way to coordinate this but be aware that a Lambda function is just code running in AWS and it can do pretty much anything. It can use the AWS Lambda API to invoke a second Lambda function, for example, passing a given payload and indicating whether or not to wait for the completion of that second Lambda function Commented Mar 9, 2022 at 0:05
  • What does the first Lambda do? Depending on what it does, there might be better ways to run a second Lambda than using Step Functions. Though in most cases, Step Functions would be the way to go. Commented Mar 9, 2022 at 2:11

3 Answers 3

4

Why don't you use Lambda Destinations ?

You can configure your lambda to trigger another lambda in case your first lambda was successfully executed. In case of failure (e.g. if an error is raised with no catch), you can configure the destination to be something else, like SQS, SNS or Event Bridge.

Note that destinations are meant for asynchronous calls, unlike Step Functions. In Step Functions, the flow is halted until the lambda function finished. With Destinations, the second lambda function is called asynchronously.

Moreover, the destination feature will not work if you called the initial lambda function synchronously (e.g. via the Test button).

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

Comments

2

Yes, you can do this. The perfect tool for that is AWS Step Functions which would allow you to chain your functions.

1 Comment

The author mentioned, that he wanted to avoid it, thus @LucasMeier answer is more correct. However, in general, Step Functions is a more robust solution, for sure.
0

The first Lambda function can invoke another Lambda function before it exits. It can simply use a normal invoke() API call to the AWS Lambda service.

You would probably want to make this an asynchronous call, so that the first function does not wait for the second function to finish.

2 Comments

Great, thanks John! After doing some research, this looks like viable option.
don't use this approach if, as @john-rotenstein mentioned, it isn't an asynchronous call because it's an anti-pattern: docs.aws.amazon.com/lambda/latest/operatorguide/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.