This project contains source code and supporting files for the serverless application which polls game data for your favorite NHL team and get notified when your team scores.
This application has been initally developed for the Lightning project of Pacific Science Center to honor the Seattle Kraken team using SportRadar.com API endpoints.
More information about this project can be found here. https://www.aboutamazon.com/news/aws/hockeys-newest-superfan-lights-up-seattle
You can change the team alias for your favorite NHL team according to documentation. https://developer.sportradar.com/docs/read/hockey/NHL_v7#nhl-api-overview
The project has been developed as an AWS CDK application using Typescript.
Note: This repository is slightly different than the initial project so that the application can be used for individual interests while keeping the core functionalities and features the same.
-
You will need an AWS Account and IAM User created as well as configured in your development environment for CDK Development
-
You will need to create a developer account for sportradar.com here.
- Once registered, you will need to create an application.
- Make sure that
Issue a new key for NHL Trial
option has been selected while creating your application. - You will be given a trial API key once you have created your application.
There are two endpoints that the application is using.
git clone https://github.com/aws-samples/aws-step-functions-sports-data-polling
cd aws-step-functions-sports-data-polling
npm install
cdk bootstrap
cdk deploy --parameters teamId="sr:team:794340" --parameters emailAddress="your email address"
The parameter teamId is the id for your favorite NHL team used by sportradar.com. The default id is for Seattle Kraken but if you wanna change it for your favorite team, have a look at teams.json file for your team's id.
Once the application is deployed, it will automatically subscribe the email address that you provide as a parameter to the Scores topic.
Therefore, you will get a confirmation email similar to the following and you should confirm your subscription by clicking the "Confirm subscription" link to get scores in your email.
Note: This email address doesn't have to be the same email address you used for sportradar.com registration.
The last step is updating the API key called SportradarApiKey in AWS Systems Manager Parameter Store using your trial key from sportradar.com.
More info how to update a parameter can be found here
-
The application will deploy the following main resources.
- An EventBridge Rule to trigger
check-games-lambda
function - A Lambda function with the file
check-games-lambda
- A Lambda function with the file
game-data-lambda
- A Step Functions State Machine
- An SNS Topic with email subscription
- An EventBridge Rule to trigger
-
The EventBridge rule will invoke
check-games-lambda
function once a day at 8 AM PT. The lambda function will check the games scheduled for the day of invokation. -
If there is an NHL game for Seattle Kraken then the lambda function will create another EventBridge rule that will start an execution of the State Machine.
-
The State Machine invokes the
game-data-lambda
function every minute. (This is intentionally high due to trial key limitations.) -
The
game-data-lambda
function checks the game data for scores. -
If there is a new score, the lambda function publishes this new score to the SNS topic.
-
SNS topic notifies the subscribed email address automatically as below.
-
When the game is over, the State Machine will stop the execution.