The Discover Weekly playlist on Spotify is pretty awesome, but it gets updated every week so you unless you save all the songs you lose those hidden gems. This is a toy project to automatically and regularly save Spotify playlists. There is an existing IFTTT integration but I wanted to flex my coding chops and try out some things on AWS.
Consists of:
- Three AWS lambdas
root- a simple redirect which kicks off the auth flow.callback- which does the OAuth dance, retrieving the OAuth token and storing in DynamoDB for subsequent operations.save- which does the actual saving of the playlist. Configure a cloudwatch cron job to run it once a week.
- A DynamoDB table
- Some cloud watch rules to schedule weekly saving
Hit the root / endpoint, which will redirect you to Spotify to login and authorise the app. Once you've authorised the app you should see a success message. This will schedule a weekly back up of Discover Weekly, the first one will happen in 2 minutes from when you invoke the app.
- Create DynamoDB table
spotifywithusernameas primary key - Run
build.shto build and deploy the lambda code to AWS. - Create API gateway definition
- Point
/to root - Point
/callbackto callback and add query string parameterscode,state, anderror
- Point
- Deploy the API
- Update lambdas with env variables
REDIRECT_URI- this is the API Gateway url to the/callbackendpointSPOTIFY_ID- the client ID from SpotifySPOTIFY_SECRET- the client secret from Spotify
- Create an IAM role for the lambdas to run under. They need to
- Create new cloud watch rules
- Read and write to dynamo db
- Write logs to cloud watch
- Add support for the state parameter to fix security hole