dev-resources.site
for different kinds of informations.
Game Notification System with Amazon Event Scheduler, AWS Lambda, and Amazon SNS Using Terraform
In this project I will utilize Terraform to automate the provisioning of a game notification system using Amazon EventBridge, AWS Lambda and Amazon SNS. Terraforms ability to manage infrastructure as code will enhance consistency, reduce errors, and accelerate the development of a robust notification system.
System Architecture Overview
• Scheduler (Amazon EventBridge): EventBridge schedules events, such as game start times, or scores updates. These scheduled events trigger Lambda functions to retrieve data from sportdata.io (NBA API).
• AWS Lambda: Lambda functions process NBA games data fetched from sportdata.io. It formats notifications with relevant information (e.g., NBA game schedules, scores or game highlights).
• Amazon SNS: Processed notifications are sent to Amazon SNS. Amazon SNS manages the distribution of messages to multiple subscribers via email, SMS, or mobile push notifications.
Prerequisites:
• AWS account with required access and permission to configure services such as Lambda, SNS, and EventBridge.
• Experience with programming languages supported by AWS Lambda, such as Python, Node.js, or Java.
• Terraform installed on your local machine
• AWS CLI Installed and configured on your local machine.
Define Your Lambda function
I will be creating a python code that our lambda function will use to retrieve NBA games data from sportdata.io, process it and publish to Amazon SNS. See complete code in the repository.
Terraform Configuration
We will be using Terraform modules for this deployment. Modules are a key feature of Terraform that promotes modularity, reusability, and maintainability in infrastructure as code. Each folder in the modules directory will contain the infrastructures required to be deployed for each AWS service. See below.
• EventBridge Module: This EventBridge scheduler sets up recurring NBA game events that triggers the lambda function.
• Iam_Role Module: This module contains the terraform codes that defines the necessary permissions for lambda to be able to publish to Amazon SNS and EventBridge to be able to trigger the lambda function.
• Lambda Module: This module defines the terraform codes for archiving the python code in a zip file and also create a lambda function that retrieves NBA data from sportsdata.io, process it and publish to Amazon SNS.
• SNS module: This module defines the terraform codes that manages the distribution of processed notifications from lambda to multiple subscribers via email, SMS, or mobile push notifications.
Check the link below for the full terraform configurations.
https://github.com/OjoOluwagbenga700/Game-Notification-System.git
Step 1: Clone the Terraform Code
By cloning the Terraform code, we'll have access to the infrastructure-as-code configurations needed for our deployment process.
Clone Repository: Use the git clone command to clone the Terraform code repository to your local machine. Ensure that you have Git installed and configured on your system.
https://github.com/OjoOluwagbenga700/Game-Notification-System.git
Change directory to the folder name game-notification-system.
Step 2: Running Terraform Commands
Below main.tf file defines all the infrastructure that will be deployed after running the terraform commands.
Terraform init: Initialize Terraform in the project directory to download necessary plugins and modules.
Run Terraform init
Terraform Plan: Generate an execution plan to preview the changes that Terraform will make to the infrastructure
Run Terraform Plan
Terraform Apply: Apply the Terraform execution plan to create infrastructure resources as needed. Respond with yes to confirm the execution plan.
Run terraform apply --auto-approve
to deploy the infrastructure on AWS.
Confirm Resources deployed on AWS
Amazon SNS Topic
Amazon SNS Subscription
Email Notification to confirm subscription
Lambda function
Environment Variables
Scheduler (Amazon EventBridge)
Cron schedule runs every 30mins from 9pm WAT
IAM Role
Game Day Notification system updates based on the cron schedule.
Conclusion: By leveraging AWS Lambda, EventBridge, and SNS, we have implemented an NBA game-day notification system using Terraform as infrastructure as code tool. This architecture enables the delivery of email notifications for your favorite NBA games.
To Clean up: Run terraform destroy
to delete all infrastructure deployed by the terraform codes.
Thanks for Reading!!!
Featured ones: