How To Use Mastodon With Cloudflare R2

Home » Notes » How To Use Mastodon With Cloudflare R2

Since Mastodon is compatible with Amazon S3, it automatically is also compatible with Cloudflare R2. Why? Because R2 uses the same API endpoints. So, what works with Amazon S3 works with Clouflare R2 as well.

Sounds pretty straight forward, in installing my Mastodon instance with Cloudflare R2 storage, I ran into a few small niggles that made it not working in the first place.

Time needed: 5 minutes

Here’s how to fix that:

  1. Log into your Mastodon server

    Log into your Mastodon server and grant yourself root access with sudo su.

  2. Navigate to where Mastodon environment file is located

    You’ll find this file located in the following structure (if you’ve installed on Ubuntu, that is):

  3. Edit the configuration file

    I use nano but you can use whatever editor you prefer. For nano it looks like this: nano env.production
    If you’ve not configured it to serve from S3 there will be very little info, but if you have, you will have to delete all AWS and S3 lines from that config file.

  4. Use this template as a basis for your configuration

    Copy this to a text editor and change the values according to your situation:
    This is ignored by R2, but it needs to be set to something valid

    The AWS Access Key and AWS Secret Access Key are your R2 keys, of course. Please take note of when to use and not to use https in front of the values.

  5. Copy and paste this inside your terminal

    Copy and paste your version of the above listed template inside your .env.production file and save the file.

  6. That should do it.

    If you’re moving over from S3 or an existing instance with local storage, you will have to move over the files to the R2 bucket.

    But other than that, that should do it.

You know have a fully scalable Mastodon server where you don’t have to worry about storage exceeding your server’s allocation. And cheaply.

First name
This field is for validation purposes and should be left unchanged.

Automatically sent to your inbox, just like 🪄 

Leave a Reply

Your email address will not be published. Required fields are marked *