benji1123 / www.benli99.xyz

https://www.benli99.xyz/
http://www.benli99.xyz/
0 stars 0 forks source link

Build backend to store and serve music for website #22

Open benji1123 opened 1 year ago

benji1123 commented 1 year ago

Requirements

I'm using paid music (downloaded from uppbeat.io with my subscription), so the music file needs to be hidden from the public (to prevent ppl from downloading it) but accessible by my website

Alternatives:

Tech Questions

References

benji1123 commented 1 year ago

Overview

I want the website to play cyberpunk themed music to immerse the viewer. I've already purchased and downloaded tracks from uppbeat that I'd like to use. To make these songs accessible to my website, I need to (A) store them somewhere (B) build a service to return them.

Solution 1: store in github repo

This website is hosted from a github repo as of today (April 2023), so the easiest solution is to push my songs here then play them:

const music = new Audio("$path-to-mp3-file");
music.play()

pros:

cons:

Solution 2: AWS S3 + Lambda + API Gateway

Main flow

  1. Store music files in an S3 bucket
  2. Fetch songs from S3 with AWS lambda function
  3. Give Lambda function an HTTP endpoint with API Gateway so website can request songs

API Access Control

(The API shouldn't work for other people) Setup a API Gateway Lambda authorizer to only allow API calls from my domain name.

Pros:

Cons:

Solution 3: Heroku

This is similar to Solution 2: AWS where my music-fetching service runs on a dyno for a fixed monthly-cost (~$5-10/month). There's no music storage solution here, so we'd still employ S3 for song storage and access it from our dyno like this.

Pros:

Cons:

benji1123 commented 1 year ago

My music files may be too large to send in one response. Read: https://aws.amazon.com/blogs/compute/introducing-aws-lambda-response-streaming/