Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invoke multiple aws lambda functions

How can we invoke multiple AWS Lambda functions one after the other ?For example if an AWS Lambda chain consists of 8 separate lambda functions and each simulate a 1 sec processing event and then invoke the next function in the chain.

like image 583
tarun kumar Sharma Avatar asked Dec 02 '22 13:12

tarun kumar Sharma


2 Answers

I wouldn't recommend using direct invoke to launch your functions. Instead you should consider creating an SNS Topic and subscribing your Lambda functions to this topic. Once a message is published to your topic, all functions will fire at the same time. This solution is also easily scalable.

See more information at official documentation Invoking Lambda functions using Amazon SNS notifications

like image 108
adamkonrad Avatar answered Dec 06 '22 06:12

adamkonrad


With python:

from boto3 import client as botoClient
import json
lambdas = botoClient("lambda")

def lambda_handler(event, context):
    response1 = lambdas.invoke(FunctionName="myLambda1", InvocationType="RequestResponse", Payload=json.dumps(event));
    response2 = lambdas.invoke(FunctionName="myLambda2", InvocationType="RequestResponse", Payload=json.dumps(event));
like image 32
antonio Avatar answered Dec 06 '22 05:12

antonio