๐Ÿ“Œ Overview

Welcome to my forth project in the DevOps Challenge, this project gave me a real-world experience and exposure to understand of how APIs, containers, and cloud infrastructure all work together in real-world applications. The Containerized Sports API Management System pushed me to explore more AWS services like ECS (Fargate), ECR, and API Gateway, all built with Terraform.

๐Ÿ› ๏ธ Project Architecture

Project NBA Game update diagram

What This Project Does

โœ… Fetches Sports Data: Retrieves real-time sports data from the SerpAPI. โœ… Containerized Backend: Runs a Flask API inside a Docker container. โœ… Deploys to AWS ECS (Fargate): Ensures a fully managed, serverless infrastructure. โœ… Exposes REST API: Uses API Gateway to provide a secure endpoint. โœ… Monitors with CloudWatch: Tracks API activity and logs errors.

๐Ÿ”ง Tools & Technologies

  • Python 3 for the app logic
  • Flask for the web framework
  • Docker for containerizing the app
  • AWS (ECS, API Gateway, ECR, CloudWatch, IAM)
  • Terraform for Infrastructure as Code

Prerequisites

  • Before you start, make sure you have:
  • AWS Account: Sign up if you donโ€™t have one.
  • AWS CLI Installed: Configure AWS CLI with valid credentials.
  • Terraform Installed: Used for provisioning AWS infrastructure.
  • SerpAPI Key: Obtain an API Key from SerpAPI.
  • Docker Installed: Required for building and running containers.

โš™๏ธ AWS Services Breakdown

โœ… ECR Reposiory: Stores the docker image in the cloud. โœ… ECS Cluster: Runs the containerized Flask application. โœ… ECS Task Definition: Defines CPU, memory, and environment settings. โœ… ECS Service: Ensures the Flask API runs consistently. โœ… Application Load Balancer: Routes traffic securely. โœ… API Gateway: Exposes the API to external consumers. โœ… CloudWatch Logs: Captures API logs for debugging and monitoring. โœ… IAM Roles: Implements least-privilege access control. โœ… Security Groups: Enforces secure network communication.

๐Ÿค” Challenges

  • IAM Permissions: IAM roles and policies took time to get right, especially when attaching them to ECS tasks.
  • API Gateway Integration: Took a bit of trial and error to properly wire up the API Gateway to ECS.
  • ECR Compatibility: Ensuring the image build architecture matched what Fargate needed (--platform linux/amd64) tripped me up for a bit.

๐ŸŽ“ Lessons Learned

This project helped me:

  • Understand how to write Terraform modules that are reusable and readable
  • Get hands-on with ECS Fargate, which is surprisingly easy once you get past the initial learning curve
  • Appreciate the value of logging and monitoring in production systems
  • Realize the power of API Gateway to add a layer of abstraction and security

๐ŸŽฏ Future Plans

  • Add a caching layer with ElastiCache for frequently requested data
  • Store historical query data in DynamoDB
  • Secure the API with keys or Cognito
  • Add a CI/CD pipeline with GitHub Actions

๐Ÿšฎ Clean-Up Instructions

Donโ€™t forget to clean up your resources when youโ€™re done!

terraform destroy -var="sports_api_key=<Enter your SerpAPI key>" -auto-approve

๐Ÿ”— Click here to access the project โ†’