I want to trigger a lambda function from multiple lambdas at the same time. The architecture i am following is lambda -- > Step Function--> parallel execution of 2 lambdas --> these two lambda should trigger one lambda. the event from these two lambda should be passed to one lambda.
Till the triggering of two lambda function from step function i have already achieved. to Trigger the lambda function i have written the below code. but only on lambda event is passed to the next lambda.
from boto3 import client as botoClient
import json
lambdas = botoClient("lambda")
def lambda_handler(event, context):
response = lambdas.invoke(FunctionName="lambda-name",
InvocationType="RequestResponse",
Payload=json.dumps(event))
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}
Here's a snippet to invoke a Lambda function, from another Lambda function -
let AWS = require('aws-sdk');
let util = require('util');
module.exports.proxyAPIRequest = async () => {
let client = new AWS.Lambda({
region: "us-east-1"
});
let requestPayload = {
'someKey' : 'someValue'
};
requestPayload = JSON.stringify(requestPayload);
console.log("Payload => ", requestPayload);
let params = {
FunctionName: functionName,
InvocationType: "RequestResponse",
Payload: requestPayload
};
let lambda = util.promisify(client.invoke).bind(client);
let response = await lambda(params);
console.log(response.Payload);
return response.Payload;
};
Ensure your caller Lambda function has permission to invoke another function -
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Lambda permission",
"Action": [
"lambda:InvokeFunction"
],
"Effect": "Allow",
"Resource": "arn:aws:lambda:awsRegion:awsAccountId:function:functionName"
}
]
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.