NBA Game Updates with AWS Lambda, SNS and EventBridge

Introduction:

Keeping up with NBA game scores in real-time can be challenging, especially for busy professionals. To solve this, I built an automated system that fetches NBA game scores and delivers updates via AWS SNS. This project leverages AWS Lambda, SportsData API, and SNS for efficient real-time notifications.

In this post, I'll walk you through the steps to build this solution, including fetching data from an API, formatting the game details, and sending notifications.

Architecture:

Core concepts covered:

  1. Integrating external APIs into cloud-based workflows.

  2. Designing a notification system with AWS SNS and Lambda.

  3. Securing AWS services with least privilege IAM policies.

  4. Using EventBridge to automate workflows.

Project Steps:

  1. Fetching NBA Game Data:

    • Open a SportsData API account to get a free API key.

  2. Create an SNS policy

    1. Open the AWS Management Console.

    2. Navigate to the SNS service.

    3. Click Create Topic and select Standard as the topic type.

    4. Name the topic (e.g., new_topic) and note the ARN.

    5. Click Create Topic.

2.1 : Add an email subscription to the SNS Topic

  1. After creating the topic, click on the topic name from the list.

  2. Navigate to the Subscriptions tab and click Create subscription.

  3. Select a Protocol:

  • For Email:

    • Choose Email.

    • Enter a valid email address.

  1. Click Create Subscription.

  2. If you added an Email subscription:

  • Check the inbox of the provided email address.

  • Confirm the subscription by clicking the confirmation link in the email.

  1. Create an SNS policy and assign it to a role

    1. Open the IAM service in the AWS Management Console.

    2. Navigate to Policies → Create Policy.

    3. Click JSON and paste the JSON policy from gd_sns_policy.json file

    4. Replace REGION and ACCOUNT_ID with your AWS region and account ID.

    5. Click Next: Tags (you can skip adding tags).

    6. Click Next: Review.

    7. Enter a name for the policy (e.g., gd_sns_policy).

    8. Review and click Create Policy.

3.1 Create an IAM Role for Lambda

  1. Open the IAM service in the AWS Management Console.

  2. Click Roles → Create Role.

  3. Select AWS Service and choose Lambda.

  4. Attach the following policies:

  • SNS Publish Policy (gd_sns_policy) (created in the previous step).

  • Lambda Basic Execution Role (AWSLambdaBasicExecutionRole) (an AWS managed policy).

  1. Click Next: Tags (you can skip adding tags).

  2. Click Next: Review.

  3. Enter a name for the role (e.g., gd_role).

  4. Review and click Create Role.

  5. Copy and save the ARN of the role for use in the Lambda function.

  1. Deploy the Lambda Function

    1. Open the AWS Management Console and navigate to the Lambda service.

    2. Click Create Function.

    3. Select Author from Scratch.

    4. Enter a function name (e.g., gd_notifications).

    5. Choose Python 3.x as the runtime.

    6. Assign the IAM role created earlier (gd_role) to the function.

    7. Under the Function Code section:

  • Copy the content of from this git repo Github repository

  • Paste it into the inline code editor.

  1. 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.

  1. Click Create Function.

  1. Set Up Automation with Eventbridge

    1. Navigate to the Eventbridge service in the AWS Management Console.

    2. Go to Rules → Create Rule.

    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 (gd_notifications) and save the rule.

  2. Test the System

    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 that SMS notifications are sent to the subscribed users.

  3. Success!!

    • I successfully recieved the games updates in my email inbox!!!

  4. 💡 Future Recommended Steps:
    1. Add a frontend dashboard for real-time score tracking
    2. Extend support to other sports (NFL, MLB, etc.)
    3. Implement advanced analytics on game data

    What do you think? Have you built similar automation projects? Let’s discuss in the comments!

    See you next time!

10
Subscribe to my newsletter

Read articles from Oriazowan Emmanuel directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Oriazowan Emmanuel
Oriazowan Emmanuel