Skip to content

furqan-cloud-dev/serverless-node-read-restful-api-optimized-aws-lambda-mongodb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

serverless-node-js-typescript-restful-api-read-optimized-aws-lambda-mongodb

RESTful apis for optimizing read operations - Node.js + TypeScript + ESBuild + AWS Lambda + MongoDB - No Framework or Third party library used

node-rest-apis-read-optimized-aws-lambda aws-lambda-rest-api-javascript-optimized node-rest-api-read-optimized-vs-code-typescript

AWS Lambda function : app.zip
Configure lambda handler as: app.handler.
Configure environment variable for MongoDB:

Environment Variable in AWS Lambda for MONGODB_URI = "{connection string}"
MongoDB Atlas is a great option for managed cloud mongodb cluster to start with - Free Tier is available

Environment Variable in AWS Lambda for MONGODB_DATABASE_NAME = "{db name}"

How to configure?: https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html"

E-Route to get the data from any collection from MongoDB Database ( Highly Dynamic) with minimum latancy. both for Cold Start Time + Init Time. Execution time is also optimized to return the data from database in minimum time. No Express Framework OR Any Third party libray is used. MongoDB Integration is added using mongodb native driver for javascript. Complete pagination, filter and specific returned fields options for dynamic read e-Route without any changes to backend

[ GET ] /api/e/users?page=1&limit=10
json body: { "filter": { "name": "furqan" }, "sort": { "_id": "desc" }, "fields": ["name", "tech_stack"] }

[ GET ] /api/e/users/6382c5ab8bfe8614c6d0df19
json body: { "fields": ["name", "tech_stack"] }



Just upload "app.zip" to AWS Lambda directly via Lambda Code mangement console as function size is just 682.7 kB
This will result towards minimum cold start time for Node.js runtime for new Node.js 18.x runtime on arm64 architecture ( AWS Graviton Processor for minimum pricing of Lambda function )

We can use MongoDB Atlas Cloud managed solution - Free Shared Instance

e-Route
Connect an API gateway with $default stage and only one route GET /{proxy+}:
Following Routes are available to access the resources from db:
[ GET ] /api/e/{entity}
[ GET ] /api/e/{entity}/{id}

READ: Any Entity as json request can be read from the MongoDB database


Working On

  • JWT authorization via:
    • APIGateway Authorizer for generic proxy route
    • Custom implementation is pretty much dynamic. Using JWT Library dependency but it may add an additional cold start time for boot up.

  • CI/CD for one-click/command deploy updates to Lambda func


Any Feedback, suggestion, improvisation is welcomed



Created By,
Furqan
(Software Developer / Solution Architect)

About

restful apis for optimizing read operations - Node.js + AWS Lambda + MongoDB - No Framework or Third part library used

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •