Ever wonder if you could get notified when new songs are added to a Spotify playlist?
Tools and Frameworks used:
- Serverless Framework
- AWS Lambda
- AWS CloudWatch Events
- AWS DynamoDB
- aws-sdk npm package
- Twitter for Node.js npm package
- CloudWatch Events Rule is set to trigger the Lambda function once an hour.
- Lambda function retrieves all songs Spotify's POLLEN playlist.
- If a song is not currently in the DynamoDB table, add the song to the table.
- For each new song, post a tweet with the artist name, song title, and link to the song.
- Why is this a good use case for AWS Lambda? Given that I'm only running the CloudWatch Events Rule once an hour, I don't need to manage a server and run a web app 24/7. It's easier and cheaper to use a Lambda function since the code will run only when invoked.
- I've used Lambda before but this was my first time using the Serverless Framework. I found it very useful to be able to invoke my function locally before deploying to AWS.
- Initially I planned to use the npm package Lowdb to store the songs within my Lambda file but I then read Lambda functions should be stateless and any persistent state information should be kept in a separate database. This was the first time I used DynamoDB in a personal project. I found it quite easy to use the aws-sdk npm package to upload data to my DynamoDB table.
- I'd like to separate the functionality of my single Lambda function into multiple Lambda functions connected through AWS Simple Notification Service
- Use Serverless Mocha Plugin to create and run a test suite for my function.
- Spotify Web API Documentation
- Twitter API Documentation
Please feel free to leave questions or comments below!