SPORTS DATA IO
The flow of this project should follow as such:
AWS Lambda function will send a request to the Sports API and return data that will be pushed out to the receiver via SMS or Email. The data push will be scheduled through Eventbridge which gives periodic updates and initiates the lambda function to make the request.
PROCESS
Create the Topic
Log into the console and go to the ‘SNS’ page. Create a topic. This one will be ‘gd-topic’ for Game Day Topic. Make sure to choose standard for the topic type.
Next we will create a subscription for the updates to be sent through.
After subscribing, you should receive an email asking for confirmation of the subscription. As well as a status message from the dashboard claiming confirmation.
Create The Lambda Policy
Go to the IAM section, probably best to open it up in a different tab. Go into policies and create one. When selecting a service, choose SNS. It will then ask you what to input, where we will switch over to the JSON tab.
When we get over to the JSON tab it will give us the ability to code exactly what we want. Copy your created code/cloned repository and paste here. You will need to gather credentials for the highlighted portion. You can find these credentials in the topic tab. Make sure when pasting that it is within the quotation marks.
Create The Lambda Role
Next we will create a role to assign the policy to. You will also find this in the IAM section. Choose AWS Service for the type and Lambda for the use case.
Once the role has been created we’re going to assign the policies to the role. Search up the name of the policy you created a couple steps back, then add an additional role called the Basic Execution Role.
Create The Lambda Function
Create the Lambda Function and make sure it says ‘Author from Scratch’. Choose your desired programming language. Then click the dropdown of the default execution role and choose ‘use an existing role’. Here you will select the role created earlier.
After fully creating the role, they will give you a visual section for the code. This is where you will paste the Notification code. After pasting, click the deploy option on the left.
Here you will grab the API from your SportsDataIO account. Go into account and it will take you to the area with your subscription. I have more interest in football than basketball so I opted for the NFL subscription.
Go into the environment variables and edit them. This would be found under ‘configuration’ + ‘environment variables’. Select Add Environment Variable. There you will provide the API key as well as the SNS topic key.
TEST
Once you have your environment variables set up, you will go in and make any corrections in the code to make the information more accurate. This could be the time-zone as well as what sport. You will then test the code to see if it works, you’ll do so by going into the ‘test’ tab and creating a new test.
I ran into an issue here, so it is imperative to make sure the required information matches up accurately. I kept getting error messages because there was a discrepancy within the url. After fixing that, and choosing an earlier game date… I was able to pull this information.
After confirming the endpoint works, continue on to testing. When testing, you should receive a confirmation message.
You should also receive a push notification in your email.
SCHEDULING
Go to ‘Eventbridge’ within the applications. You will need to create a rule.
The next step is to determine its frequency. We’re gonna go with a recurring schedule. The option of Cron-based scheduling allows for a specific time to update, rather than a set frequency of updates (eg. every 10 mins). You can get more specific through the Cron expression.
The value boxes coordinate with the specific time frames as well as the frequency. In the screenshot, the 9-23 represents the hours that it will be running (Military time), and the ‘/2’ represents the frequency. So this reads that from 9am-11pm you will get updates every 2 hours.
Next, select your target. Since we are coding with a Lambda function, we would need to choose Invoke. The screen will auto-scroll down to the JSON script, and from the drop down menu you choose the function you want to invoke. It will be the ‘gd_notifications’ that we created before.
Continue to click next until the rule has been fully created. The dashboard should look like this after.
Depending on your frequency, and when you made the rule, the push notification will vary. I finished the project really close to one of the update times and here we are receiving an update.
UPDATE
After letting the app sit a bit, I waited until today’s date (01/26/2025) to keep it enabled so I could truly see the realtime updates. Here’s what the email looks like