Day 2: Creating NBA Game Day Notification System using Event-Driven Architecture
Project Description
This article details building a notification system using event driven architecture that sends NBA Game day Results to your mail at specific intervals.
This is the second project for the Devops All Stars Challenge
Project Architecture
Project Requirements
The following services/tools are required for this project:
- AWS Lambda
- AWS EventBridge
- AWS SNS (Simple Notification System)
- Python
Project Workflow
Basically the project uses AWS EventBridge to run a scheduled rule at intervals that triggers the Lambda Function which contains a python script to pull game data via the Sports Data API and send to an SNS Topic which is then now sent to either your mail or sms
The Project can be found here: Gameday-Notification
This project is implemented as follows:
Create AWS SNS TOPIC
- Open the AWS Management Console
- GO to SNS
- Click on topics, click create topic
- Select Standard as topic type
- Name your topic (e.g gameday-topic) and click create topic
Create a Subscription for the Topic
- Click on your topic
- Click create subscription
- Set Protocol to email
- Put your mail
- Click create Subscription
- Confirm the subscription from your mail
Create an SNS Publish Policy
- Open the IAM service in the AWS Management Console.
- Navigate to Policies → Create Policy.
- Click JSON and paste the JSON policy from gd_sns_policy.json file
- Replace REGION and ACCOUNT_ID with your AWS region and account ID.
- Click Next: Tags (you can skip adding tags).
- Click Next: Review.
- Enter a name for the policy (e.g., gameday-policy).
- Review and click Create Policy.
Create IAM Role for Lambda
- Open the IAM service in the AWS Management Console.
- Navigate to Roles -> Create Role
- Click on use case drop down and click Lambda
- Click Next and then attach two policies:
- The policy create earlier (gameday-policy)
- The Lambda Basic Execution Role (AWSLambdaBasicExecutionRole) (an AWS managed policy).
- CLick Next, skip tags and create the role
Create Lambda Function
- Open the AWS Management Console and navigate to the Lambda service.
- Click Create Function.
- Select Author from Scratch.
- Enter a function name (e.g., gameday-function).
- Choose Python 3.x as the runtime.
- Assign the IAM role created earlier (gameday-role) to the function.
- Under the Function Code section:
- Copy the content of the src/gd_notifications.py file from the repository.
- Paste it into the inline code editor.
- Under the Environment Variables section, add the following:
- NBA_API_KEY: your NBA API key.
- SNS_TOPIC_ARN: the ARN of the SNS topic created earlier.
- Click Create Function
Set up EventBridge Schedule to trigger Lambda
- Navigate to the Eventbridge service in the AWS Management Console.
- Go to Rules → Create Rule.
- Select Event Source: Schedule.
- Set the cron schedule for when you want updates (e.g., hourly).
- Under Targets, select the Lambda function (gameday-function) and save the rule.
Test the System
- Open Lambda function and click on the function you created
- click on test and name the event
- Test the function
- Verify you get a mail confirming it was successful
Conclusion
This project demonstrates how to build a notification system using event-driven architecture on AWS. By leveraging AWS Lambda, EventBridge, and SNS, you can create a reliable and efficient system to receive NBA Game Day updates via email or SMS. This setup is a great example of automating tasks and building scalable systems using cloud services.