DEV Community

Cover image for NBA Game Day Notifications / Sports Alerts System
Victor Robin
Victor Robin

Posted on

NBA Game Day Notifications / Sports Alerts System

Project Overview

This project is an alert system that sends real-time NBA game day score notifications to subscribed users via SMS/Email. It leverages Amazon SNS, AWS Lambda, Python, Amazon EventBridge, and NBA APIs to provide sports fans with up-to-date game information. The project demonstrates cloud computing principles and efficient notification mechanisms.

Features

  • Fetches live NBA game scores using an external API.
  • Sends formatted score updates to subscribers via SMS/Email using Amazon SNS.
  • Automates scheduled updates using Amazon EventBridge.
  • Designed with security in mind, following the principle of least privilege for IAM roles.

Prerequisites

  • Free account with subscription and API key at sportdata (subscribe for NBA games).
  • Personal AWS account with a basic understanding of AWS and Python.

Technical Architecture

Image description

Technologies

  • Cloud Provider: AWS
  • Core Services: SNS, Lambda, EventBridge
  • External API: NBA Game API (SportsData.io)
  • Programming Language: Python 3.x
  • IAM Security:
  • Least privilege policies for Lambda, SNS, and EventBridge.

Project Structure

Clone this repo:
git clone https://github.com/Vivixell/Game-Result-Notification.git

Game-Result-Notification/
├── src/
│   ├── gd_notifications.py          # Main Lambda function code
├── policies/
│   ├── gd_sns_policy.json           # SNS publishing permissions
│   ├── gd_eventbridge_policy.json   # EventBridge to Lambda permissions
│   └── gd_lambda_policy.json        # Lambda execution role permissions
├── .gitignore
└── README.md                        # Project documentation
Enter fullscreen mode Exit fullscreen mode

Setup Instructions

Create an SNS Topic

  • Open the AWS Management Console and search for SNS.

Image description

  • Navigate to the SNS service, then click Topics → Create Topic.

Image description

  • Select Standard as the topic type.
  • Name the topic (e.g., Victor_Game_Notification) .

Image description

  • Leave other options as default, click Create Topic and copy the ARN of the created topic (needed later).

Image description

Create an SNS Subscription

  • Go to Create Subscription under the newly created topic.

Image description

  • Select a Protocol:

    • Email: Enter a valid email address.
    • SMS: Enter a valid phone number in an international format (e.g., +2348056789012).
  • Click Create Subscription.

Image description

  • If using email, check your inbox and confirm the subscription. For SMS, it activates immediately.

Image description

Create an SNS Publish Policy

  • Open IAM in the AWS Management Console.

Image description

  • Navigate to PoliciesCreate Policy.

Image description

  • Click JSON and paste the policy of the GitHub repo from gd_sns_policy.json (Replace the ARN with your SNS topic's ARN copied earlier).

Image description

  • Click Next: Review, and name the policy (e.g., Victor_Game_Policy), and create it.

Image description

Create an IAM Role for Lambda

  • In IAM, go to RolesCreate Role.

Image description

  • Select AWS ServiceLambdaNext.

Image description

  • Attach these policies:

    • SNS Publish Policy: Victor_Game_Policy.
    • AWS Managed Policy: AWSLambdaBasicExecutionRole.

Image description

  • Click Next: Review, name the role (e.g., Lambda_Game_Role), and create it.

Image description

Deploy the Lambda Function

  • Open the AWS Management Console and go to Lambda.

Image description

  • Click Create FunctionAuthor from Scratch.
  • Name the function (e.g., Victor_Game_Notty).
  • Select Python 3.x as the runtime.

Image description

  • Assign the Lambda_Game_Role created earlier.
  • Click Create Function.

Image description

  • Under Function's Code Tab:

    • Copy the content of src/gd_notifications.py and paste it into the inline editor.
    • Click Deploy.

Image description

  • Under ConfigurationEnvironment Variables, add:
  • NBA_API_KEY: Your NBA API key.
  • SNS_TOPIC_ARN: The ARN of the SNS topic created earlier.

Image description

Image description

  • Save the settings.

Test the Lambda Function

  • Click TestCreate a test event.
  • Name it (e.g., Test1) and save it.
  • Click Test and check your email/SMS for notifications.
  • Retry if needed (delays may occur due to API latency).

Image description

Image description

Image description

Set Up Automation with EventBridge

  • Open EventBridge in the AWS Console.
  • Go to** Rules** → Create Rule.

Image description

  • Choose Schedule as the event source.

Image description

  • Set a recurring schedule using this cron expression:
  • 0 9–23/2,0–2/2 * * ? *

  • Breakdown:

    • Minute (0): Runs at the start of the hour.
    • Hour (9–23/2,0–2/2): Every 2 hours from 9 AM–11 PM and 12 AM–2 AM.
    • Day of Month (*): Any day.
    • Month (*): Any month.
    • Day of Week (?): Any day.
    • Year (*): Any year.
  • Turn off Flexible Window and click Next

Image description

  • Under Targets, select the Lambda function (Victor_Game_Notty).

Image description

Click Next, Next, then Create Schedule.

What We've Learned

  • Designing a notification system with AWS SNS and Lambda.
  • Securing AWS services using least privilege IAM policies.
  • Automating workflows with EventBridge.
  • Integrating external APIs into cloud-based workflows.

Future Enhancements

  • Add NFL score alerts for extended functionality.
  • Store user preferences (teams, game types) in DynamoDB for personalized alerts.
  • Implement a web UI.

That's it! You now have an automated NBA game alert system running in the cloud.

Top comments (0)