1

The scenario that I want to achieve with AWS Lambda functions:

  1. Make a call to Lambda and receive a response.
  2. After the response is received I need to execute another Lambda function, which does its own job.

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?

1

4 Answers 4

2

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:

enter image description here

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.

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

Comments

1

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.

Comments

0

Possible solution:

  1. Create SQS queue
  2. Put return object as a message in a queue
  3. set SQS queue as a trigger for the second lambda and get the SQS queue message from event object

You can find more about about it in the docs

3 Comments

If I correctly understand your suggestion it would pass data to the second lambda, I do not need that, I do not care about return object from first fn. I simply need first lambda to return to the caller and then that something triggers second lambda's execution.
Passing the data to the second lambda is optional, but by using this approach, you would actually be able to invoke another lambda in the end of the finishing of the first one.
But maybe I misunderstood you, maybe you want to invoke second lambda from client side?
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.