22
33The goal of this project is to build, configure, and automate the deployment of a simple serverless application on AWS. Created a health check endpoint that logs requests and stores them in a database, with a CI/CD pipeline to manage deployments for both staging and production environments, fully provisioned via Terraform and deployed automatically using GitHub Actions.
44
5+ ## Prerequisites
6+ - An AWS account and IAM user with rights to create IAM, Lambda, API Gateway, DynamoDB, CloudWatch.
7+ - Local toolchain:
8+ - Terraform v1.2+
9+ - GitHub repo secrets (Repository > Settings > Secrets):
10+ - ` AWS_ACCESS_KEY_ID `
11+ - ` AWS_SECRET_ACCESS_KEY `
12+ - ` AWS_REGION ` (e.g. ` us-east-1 ` )
13+
514## Architectural desig
615
716### Core Components
@@ -14,6 +23,8 @@ The goal of this project is to build, configure, and automate the deployment of
1423
1524Each environment (staging, prod) is isolated by naming convention and Terraform variables.
1625
26+ [ Live Demo Link] ( https://www.loom.com/share/3b1a44b435724293b7be8953ed51ae27 )
27+
1728### Runtime Request Flow
1829
19301 . _ Client_ : sends a GET or POST request to:
@@ -60,6 +71,7 @@ https://<api-id>.execute-api.<region>.amazonaws.com/health
6071| Terraform vars | ` staging.tfvars ` | ` prod.tfvars ` |
6172| Lambda | ` staging-health-check-function ` | ` prod-health-check-function ` |
6273| DynamoDB | ` staging-requests-db ` | ` prod-requests-db ` |
74+ | S3 Bucket | ` serverless-health-check-api/staging/tfstate ` | ` serverless-health-check-api/prod/tfstate ` |
6375| API Gateway | ` staging-health-check-api ` | ` prod-health-check-api ` |
6476| Approval | None | Required |
6577
@@ -80,50 +92,74 @@ Each Lambda function has one dedicated IAM role with:
8092 - No credentials committed to repository
8193
8294
83-
84-
85-
86-
87-
88-
89- create hello lambda funtion using Python
90-
95+ ![ ] ( /svrhecheck.drawio.png )
96+
97+ ## Setup
98+
99+ _ Repository Structure_
100+ .
101+ ├── .github
102+ │ └── workflows
103+ │ └── deploy.yml
104+ ├── destroy.yml
105+ ├── lambda
106+ │ └── lambda_function.py
107+ ├── terraform
108+ │ ├── provider.tf
109+ │ ├── variables.tf
110+ │ ├── main.tf
111+ │ ├── iam.tf
112+ │ ├── lambda.tf
113+ │ ├── apigw.tf
114+ │ ├── outputs.tf
115+ │ └── staging.tfvars
116+ │ └── prod.tfvars
117+ | └── backend-prod.tfvars
118+ | └── backend-staging.tfvars
119+ └── README.md
120+
121+ - Create the lambda function, run the python funtion locally using VS Code Run Button, import boto3, logging,json, os, uuid.
122+ - Resource names follows _ env-resource-name_
123+
124+ ## How to trigger deployments
125+
126+ _ Manual for test_
127+ - terraform init -backend-config=backend-staging.tfvars for staging environment
128+ - terraform init -backend-config=backend-prod.tfvars for prod environment
129+ - terraform plan -backend-config=backend-staging.tfvars for staging environment
130+ - terraform plan -backend-config=backend-prod.tfvars for prod environment
131+ - terraform apply -var-file="staging.tfvars"
132+ - terraform apply -var-file="prod.tfvars"
133+ - terraform destroy -backend-config=backend-staging.tfvars for staging environment
134+ - terraform destroy -backend-config=backend-prod.tfvars for prod environment
135+
136+ _ GitHub Action CICD_
137+ ### Staging
138+ 1 . Push to branch ` staging ` (or open a PR merging into ` staging ` and merge).
139+ 2 . GitHub Action will automatically:
140+ - ` terraform init `
141+ - ` terraform plan -var-file="staging.tfvars" `
142+ - ` terraform apply ` (auto-approved)
143+
144+ ### Production
145+ 1 . Push to branch ` main ` (or merge PR into ` main ` ).
146+ 2 . Workflow will run and wait for ** manual approval** in the ` production ` environment (configure environment reviewers in Settings).
147+ 3 . Approve in GitHub UI → workflow will ` apply ` the ` prod.tfvars ` plan.
148+
149+ ### Trigger Destroy CICD pipeline
150+ Manually trigger the terraform destroy workflow in GitHub UI -> actions -> destroy.yaml
151+
152+ ## Testing the /health endpoint
153+
154+ After deployment, Terraform outputs the API endpoint. You can fetch it:
155+ - From the Actions run logs (last step runs ` terraform output -json ` )
156+
157+ Example curl (replace ` <API_ENDPOINT> ` with the ` api_endpoint ` output):
91158```
92- # Hello lambda function
93- def lambda_handler(event, context):
94- name = event.get("name", "World")
95- message = f"Hello, {name}!"
96-
97- return {
98- "statusCode": 200,
99- "body": message
100- }
101-
102- # Run the funtion locally for testing
103- if __name__ == "__main__":
104- test_event = {"name": "Emmanuel Ogah"}
105- result = lambda_handler(test_event, None)
106- print(result)
107- ```
108-
109- Run the python funtion locally using VS Code Run Button
110- - Click the “Run Python File” button in the top right corner.
159+ # GET
160+ curl "https://nrbefv9bcj.execute-api.us-east-1.amazonaws.com/health"
111161
112- ```
113162# Output
163+ {"status": "healthy", "message": "Request processed and saved.", "id": "0fb4fa88-64a1-440d-84b1-5a6d4354364b"}
114164
115- {'statusCode': 200, 'body': 'Hello, Emmanuel Ogah!'}"
116- ```
117-
118- - Create the terraform folder structure
119-
120- - Deploy with: terraform init then terraform apply -var-file="staging.tfvars" (or prod.tfvars)
121-
122-
123- endpoint - https://nrbefv9bcj.execute-api.us-east-1.amazonaws.com/health
124-
125-
126-
127- terraform init -backend-config=backend-staging.tfvars for staging environment
128-
129- terraform init -backend-config=backend-prod.tfvars for prod environment
165+ ```
0 commit comments