Skip to content

Commit 1f063be

Browse files
committed
modified readme
1 parent 9eb2d23 commit 1f063be

4 files changed

Lines changed: 97 additions & 53 deletions

File tree

README.md

Lines changed: 93 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,113 @@
11
# Project Overview
22

3-
This repository deploys a Node.js WebAPI 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
3+
This repository deploys a Node.js WebAPI 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.
44

55

66

77
# Table of Contents
88

99
1. [Architecture Diagram](#architecture-diagram)
10-
2. [Getting Started](#getting-started)
11-
3. [Terraform Infrastructure](#terraform-infrastructure)
12-
4. [Services](#services)
13-
5. [Workflow Summary](#workflow-summary)
10+
2. [Workflow](#workflow)
11+
3. [Getting Started](#getting-started)
12+
4. [Terraform Infrastructure](#terraform-infrastructure)
13+
1414

1515

1616

1717
# Architecture Diagram
1818

19-
![architecture diagram](<images/architecture.drawio.svg>)
19+
![architecture diagram](<images/lambda.drawio.svg>)
2020

2121
![serverless](images/app.png)
2222

2323

24+
# Workflow
25+
26+
## Overview
27+
28+
This project demonstrates a **serverless Node.js WebAPI** deployed on AWS using **Terraform**.
29+
30+
31+
Running `terraform apply` provisions:
32+
33+
1. **S3 Bucket**
34+
- Stores the deployment ZIP (`deployment.zip`) for Lambda
35+
2. **AWS Lambda Function**
36+
- Pulls the deployment ZIP from S3 during first deployment
37+
- Executes both `/` and `/health` routes
38+
3. **API Gateway**
39+
- Routes HTTP requests to Lambda
40+
- Supports `/` and `/health`
41+
4. **RDS SQL Server**
42+
- Stores application data
43+
- Used by `/health` route to verify connectivity
44+
5. **Security Groups & VPC**
45+
- Ensures Lambda and RDS can communicate securely
46+
6. **GitHub Actions**
47+
- updates Lambda automatically on code changes
48+
49+
50+
## API Routes
51+
52+
| Route | Method | Description |
53+
|------------|--------|-------------|
54+
| `/` | GET | Returns a welcome message with timestamp |
55+
| `/health` | GET | Checks SQL Server connectivity and returns status |
56+
57+
58+
## Root Route `/`
59+
60+
61+
1. User requests `GET /`
62+
2. API Gateway receives the request and packages it into an **event payload** containing:
63+
- HTTP method
64+
- Path
65+
- Headers
66+
3. Lambda is invoked with the event payload.
67+
4. Lambda inspects `event.requestContext.http.path` and identifies `/`.
68+
5. Lambda executes root route logic:
69+
- Generates JSON with a greeting and current timestamp.
70+
6. Lambda returns response to API Gateway.
71+
7. API Gateway sends JSON back to the client:
72+
73+
74+
## Health Route `/health`
75+
76+
77+
1. User requests `GET /health`
78+
2. API Gateway receives the request and packages it into an **event payload** containing:
79+
- HTTP method
80+
- Path
81+
- Headers
82+
3. Lambda is invoked with the event payload.
83+
4. Lambda inspects `event.requestContext.http.path` and identifies `/health`.
84+
5. Lambda reads database environment variables:DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT, DB_SECRET_ARN
85+
6. Lambda connects to the RDS SQL Server using the credentials.
86+
7. Lambda executes a test query:
87+
8. API Gateway returns the JSON response to the client.
88+
89+
## API Routes
90+
91+
Client
92+
93+
├─ GET / ──► API Gateway ──► Lambda ──► Returns Welcome Message
94+
95+
└─ GET /health ──► API Gateway ──► Lambda ──► Connects to RDS ──► Returns DB Status
96+
97+
## How code changes are deployed (CI/CD workflow)
98+
99+
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. The process works as follows:
100+
101+
1. A code change is pushed to the GitHub repository.
102+
- A GitHub Actions workflow is triggered.
103+
2. Installs Node.js
104+
- Installs project dependencies
105+
3. Builds a new deployment.zip file containing the Lambda application code
106+
4. The pipeline uploads the new ZIP file to the S3 bucket that was created by Terraform during initial setup.
107+
5. 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.
108+
6. Lambda immediately switches to the new code, meaning all API Gateway requests (`/` and `/health`) begin using the updated Lambda logic without any downtime.
109+
110+
24111
# Getting Started
25112

26113
## Prerequisites
@@ -42,26 +129,6 @@ Default region name [None]: your region
42129
Default output format [None]:
43130
```
44131

45-
## Clone Repository
46-
47-
```bash
48-
git clone <repository-url>
49-
```
50-
51-
52-
## Lambda Deployment zip
53-
54-
`Install dependencies locally:`
55-
56-
```bash
57-
npm install
58-
```
59-
60-
`Zip the application code and node_modules:`
61-
62-
```bash
63-
zip -r deployment.zip .
64-
```
65132

66133
# Terraform Infrastructure
67134

@@ -101,26 +168,3 @@ serverless/
101168
```
102169

103170

104-
# Services
105-
106-
107-
- **AWS Lambda**: A serverless compute service used to host the Node.js WebAPI. Lambda allows the application to run without provisioning or managing servers. It automatically scales based on traffic, and you only pay for the compute time consumed by your code.
108-
- **API Gateway v2 (HTTP API)**: Exposes HTTP endpoints for the Lambda function, enabling clients to interact with the WebAPI. API Gateway handles routing, request validation, and security, providing a managed entry point for the API.
109-
- **Amazon RDS (SQL Server)**: A fully managed relational database service used to store the application’s data. The SQL Server instance is provisioned with standard compute (`db.t3.medium`) and includes automated backups, monitoring, and maintenance. It is easily upgradable for future performance or availability requirements.
110-
- **Terraform**: An Infrastructure-as-Code (IaC) tool used to define, provision, and manage AWS resources declaratively. Terraform ensures that the infrastructure is reproducible, version-controlled, and can be modified or extended with minimal effort.
111-
- **GitHub Actions**: Provides the CI/CD pipeline to automatically build, test, and deploy changes to the Node.js WebAPI. When code is pushed to the main branch, the workflow packages the Lambda function, runs tests, and deploys the code to AWS, ensuring fast and reliable updates.
112-
- **IAM Roles**:
113-
- **AWS Secrets Manager**:
114-
- **Security Group**:
115-
- **CloudWatch**:
116-
117-
118-
# Workflow Summary
119-
120-
A user accesses the API using a URL. The API Gateway recieves the HTTP request. It determines which route matches ( / or /health). The request is forwaded to the configured AWS Lambda Function. Lambda is invoked with an event payload containing details such as path and method. The function inspects the request path and decides which logic to run. Lambda reads database configuration values (DB host, username, password, name and port) from its environmental variable which are set in Terraform. Lambda attempts to connect to the SQL server instance in Amazon RDS. Lambda runs a SQL query and if successful, Lambda confirms the database is reachable. Lambda reutrns a structured JSON response:
121-
122-
/ returns a welcome message + timestamp
123-
124-
/health returns API status, timestamp and database connection status
125-
126-
Then API Gateway converts the Lambda response into a standard HTTP response. The user recieves the final JSON output.

images/architecture.drawio.svg

Lines changed: 0 additions & 4 deletions
This file was deleted.

images/lambda.drawio.svg

Lines changed: 4 additions & 0 deletions
Loading

src/handler/deployment.zip

-37 MB
Binary file not shown.

0 commit comments

Comments
 (0)