Reputation: 25
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?
Upvotes: 1
Views: 6932
Reputation: 469
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).
Upvotes: 4
Reputation: 270334
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.
Upvotes: 0
Reputation: 239005
Yes, you can do this. The perfect tool for that is AWS Step Functions which would allow you to chain your functions.
Upvotes: 2