Updated s3 region setting not working for newly uploaded assets

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.