Updated s3 region setting not working for newly uploaded assets

AI-generated summary

rsweetland reported that after changing the s3_region setting in Discourse from us-east-1 to us-west-2, newly uploaded images were correctly stored in S3 but Discourse continued referencing them via the old region URL, breaking image links. The expected URL used us-west-2, but the actual URL still pointed to us-east-1. A workaround was to run discourse remap to update all URLs to the new region, which also fixed previously uploaded images. The issue appeared intermittent and occurred during setup of a new forum where the setting was toggled back and forth. The behavior was confirmed on the latest main commit (967946378). rsweetland also provided instructions for running remap on Digital Ocean and Bitnami installations. Falco clarified that this is not a bug, as remapping is expected when changing asset locations.

After changing the Discourse s3_region setting from the default us-east-1 to us-west-2, newly uploaded images were successfully uploaded to S3, but Discourse attempted to reference these at the previous, default us-east-1 region, causing any newly uploaded images to break.

Ex: For newly uploaded images…
Expected: my-bucket.s3.dualstack.us-west-2.amazonaws.com/original/1X/xyz.png
Actual: my-bucket.s3.dualstack.us-east-1.amazonaws.com/original/1X/xyz.png

Workaround Running discourse remap //my-bucket.s3.dualstack.us-east-1.amazonaws.com //my-bucket.s3.dualstack.us-west-2.amazonaws.com caused the system to use the proper s3_region for newly uploaded images (in addition to fixing previously uploaded images, as expected).

Strangely, the issue was intermittent. This may have worked for previously uploaded images. I’m not sure.

Most people probably run remap anyway when changing this setting. In my case, I was setting up a new forum. I simply changed the setting one way, then the other, causing all image uploads to break.

I verified this behavior on the latest commit on main yesterday: (commit: 967946378)

Related issues / conversations

A few notes for those stumbling on this later (including myself):

I am running discourse from the Digital Ocean installer. To run remap or other discourse scripts:

  • ssh to your server
  • cd /var/discourse
  • enter the container by running ./launcher enter app
  • cd /var/www/discourse
  • discourse remap //my-bucket.s3.dualstack.us-east-1.amazonaws.com //my-bucket.s3.dualstack.us-west-2.amazonaws.com (Once here you can also run other discourse scripts)

Here’s how to run rake / discourse scripts on Bitnami installactions

Not a bug, as it’s expected that you will need to remap if you change your assets location.