4

I need to launch a LambdaA function and after X minutes I need to launch a LambdaB function with parameters passed from LamdaA

I have testing the following:

APIGW > LambdaA > SQS with delay > SQS can't trigger lambda functions APIGW > LambdaA > SNS > trigger LambdaB . In that case I can't add a delay

I need to do it serverless and without constant pooling for a queue or new messages.

Is there any other possibility to trigger a second lambda function with a "big" delay?

  • with parameters passed from LamdaA <-- How exactly are you (trying to) achieve this? – Dawny33 Aug 10 '17 at 11:43
  • It depends on the solution. If i use SQS, it's just a json in the payload. Any other solution could be using S3 files for that purpose. I'm not worried about this point. The main difficult is launch the second lambda with a delay from the first one and without doing a pooling constantly ;) – RuBiCK Aug 10 '17 at 12:27
5

Use Step Functions. They allow you to coordinate lambda functions and have an inbuilt wait state

  • That's the best method rather than configure more services to achieve the same, definitively – RuBiCK Aug 13 '17 at 21:17
  • I'm having some problems because when I launch the step function I need get back the first lambda a http response to the api gw call. I was unable to find documentation about if that is possible. – RuBiCK Aug 15 '17 at 17:24
  • Have you looked at this? docs.aws.amazon.com/step-functions/latest/dg/… – Robo Aug 16 '17 at 6:14
  • That's the doc I followed to call step functions from Spi Gateway but it doesn't tell you how to send back a response from a lambda which is executed by a Step function. There are the same question in AWS forum without response – RuBiCK Aug 16 '17 at 7:26
  • Checkout docs.aws.amazon.com/apigateway/latest/developerguide/… for the possible integration responses. The example uses passthrough but it looks like the gateway doesn't wait for a response it just starts the state machine – Robo Aug 16 '17 at 7:32
2

From your comment above:

The main difficult is launch the second lambda with a delay from the first one and without doing a pooling constantly

As using SQS queues are an option for you, you can make CloudWatch alarms which can monitor for activity in the queues, and link them up with SNS, which can be used as a trigger for LambdaB.

So, your flow can be:

Lambda1 --> SQS --> CloudWatch metric linked to an alarm --> SNS --> Lambda2
  • 1
    I was testing ClodWatch Events but I'm not able to get a working filter for catching SQS message events . I'll test with Cloudwatch as you suggested – RuBiCK Aug 10 '17 at 12:53
  • CloudWatch alarms --> SNS --> Lambda works. I run multiple workloads with the same pipeline. However, you need to poll SQS from LambdaB though. No escape from that. even if you take the S3 route, you need to receive from S3. – Dawny33 Aug 10 '17 at 13:13
  • That solutions seems to work for the subject of this question :) but unfortunately it doesn't fit in my specific needs. I need a delay of 3-4min but CloudWatch metrics for your Amazon SQS queues are automatically collected and pushed to CloudWatch every five minutes. (Detailed monitoring, or one-minute metrics, is currently unavailable for Amazon SQS.) – RuBiCK Aug 10 '17 at 21:40
  • @RuBiCK You can set that in CloudWatch itself, like example 200 messages in queue for 5 minutes condition will send an alarm only if there were 200 messages in the queue for >= 5 mins – Dawny33 Aug 12 '17 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.