Skip to content
Lambda function to log my recently played songs from Spotify
Python
Branch: master
Clone or download
Latest commit f7b2336 Oct 13, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE Create LICENSE Dec 21, 2017
README.md Flesh out setup instructions a bit more Dec 21, 2017
index.py Only submit a batch of items if we have one Jul 14, 2018
requirements.txt

README.md

Track Spotify Plays

A lambda function I run every twenty minutes via AWS Cloudwatch Events to make a persistent log of my Spotify listening history. For those "what was that song I was listening to?" moments.

Installation

To run this, you'll need to set up...

  • DynamoDB
  • A Spotify Application
  • AWS Lambda

Someone contributing a SAM config or something to automate this would be most welcome!

DynamoDB Setup

You'll need to set up a DynamoDB table named spotify-plays with played_at as the partition key.

Spotify Application Setup

First, register a new Spotify application. Make note of the Client ID and Client Secret - you'll need them later.

Now you need to generate an auth token for your Spotify user, so that you can query the API for data specific to your account. There's probably a better way to do this (contributions welcome!), but I cheat and do the following:

Lambda Setup

Set up a new Lambda function using Python 3. I uploaded the code as a zip, including its dependencies, like so:

$ pip install -t . -r requirements.txt
$ zip -r /tmp/app.zip *

You'll need to create the following environment variables - these correspond to the values I told you to keep track of earlier:

  • SPOTIFY_REFRESH_TOKEN
  • SPOTIFY_CLIENT_ID
  • SPOTIFY_CLIENT_SECRET

You'll need to use KMS to encrypt these values (since the code assumes they're encrypted).

Finally, you'll want to set up a CloudWatch Event to trigger the function every so often - I set mine to trigger every twenty minutes.

You can’t perform that action at this time.