Introduction
Lambda is a AWS service that provides the server-less
application that is easy to run application without maintaining server. It is not expensive and always free under 1000 000
requests. There is no need to use any other service in lambda you just can deploy with Function URL
. In this demonstration I will provide the exact steps that you need to follow in order to deploy this application.
Steps π
Create a Node JS server
1) Create Directory for application
mkdir lambda-express
cd lambda-express
2) Initialization
npm init
3) Install Express
npm install express
Implementing application
- This is a simple 'Hello World' application here is the code
1) Creating the file
touch index.js
2) Code of the application
const express = require('express')
const serverless = require('serverless-http')
const app = express()
const port = 3003
app.use(express.json());
app.get('/', (req, res) => {
res.send('Hello World!');
});
if(process.env.ENVIRONMENT === "lambda") {
module.exports.handler = serverless(app);
} else {
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
});
}
3) Test it is running on port 3003
node index.js
Deploy on AWS π
1) Create the .zip file
zip -r lambda.zip node_modules index.js package.json
- you can use this command to create the zip file or you can download this file -> lambda.zip
2) Create a Lambda function
3) Set Environment Variable
4) Now your App is ready
- You can click Function URL and check the applications is working
Considerations ββ
- This lambda is open to public by Using Public URL
- It might lead to a DDOS attach by someone else
- If you want you can manage lambda by using
AWS API Gateway
Congratulations π Just now you deployed your app
click your Function URL and enjoy
happy coding !
Top comments (1)
Great article, Janith! I really enjoyed how clearly you explained the steps to deploy an Express.js app in AWS Lambda. The way you broke down each step made it super easy to follow, even for someone new to serverless architectures. The tip on optimizing the app's size before deployment was especially helpful. Looking forward to more content like this.