DEV Community

Cover image for Serverless Spotify Playlist Updates
Rohan
Rohan

Posted on • Edited on

Serverless Spotify Playlist Updates

Ever wonder if you could get notified when new songs are added to a Spotify playlist?

I made a Twitter bot using node.js that tweets out new songs added to Spotify's POLLEN playlist.
Link to Github Repo: Github Repo

Tools and Frameworks used:

App Workflow:
Alt Text

  1. CloudWatch Events Rule is set to trigger the Lambda function once an hour.
  2. Lambda function retrieves all songs Spotify's POLLEN playlist.
  3. If a song is not currently in the DynamoDB table, add the song to the table.
  4. For each new song, post a tweet with the artist name, song title, and link to the song.

My Thoughts:

  • 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.

Next Steps:

Useful Links:

Please feel free to leave questions or comments below!

Top comments (0)