๐Ÿš€ Introduction

As part of my 30 Days DevOps Challenge, i completed my second project NBA Game Updates, an automated notification system for NBA game updates using AWS services. i chose to continue with AWS for its scalability and integration capabilities, and i decided to integrate Terraform in the mix to ensure consistent automatation in the infrastructure deployment.

Project architecture diagram

Project NBA Game update diagram

๐Ÿ€ What This Project Does

This project automates NBA game update notifications by:

  • Fetching NBA Data โ€“ Retrieves real-time game data from an external API.
  • Processing Data with Lambda โ€“ Uses AWS Lambda to format and process the updates.
  • Sending Notifications via SNS โ€“ Publishes updates to an AWS SNS topic for email alerts.
  • Scheduling with EventBridge โ€“ Runs every 2 hours through AWS EventBridge triggers.

๐Ÿ› ๏ธ Tools and Technologies Used

  • Programming Language: Python โ€“ For processing NBA game updates within the Lambda function.
  • AWS Lambda: Executes the Python script to fetch, process, and send notifications.
  • AWS SNS (Simple Notification Service): Manages pub-sub messaging and sends email alerts to subscribers.
  • AWS EventBridge: Creates scheduled triggers to run the Lambda function every 2 hours.
  • AWS IAM (Identity and Access Management): Manages permissions and access control for AWS services.
  • Terraform: Automates infrastructure deployment as code, creates the Lambda function, SNS, and all the policy.

๐Ÿ“ Setup Instructions

Project Structure

Here is how the project is organized:

File Structure of nba_game_notification_update

nba_game_notification_update/
โ”œโ”€โ”€ lambda/
โ”‚   โ””โ”€โ”€ nba_game_lambda.zip      # Contains the Python code for the Lambda function.
|   โ””โ”€โ”€ requirements.txt         # Required packeges needed to run the python code
โ”œโ”€โ”€ terraform/
โ”‚   โ”œโ”€โ”€ main.tf                  # Terraform configuration defining AWS resources.
โ”‚   โ”œโ”€โ”€ variables.tf             # Terraform variables file.
|   โ”œโ”€โ”€ provider.tf              # Terraform provider and region
โ”‚   โ””โ”€โ”€ outputs.tf               # Outputs such as the SNS topic ARN.
โ”œโ”€โ”€ .gitignore                   # Specifies intentionally untracked files.
โ””โ”€โ”€ README.md                    # Project documentation and setup instructions.

Prerequisites

Ensure you have:

  • An AWS account.
  • API keys for the NBA data provider.
  • IAM roles with permissions for Lambda, SNS, and EventBridge.

How It Works

The project structure includes a Terraform configuration and a Python script:

  • Terraform: Provisions AWS resources (Lambda, SNS, EventBridge, IAM roles).
  • Python Script: Processes game data and publishes notifications via SNS.

๐Ÿ—๏ธ Order of Execution

  1. Create an SNS Topic โ€“ For email notifications.
  2. Deploy Lambda Function โ€“ Processes game data and sends alerts.
  3. Configure EventBridge Rule โ€“ Triggers Lambda every 2 hours.
  4. Subscribe Users to SNS โ€“ Adds email subscribers for updates.

๐Ÿ›ก๏ธ Monitoring with CloudWatch

To monitor the workflow, AWS CloudWatch is integrated for logging all activities. CloudWatch collects and stores logs from services like Lambda and EventBridge automatically.

How CloudWatch Integrates with Lambda:

  • When the Lambda function runs, CloudWatch captures logs from the execution.
  • It tracks metrics such as duration, errors, and invocation count.

Example CloudWatch Log Entry

Cloudwatch log

This visibility helps with performance optimization and troubleshooting.

๐ŸŒŸ Lessons Learned

This project enhanced my cloud automation and DevOps skills, teaching me:

  • How to automate infrastructure with Terraform.
  • How to build event-driven architectures with AWS services.
  • The importance of logging and monitoring with CloudWatch.

Challenges Faced and How I Overcame Them:

  • Issue: No Emails Received.

    Solution:

    • Ensure you confirmed the SNS subscription via the email link.
    • Verify the email address in the aws_sns_topic_subscription resource.
  • Issue: Errors in Lambda Execution.

    Solution:

    • Check the CloudWatch logs for the Lambda function
    • Verify that the NBA_API_KEY is correctly set and valid.

NBA Game Updates received from SNS

Notification from SNS

๐Ÿ”ฎ Future Enhancements

To improve the project, I plan to:

  • Add a retry mechanism for failed notifications โ€“ Ensures users donโ€™t miss critical updates due to temporary delivery failures.
  • Enable multi-channel alerts (SMS and mobile push notifications) โ€“ Expands accessibility beyond email, making notifications more immediate.
  • Incorporate a user-friendly dashboard with AWS QuickSight โ€“ Provides real-time analytics and visualization of game updates for better user experience.

๐ŸŽฏ Final Thoughts

This project has been a valuable experience in building serverless solutions and deploying infrastructure with Terraform. I’m excited to tackle more cloud and DevOps challenges as I continue my journey into Cloud Engineering! ๐Ÿš€

๐Ÿ”— Click here to access the project โ†’