Sharing my recent Spotify favorites with Elm and AWS Spotify Logo

UPDATE 12-27-20: This project was updated in Using Netlify Functions & Spotify APIs. The AWS Serverless request was replaced in this post with a screenshot of the original results.

This year a friend and I shared past playlists as a way to catch up and realized they were a great way to journal. The best way to share that time and experience with each other was to listen to the playlists on our own and at our own pace. This was a surprising, no-pressure way to share myself and I wanted to explore it even more.

Live Sharing

How can I share a snapshot of myself, without it becoming dated, and without it being an overwhelming task? So far, I had the core data about me - Spotify - and the idea that I wanted it to stay current.

Get the current user’s top artists or tracks based on calculated affinity.

Spotify gives us access to a very suitable API. The goal here is to have something call this API, handle authentication, and bring the results to our blog. Later, I use this goal to scope the work and build this PoC.

Spotify Artists loaded from AWS Serverless stack

How it Works

Breaking down this project mostly came down to speed and ease of development. The goal is a product for enjoyment sake, and the highest priority is getting it out the door. The biggest decision is platform; do I want to host a server? what language do I want to write it in (Elixir is my most natural right now)? Cost isn’t a huge concern, but maintenance is.

Those questions lead me to Lambda as the backbone (I already use lots of AWS), and I can connect that with an API Gateway & DynamoDB for a fully serverless stack. This also means I can lean on CORs to only allow our website to access the Lambda, saving me a little auth code.

The Lambda is a wrapper around the Spotify API. The API gateway exposes that lambda to our website, and the DynamoDB table stores the Api token. This way, the only origin that can hit the API is our website, and the lambda knows how to handle authenticating with Spotify as my account only. That decoupled the serverless-side from the UI, which is a tiny Elm app that knows how to request and decode from the AWS endpoint.

Elm -> API Gateway -> Lambda (DynamoDB) -> Spotify API

Lessons Worth Remembering

The AWS setup and the Spotify authentication both took more time and brain power than I expected. Josh Spicer wrote a fantastic & detailed post about his process making a similar Serverless Spotify tool that was great for getting through some of that (Spotify “Now Playing” with AWS Lambda).

AWS Resources with SAM

After adding the DynamoDB table, I started to worry about all of the AWS resource setup and organization. I discovered the AWS Serverless Application Model - SAM and the Sam Cli. Together, these allow you to define your serverless stack in a single config file and deploy via the CLI. This was a game changer.

  • Codified the Project Boundaries
  • Easily Reproducible (Infrastructure as Code)
  • Sped up Development, Testing, and Deployment
  • My inner Engineer and PM were in Alignment 😊

Scoping well saved me

A secondary part of this project was to practice some non-technical skills around scoping and attempting to write blog posts before doing the fun technical tasks. I’m still reflecting on the success of those, and I highly suggest giving Shape Up a read if you’re also interested in practicing your ability to get work out the door.

Want to know more?

There are a lot of exciting technical bits to this project and realizations made along the way. Send us an email or a comment on the if you want to know more.