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
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
Setup Instructions
Create an SNS Topic
- Open the AWS Management Console and search for SNS.
- Navigate to the SNS service, then click Topics → Create Topic.
- Select Standard as the topic type.
- Name the topic (e.g.,
Victor_Game_Notification
) .
- Leave other options as default, click Create Topic and copy the ARN of the created topic (needed later).
Create an SNS Subscription
- Go to Create Subscription under the newly created topic.
-
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.
- If using email, check your inbox and confirm the subscription. For SMS, it activates immediately.
Create an SNS Publish Policy
- Open IAM in the AWS Management Console.
- Navigate to Policies → Create Policy.
- 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).
- Click Next: Review, and name the policy (e.g.,
Victor_Game_Policy
), and create it.
Create an IAM Role for Lambda
- In IAM, go to Roles → Create Role.
- Select AWS Service → Lambda → Next.
-
Attach these policies:
- SNS Publish Policy:
Victor_Game_Policy
. - AWS Managed Policy:
AWSLambdaBasicExecutionRole
.
- SNS Publish Policy:
- Click Next: Review, name the role (e.g.,
Lambda_Game_Role
), and create it.
Deploy the Lambda Function
- Open the AWS Management Console and go to Lambda.
- Click Create Function → Author from Scratch.
- Name the function (e.g.,
Victor_Game_Notty
). - Select Python 3.x as the runtime.
- Assign the Lambda_Game_Role created earlier.
- Click Create Function.
-
Under Function's Code Tab:
- Copy the content of
src/gd_notifications.py
and paste it into the inline editor. - Click Deploy.
- Copy the content of
- Under Configuration → Environment Variables, add:
-
NBA_API_KEY
: Your NBA API key. -
SNS_TOPIC_ARN
: The ARN of the SNS topic created earlier.
- Save the settings.
Test the Lambda Function
- Click Test → Create 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).
Set Up Automation with EventBridge
- Open EventBridge in the AWS Console.
- Go to** Rules** → Create Rule.
- Choose Schedule as the event source.
- 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
- Under Targets, select the Lambda function (
Victor_Game_Notty
).
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)