Deploy Node.js app using Lambda , API gateway through Terraform Modules.

jaffar shaik
2 min readOct 2, 2022

Description :

In this sample project ,We will deploy a node.js application by writing a Lamda function and mapping it to an existing Apigateway.

step1:

creating a lamda function :

the source code to create a lambda function is available in below repository .

Jaffarterraform786/lambda (github.com)

  • The name of the function which we are giving is as “nodejs-helloworld-function” .
  • we will be placing the source code in a bucket with file name “helloworld.zip” .
  • we will be passing “apigatewayid” to the variable that is fetched from aws console as shown below.
Figure :Apigateway

now lets pull the code from Jaffarterraform786/lambda (github.com) from this repo and build the code .

Figure :Lambda function resources with required policies.

now lets integrate the Lamda function with Apigateway .

To integrate the Lamda function with apigateway we need apigateway route and integration of apigateway .

the source code is present in

Jaffarterraform786/lambda (github.com)

Lets provision the resources .

Figure apigateway resources.

We can see the integration details from the aws console as shown below.

figure Lamda function integrating with api gateway

now lets go to apigateway and click on Invoke url as shown below and we will pass token “hello “ to url it will display message helloworld by triggering the lamda function.

if you need to use above modules and want to call in your application , we have the source code in below repository.

Jaffarterraform786/api-lamda-infra (github.com)

Figure :Invoking API gateway Uri by passing token -hello

--

--