Welcome to the Portfolio AWS Architecture DevOps repository! This project demonstrates a robust, cloud-native infrastructure for deploying FastAPI applications on AWS using Infrastructure as Code (IaC) with Terraform. The focus is on scalability, automation, modularity, and best practices for both containerized and VM-based workloads.
- Portfolio AWS Architecture DevOps
This repository provides a complete solution for deploying a FastAPI application using AWS managed services.
Everything is automated: from provisioning cloud infrastructure to building Docker images and running them in both ECS Fargate and EC2 VMs, all behind a load balancer with centralized log management.
High-level infrastructure workflow:
- π¨βπ» Developer pushes code to GitHub.
- βοΈ Terraform provisions AWS resources:
- π³ ECR: Docker image storage
- π ECS Fargate & EC2: Containers and VMs for deployment
- π VPC/Subnets/Security Groups: Networking & security
- βοΈ ALB: Load balancing for containers and VMs
- π CloudWatch: Centralized logging
- ποΈ Docker images are built and pushed to ECR.
- π ECS Fargate and/or EC2 pull the images and run the app.
- π ALB routes requests to containers or VMs.
- π Logs are collected in CloudWatch.
- Modular Terraform: Clean and reusable modules for networking, VMs, containers, logging, and image registry.
- Deploys to Containers (ECS) and VMs (EC2): Flexibility for different workloads.
- Elastic Container Registry (ECR): Secure Docker image storage.
- Application Load Balancer (ALB): Managed traffic for containers and VMs.
- Centralized Logging: All logs shipped to CloudWatch.
- Secure Networking: Custom VPC, public subnets, dedicated security groups.
- Automation via Makefile: Streamlined workflows (plan, apply, destroy, validate, etc).
- Production-Ready Dockerfile: Optimized build, dependency management via pip-tools.
- CI/CD with GitHub Actions: Automated testing and continuous deployment.
- Language: Python (FastAPI)
- Containerization: Docker
- Infrastructure as Code: Terraform
- Cloud: AWS (ECS, EC2, ECR, VPC, ALB, CloudWatch)
- Automation: Makefile, GitHub Actions
portfolio-aws-architecture-devops/
β
βββ application/
β βββ containers/
β βββ fastapi.Dockerfile
β
βββ terraform/
β βββ aws/
β βββ main.tf
β βββ outputs.tf
β βββ modules/
β βββ containers/
β βββ image-registries/
β βββ logs/
β βββ load-balancers/
β βββ networks/
β βββ vms/
β
βββ env/
β βββ example.env
β βββ example.tfvars
β
βββ docs/
β βββ aws-policies/ # Example IAM policies for the project
β
βββ .github/
β βββ workflows/ # GitHub Actions CI/CD workflows
β
βββ Makefile
βββ README.md
git clone https://github.com/konkah/portfolio-aws-architecture-devops.git
cd portfolio-aws-architecture-devops- Copy the example environment files and edit them with your own values:
cp env/example.env env/dev.env
cp env/example.tfvars env/prod.tfvars- Edit
env/dev.envandenv/prod.tfvarswith your AWS credentials and configuration.
Note: Do not edit the
example.*files directly. Always create local copies and update those copies.
Terraform automates image build/push, but for local development:
make app-startYou can provision the AWS infrastructure using Makefile commands (recommended) or direct Terraform commands.
make cloud-init-aws # Initialize Terraform for AWS
make cloud-plan-aws # Show the Terraform execution plan
make cloud-start-aws # Apply and provision all AWS resourcescd terraform/aws
terraform init
terraform plan -var-file="../../env/prod.tfvars"
terraform apply -var-file="../../env/prod.tfvars" -auto-approveTip: The Makefile wraps the corresponding Terraform commands for your convenience.
- Find the output
lb_dns_nameand open it in your browser:http://<load-balancer-dns>
| Command | Description |
|---|---|
make app-start |
Start local app containers with Docker |
make app-finish |
Stop and remove local containers |
make cloud-init-aws |
Initialize Terraform for AWS |
make cloud-plan-aws |
Show Terraform plan for AWS |
make cloud-start-aws |
Apply (deploy) AWS infrastructure |
make cloud-finish-aws |
Destroy all AWS infrastructure |
make cloud-validate-aws |
Validate Terraform configuration |
After a successful deployment, Terraform provides:
- ECR: URL and repository name for Docker images
- ECS/EC2: Cluster/service names, task definition ARNs, instance IDs
- Networking: VPC ID, subnets, ALB DNS name
- Logging: CloudWatch Log Group name/ARN
Example output:
ecr_repository_url = "123456789012.dkr.ecr.eu-west-1.amazonaws.com/portfolio-api-container-hub"
lb_dns_name = "portfolio-alb-123456789.eu-west-1.elb.amazonaws.com"
cloudwatch_log_group_name = "portfolio-api-logs"
-
Application Code: Edit
application/containers/fastapi.Dockerfileand relevant source files for your FastAPI logic. -
Infrastructure Variables: Change values in
env/prod.tfvarsor module variables files. -
Scaling: Adjust
desired_countin ECS/EC2 modules, subnet CIDRs, instance types, etc.
The project requires specific AWS IAM permissions for Terraform to provision and manage resources.
Example policy documents can be found in the docs/aws-policies/ directory.
Important: Make sure your AWS user or role has permissions as defined in these policy files before running Terraform.
License: MIT Author: Karlos Helton Braga (Konkah)
Feel free to fork, adapt, or reach out for improvements or questions!