Reputation: 25
The scenario that I want to achieve with AWS Lambda functions:
The pain point for me is how to trigger the second Lambda without a second call. I am trying to do this in AWS Step Functions, however, I believe I can not return something from the first function and then carry on with executing the second one, or can I?
Upvotes: 1
Views: 5496
Reputation: 698
This can be easily achieved by AWS Step Function itself. You can simply create two Task State each one for your Lambda and if you don't want to pass any of the input in any of the lambda that is fine too because it's not necessary at all.
So in short your simple step function will look like:
This is going to run in sequence.
You can simply define your state like:
"States": {
"FirstLambda": {
"Type": "Task",
"Resource": "<first-lambda-arn>",
"TimeoutSeconds": 9000,
"Next": "SecondLambda"
},
"SecondLambda": {
"Type": "Task",
"Resource": "<second-lambda-arn>",
"TimeoutSeconds": 9000,
"End": true
}
}
You need not to to pass anything as payload to lambda if you don't want too. and if required you can pass the input of first lambda to another lambda function using "ResultPath":"$.output"
in the first state definition above (definition for First Lambda.) and passing that $.output
within payload of next one.
Upvotes: 2
Reputation: 357
I have a similar setup between some of my lambda functions.
I would just have the calling service send an http request to the designated endpoint of the second lambda function when it recieves a response from the first lambda function.
That of course would require the second lambda function to have an endpoint setup to trigger the job.
Upvotes: 0
Reputation: 9624
You may achieve this by using aws lambda destinations
.
For each execution status such as Success or Failure you can choose one of four destinations: another Lambda function, SNS, SQS, or EventBridge. Lambda can also be configured to route different execution results to different destinations.
This post may give you some insights.
Upvotes: 1