Skip to content

konkah/portfolio-aws-architecture-devops

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

22 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Portfolio AWS Architecture DevOps

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.


πŸ—‚οΈ Table of Contents


πŸ“– About the Project

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.


πŸ—οΈ Architecture Overview

High-level infrastructure workflow:

  1. πŸ‘¨β€πŸ’» Developer pushes code to GitHub.
  2. βš™οΈ 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
  3. πŸ—οΈ Docker images are built and pushed to ECR.
  4. πŸš€ ECS Fargate and/or EC2 pull the images and run the app.
  5. 🌐 ALB routes requests to containers or VMs.
  6. πŸ“Š Logs are collected in CloudWatch.

✨ Features

  • 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.

πŸ› οΈ Tech Stack

  • Language: Python (FastAPI)
  • Containerization: Docker
  • Infrastructure as Code: Terraform
  • Cloud: AWS (ECS, EC2, ECR, VPC, ALB, CloudWatch)
  • Automation: Makefile, GitHub Actions

πŸ“ Project Structure

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

🚦 Getting Started

1. Clone the Repository

git clone https://github.com/konkah/portfolio-aws-architecture-devops.git
cd portfolio-aws-architecture-devops

2. Configure Your Environment

  • 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.env and env/prod.tfvars with your AWS credentials and configuration.

Note: Do not edit the example.* files directly. Always create local copies and update those copies.

3. Build & Push Docker Image

Terraform automates image build/push, but for local development:

make app-start

4. Provision AWS Infrastructure

You can provision the AWS infrastructure using Makefile commands (recommended) or direct Terraform commands.

Option 1: Using Makefile 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 resources

Option 2: Using Terraform Directly

cd terraform/aws
terraform init
terraform plan -var-file="../../env/prod.tfvars"
terraform apply -var-file="../../env/prod.tfvars" -auto-approve

Tip: The Makefile wraps the corresponding Terraform commands for your convenience.

5. Access Your Application

  • Find the output lb_dns_name and open it in your browser:
    http://<load-balancer-dns>
    

⚑ Usage & Automation

Common Makefile Commands

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

πŸ“€ Outputs

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"

πŸ› οΈ Customization

  • Application Code: Edit application/containers/fastapi.Dockerfile and relevant source files for your FastAPI logic.

  • Infrastructure Variables: Change values in env/prod.tfvars or module variables files.

  • Scaling: Adjust desired_count in ECS/EC2 modules, subnet CIDRs, instance types, etc.


πŸ›‘οΈ AWS IAM Policies

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 & Author

License: MIT Author: Karlos Helton Braga (Konkah)


Feel free to fork, adapt, or reach out for improvements or questions!

About

This project demonstrates a deploying FastAPI applications on AWS using Terraform. The focus is on best practices for both containerized and VM-based workloads.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors