Stop using Amazon s3 for uploads

Not smarter than you but just went through it - and made it out with @Pravi’s help.

The steps that you need to take to move from S3 upload back to the vanilla state

This is not super-easy - take great care with the text and links as it will be a right mess to tidy up if it goes wrong. But it is very doable.

Step 1 - Copy the files from your S3 bucket to the `public/uploads/default’ folder

First, install AWS CLI inside the app container

cd /var/discourse
./launcher enter app
sudo apt install awscli

Configure aws with your S3 ID and password (usually straightforward)

aws configure

Then use aws to copy all the content of the bucket into public/uploads/default/

aws s3 sync s3://my-bucket-name/ public/uploads/default/

Step 2 - Remap the S3 URL

This is easiest by finding an image on your forum and inspecting the URL. You want every bit until the actual filename (including the last /):

discourse remap //the-long-url-in-your-images-until-the-filename /uploads/default/

Step 3 - Rebake the posts and rebuild the app:

rake posts:rebake
exit
./launcher rebuild app

Step 4 - Turn off S3

  1. Switch off S3 uploads in the settings (or in your app.yml if you set it up that way). If you have been using a CDN, then remove the link to it from the setting too (otherwise it doesn’t actually turn off).
  2. Turn off your container. I did this by moving the content to a new container as a backup as an initial step.

Whew! Done. So far I haven’t encountered any issues. Go and test it out!

10 Likes