DEV Community

Gbenga Ojo-Samuel
Gbenga Ojo-Samuel

Posted on

Containerized Sports API for Premier League Game Day Schedule with AWS

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

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs