How sagary2j/python-flask-hello-world works
Project type and purpose
• This is a small, containerized Flask-based HTTP API service (“Hello World”), which can run locally (using SQLite) or in AWS (using DynamoDB). It is deployed via a CI/CD pipeline (GitHub Actions) onto AWS ECS, with infrastructure managed by Terraform.
File structure
• Top-level files:
• app.py / applocal.py – two entrypoints: one for DynamoDB (prod), one for SQLite (local).
• requirements.txt – Python dependencies.
• Dockerfile – containerizes the Flask app.
• setup.sh – bootstraps ECR repo and pushes initial image.
• terraform/ – Terraform modules and configuration for provisioning AWS resources (ECR, ECS, ALB, DynamoDB, S3 state bucket).
• .github/workflows/deploy.yml – GitHub Actions defines the CI/CD pipeline.
• tests/ – unit test for the API.
• .gitignore – excludes local artifacts.
README
• Describes two HTTP endpoints (PUT/GET) for user birthday management.
• Enumerates AWS services in use: ECS (EC2 launch type), DynamoDB, S3 (terraform state), CloudWatch (logs/metrics), ECR (container registry).
• Outlines the CI/CD workflow and Terraform-based infrastructure provisioning.
Main components
a. Developer Workflow
• GitHub Repository
• GitHub Actions (CI/CD)
• Docker build & push to Amazon ECR
• Terraform apply (reads .tf in repo, stores state in S3)
b. AWS Infrastructure
• AWS S3 bucket (Terraform state)
• AWS ECR (container registry)
• AWS ECS Cluster (EC2 instances running the container task)
• Application Load Balancer (public entry point)
• AWS DynamoDB table
• AWS CloudWatch (log groups + metrics)
c. Runtime Application
• Flask microservice container
• HTTP endpoints: PUT /hello/<username>, GET /hello/<username>
Relationships and data flows
• Developer pushes code → GitHub Actions kicks off CI/CD.
• CI/CD:
1. Build Docker image → Tag & Push to ECR.
2. Run Terraform (init, plan, apply) → Provision or update ECS, ALB, DynamoDB, S3 bucket.
• At runtime:
• Client request → ALB → ECS task (Flask container).
• Flask service → DynamoDB (Read/Write).
• Logs → CloudWatch.
Architectural patterns and design principles
• Infrastructure-as-Code (Terraform) for reproducible environment.
• Containerization (Docker) + immutable deployments.
• CI/CD pipeline (GitHub Actions) that ties code changes to infra/app deployments.
• Separation of concerns: application logic vs infra provisioning vs CI/CD.
• Two execution modes (local vs cloud) following the 12-factor app principle (config via environment).
Technologies and frameworks
• Python 3.8+, Flask 2.x
• Docker
• Terraform
• AWS ECS (EC2), ECR, DynamoDB, S3, CloudWatch
• GitHub Actions
Putting it all together
• Split AWS Runtime into ALB → ECS Container → DynamoDB.
• CloudWatch adjacent to ECS to capture logs.