Containerized Sports API for Premier League Game Day Schedule with AWS

Gbenga Ojo-Samuel - Feb 20 - - Dev Community

Introduction

Sports enthusiasts and developers often require real-time game schedules for various leagues. This article demonstrates how to build a containerized API using AWS Elastic Container Registry (ECR), Elastic Container Service (ECS), Application Load Balancer (ALB), and API Gateway, with an ECS-hosted Flask application that retrieves Premier League game schedules from SerpAPI. The entire setup will be provisioned using Terraform.

Architecture Overview

Image description

Flask Application: A Python-based application that fetches EPL game schedules from SerpAPI.

ECR: Stores the Docker image of the Flask application.

ECS (Fargate): Runs the containerized application in a scalable environment.

ALB: Routes traffic to the ECS service.

API Gateway: Acts as an entry point for external requests.

Prerequisites

  • AWS Account with necessary IAM permissions
  • Terraform installed on the local machine
  • AWS CLI configured with appropriate credentials
  • Docker installed for containerization
  • SerpAPI key for fetching Premier League schedules

Tech Stack

  • Programming Language: Python (Flask framework)
  • Containerization: Docker
  • Infrastructure as Code: Terraform
  • Cloud Provider: AWS (ECR, ECS Fargate, ALB, API Gateway)
  • External API: SerpAPI

Implementation Steps

Flask Application

The Flask application in app.py fetches Premier League schedules from SerpApi

Image description

Provision AWS Resources Using Terraform

The full terraform codes can be found in the repository below

https://github.com/OjoOluwagbenga700/containerized_sport_api.git

Create custom VPC and Security Groups

Image description

Image description

Create ECR, build Docker image and push image to ECR

Dockerfile

Image description

Image description

Create ECS Cluster,ECS Role/Permissions, ECS Task Definitions and ECS Service

Image description

Create Application Load Balancer and Target Group

Image description

Create API Gateway

Image description

Deploy and Test

Run the following commands to provision the infrastructure:

terraform init
terraform plan 
terraform apply -auto-approve
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

Image description

Image description

Conclusion

This setup provides a fully automated, scalable, containerized API for retrieving Premier League schedules in real-time. By leveraging Terraform, ECS, ECR, ALB, and API Gateway, the architecture ensures reliability, security, and efficiency for sports API solutions.

To Clean up

Run the command below

terraform destroy --auto-approve 

Enter fullscreen mode Exit fullscreen mode

Image description

. . . . . . . . . . . . . . . . . . . . . . . .