|
1 | 1 | # Serverless Health Check API with CI/CD |
2 | 2 |
|
| 3 | +The 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. |
| 4 | + |
| 5 | +## Architectural desig |
| 6 | + |
| 7 | +### Core Components |
| 8 | + |
| 9 | +- Amazon API Gateway (HTTP API) |
| 10 | +- AWS Lambda (Python) |
| 11 | +- Amazon DynamoDB |
| 12 | +- AWS IAM |
| 13 | +- Amazon CloudWatch Logs |
| 14 | + |
| 15 | +Each environment (staging, prod) is isolated by naming convention and Terraform variables. |
| 16 | + |
| 17 | +### Runtime Request Flow |
| 18 | + |
| 19 | +1. _Client_: sends a GET or POST request to: |
| 20 | + |
| 21 | +``` |
| 22 | +https://<api-id>.execute-api.<region>.amazonaws.com/health |
| 23 | +``` |
| 24 | +2. _API Gateway_: |
| 25 | +- Matches the /health route |
| 26 | +- Forwards the request using AWS_PROXY integration |
| 27 | +3. _Lambda Function (env-health-check-function)_: |
| 28 | +- Logs the full request event to CloudWatch Logs |
| 29 | +- Generates a UUID |
| 30 | +- Stores request metadata in DynamoDB (env-requests-db) |
| 31 | +- Returns a JSON response |
| 32 | +4. _DynamoDB_: |
| 33 | +- Stores the request record (ID, timestamp, request payload) |
| 34 | + |
| 35 | +### Pipeline Flow |
| 36 | +1. Developer pushes code |
| 37 | +- staging branch → auto deploy |
| 38 | +- main branch → production deploy |
| 39 | +2. GitHub Actions workflow: The GitHub action workflow contain both terraform deploy and terraform destroy. |
| 40 | +- Configures AWS credentials (GitHub Secrets) |
| 41 | +- Terraform deploy - deploy.yaml |
| 42 | + - Checks out code |
| 43 | + - Runs: |
| 44 | + - terraform fmt |
| 45 | + - terraform validate |
| 46 | + - terraform plan |
| 47 | + - terraform apply |
| 48 | + |
| 49 | +- Terraform destroy - destroy.yaml |
| 50 | + - On GitHub console, manually trigger the destroy pipeline from the actions |
| 51 | + - Runs: |
| 52 | + - terraform int |
| 53 | + - terraform destroy |
| 54 | + |
| 55 | +### Environment separation |
| 56 | + |
| 57 | +| Aspect | Staging | Production | |
| 58 | +| -------------- | ------------------------------- | ---------------------------- | |
| 59 | +| Branch | `staging` | `main` | |
| 60 | +| Terraform vars | `staging.tfvars` | `prod.tfvars` | |
| 61 | +| Lambda | `staging-health-check-function` | `prod-health-check-function` | |
| 62 | +| DynamoDB | `staging-requests-db` | `prod-requests-db` | |
| 63 | +| API Gateway | `staging-health-check-api` | `prod-health-check-api` | |
| 64 | +| Approval | None | Required | |
| 65 | + |
| 66 | + |
| 67 | +### Security and IAM Role |
| 68 | +Each Lambda function has one dedicated IAM role with: |
| 69 | +- _Allowed permissions_ |
| 70 | + - dynamodb:PutItem → specific DynamoDB table ARN |
| 71 | + - logs:CreateLogGroup |
| 72 | + - logs:CreateLogStream |
| 73 | + - logs:PutLogEvents |
| 74 | +- Denied by default |
| 75 | + - No read access to DynamoDB |
| 76 | + - No access to other AWS services |
| 77 | + - No wildcard write permissions |
| 78 | +- secrets Handling |
| 79 | + - AWS credentials stored in GitHub Secrets |
| 80 | + - No credentials committed to repository |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | + |
3 | 89 | create hello lambda funtion using Python |
4 | 90 |
|
5 | 91 | ``` |
@@ -37,6 +123,7 @@ Run the python funtion locally using VS Code Run Button |
37 | 123 | endpoint - https://nrbefv9bcj.execute-api.us-east-1.amazonaws.com/health |
38 | 124 |
|
39 | 125 |
|
| 126 | + |
40 | 127 | terraform init -backend-config=backend-staging.tfvars for staging environment |
41 | 128 |
|
42 | 129 | terraform init -backend-config=backend-prod.tfvars for prod environment |
0 commit comments