Real-Time NBA Game Day Notification System Setup with Event-Driven Architecture
Hi Peepz,
I joined a challenge this new year; #DevOpsAllStarsChallenge
Brief Overview
This project is the Day 2 project of the challenge. #DevOpsAllStarsChallenge is a challenge that aims to equip devops engineers with on demand skills required of them.
Project Description
As sports enthusiasts like me π, staying updated with game schedules and scores can be crucial, especially for planning your day around the big games. You can guess the sport I was obsessed with I will answer at the end of the post.
In this post, weβll explore how to build an automated Game Day Notification Solution using AWS Serverless Services like Amazon EventBridge, AWS Lambda, and Amazon SNS. By integrating with an external NBA API, this system delivers timely notifications about game schedules, scores, and more, directly to subscribers via email or SMS.
Project Structure
game-day-notifications/
βββ src/
β βββ game-day-notifications.py
βββ iam policies/
β βββ sns_policy.json
βββ .gitignore
βββ README.md
Features
Amazon EventBridge: Automates the triggering of the workflow with rules configured for specific times (e.g., daily or live updates). Reduces manual intervention, ensuring the system operates seamlessly.
AWS Lambda: Processes game data fetched from the API and formats it for distribution. Handles logic for categorizing games (e.g., Scheduled, In Progress, Final) and crafting messages.
Amazon SNS: Publishes notifications to all subscribed users. Supports multiple communication channels (email, SMS).
NBA API :External source for game data, including schedules, live scores, and results. Enables real-time updates, keeping users informed.
Letβs dive inβ¦
Prerequisites
Before you commence this project, you must have the following:
You can clone the repository from my github account
1. Sportdata.io account:
Create a free tier account on SportsData
Follow the steps to get your NBA API Key.
2. AWS Credentials:
If you donβt already have an AWS account you can create a free tier account using this link.
Project Walkthrough
SNS
Creating an SNS Topic
1. Navigate to SNS on your AWS Management Console.
2. Click on create topic and select the standard as the topic type.
3. Give your topic a unique name copy your SNS ARN (you will need it later) and click create topic.
Adding subscribers to the SNS Topics
1. Click the topic you previously created.
2. Navigate to the subscriptions tab and create subscription.
3. Set protocol to email and input the email address you want to receive notifications.
4. Click create subscription.
5. Go to your email and confirm your subscription.
IAM
You will need to create an IAM Role for Lambda and policy for both the SNS.
SNS Policy
1. Navigate to IAM on your AWS Management Console.
2. Click on Policyβ Create Policy
3. Select Lambda as the AWS service.
4. Click JSON and paste the JSON policy from sns_policy.json file from the githib repo
5. Replace REGION and ACCOUNT_ID with your AWS region and account ID.
6. Click Next: Review.
7. Enter a unique name for the policy (e.g., gameday_sns_policy).
8. Review and click Create Policy.
Lambda Role
1. Open the IAM service in the AWS Management Console.
2. Click Roles β Create Role.
3. Select Lambda as the AWS service.
4. Attach the LambdaBasicExecutionRole and the gameday_sns_policy you previously created.
5. Enter a unique name for the policy (e.g., gameday_lambda_role).
Lambda Function
To create a lambda function;
1. Navigate to Lambda Service on your AWS Management Console.
2. Click create function.
3. Select Author from scratch
4. Give your function a unique name (game-day-notifications) and select the Python 3.x from the dropdown as the runtiime.
5. Assign the IAM role you previously created to the function.
6. Under the Function Code section:
a.Copy the content of the src/game-day-notifications.py file from the repository.
b. Paste it into the inline code editor.
7. Under the Environment Variables section, add the following:
a. NBA_API_KEY: your NBA API key.
b. SNS_TOPIC_ARN: the ARN of the SNS topic created earlier.
8. Click Create Function
EventBridge
To setup eventbridge schedule to trigger lambda;
1. Navigate to EventBridge on your AWS Management Console.
2. Click Rules β Create Rules.
3. Select Event Source: Schedule.
4. Set the cron schedule for when you want updates (e.g., hourly).
5. Under Targets, select the Lambda function (game-day-notifications) and save the rule.
Test
1. Open the Lambda function in the AWS Management Console.
2. Create a test event to simulate execution.
3. Run the function and check CloudWatch Logs for errors.
4. Verify you received a mail.
Viola!!!
Oh for the people curious about the sport I was obsessed with, itβs English football.
Checkout my post on medium