This content originally appeared on DEV Community and was authored by Janith Kavinda
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
- Create Directory for application
mkdir lambda-express
cd lambda-express
- Initialization
npm init
- Install Express
npm install express
Implementing application
- This is a simple 'Hello World' application here is the code
- Creating the file
touch index.js
- 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}`)
});
}
- Test it is running on port 3003
node index.js
Deploy on AWS 🚀
- 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
- Create a Lambda function
- Set Environement Variable
- 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
This content originally appeared on DEV Community and was authored by Janith Kavinda
Janith Kavinda | Sciencx (2024-08-31T00:00:32+00:00) Deploy a Express JS app in Lambda AWS. Retrieved from https://www.scien.cx/2024/08/31/deploy-a-express-js-app-in-lambda-aws/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.