In this article, I will show you how to invoke a lambda function from another lambda function.

This invocation is most helpful in scenarios where you have layers or have common inputs to two functions, but they can’t be integrated, in such cases, we use the invoke method. Well, this is just one of the reasons, there are infinitely many reasons to use this based on your requirement.

For this, I have created two functions, **triggerLambdaFunction **and testFunction. While creating a Lambda function make sure you assign the IAM Role for Lambda, which has Policies of “AWSLambdaFullAccess” attached to it as shown below.

Image for post

IAM Role to be used in lambda functions

The “testFunction” is the one we are going to trigger using another lambda function called “triggerLambdaFunction”. Both are created in the same way and here I’m using Node.js to write the functions.

Image for post

Creating a new Lambda Function

In this triggerLambdaFunction, we have a FunctionCode window where we write our code to invoke another function using AWSLambda-invoke method which is defined in AWS.Lambda-class. So to use this method we should first import our AWS-SDK in the function. This is done to provide JavaScript objects for our AWS service.

#nodejs #lambda #aws #aws-lambda

Invoke AWS Lambda with Another Lambda Function with Nodejs
9.90 GEEK