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:
- Log into your Mastodon server
Log into your Mastodon server and grant yourself root access with
- 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):
- Edit the configuration file
nanobut you can use whatever editor you prefer. For
nanoit looks like this:
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.
- 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
AWS Access Keyand
AWS Secret Access Keyare your R2 keys, of course. Please take note of when to use and not to use
httpsin front of the values.
- Copy and paste this inside your terminal
Copy and paste your version of the above listed template inside your
.env.productionfile and save the file.
- 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.