This repository deploys a Node.js WebAPI app and a SQL Server database on AWS. It also includes a CI/CD pipeline using GitHub Actions to automate deployment of code changes to the API. The infrastructure is designed to be modular, scalable, and extendable for future enhancements. Lambda was used to host the Node.js WebAPI and the API Gateway exposes HTTP endpoints for the Lambda function.
This project demonstrates a serverless Node.js WebAPI deployed on AWS using Terraform.
- S3 Bucket
- Stores the deployment ZIP (
deployment.zip) for Lambda
- Stores the deployment ZIP (
- AWS Lambda Function
- Pulls the deployment ZIP from S3 during first deployment
- Executes both
/and/healthroutes
- API Gateway
- Routes HTTP requests to Lambda
- RDS SQL Server
- Stores application data
- Used by
/healthroute to verify connectivity
- Security Groups & VPC
- Ensures Lambda and RDS can communicate securely
- GitHub Actions
- updates Lambda automatically on code changes
serverless/
├── infra/
│ ├── environments/
│ │ ├── dev/
│ │ │ ├── backend.tf
│ │ │ ├── component.tf
│ │ │ ├── main.tf
│ │ │ ├── oidc.tf
│ │ │ ├── outputs.tf
│ │ │ └── variables.tf
│ │ └── prod/
│ └── modules/
│ ├── api/
│ ├── database/
│ ├── lambda/
│ └── networking/
├── src/
│ └── handler/
│ ├── node_modules/
│ ├── index.js
│ ├── package-lock.json
│ └── package.json
├── .gitignore
├── .pre-commit-config
└── README.md
| Route | Method | Description |
|---|---|---|
/ |
GET | Returns a welcome message with timestamp |
/health |
GET | Checks SQL Server connectivity and returns status |
- User requests
GET / - API Gateway receives the request and packages it into an event payload
- Lambda is invoked with the event payload.
- Lambda inspects
event.requestContext.http.pathand identifies/. - Lambda executes root route logic:
- Generates JSON with a greeting and current timestamp.
- Lambda returns response to API Gateway.
- API Gateway sends JSON back to the client
- User requests
GET /health - API Gateway receives the request and packages it into an event payload
- Lambda is invoked with the event payload.
- Lambda inspects
event.requestContext.http.pathand identifies/health. - Lambda reads database environment variables:DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT, DB_SECRET_ARN
- Lambda connects to the RDS SQL Server using the credentials.
- Lambda executes a test query
- API Gateway returns the JSON response to the client.
When application code is modified and pushed to GitHub, the CI/CD pipeline automatically updates the Lambda function with the latest version of the code:
- A code change is pushed to the GitHub repository.
- A GitHub Actions workflow is triggered.
- Installs Node.js
- Builds a new deployment.zip file containing the Lambda application code
- The pipeline uploads the new ZIP file to the S3 bucket that was created by Terraform during initial setup.
- After the ZIP is uploaded, the workflow calls AWS to update the Lambda function’s code, instructing Lambda to pull the latest ZIP from S3.
- Lambda immediately switches to the new code, meaning all API Gateway requests (
/and/health) begin using the updated Lambda logic without any downtime.

