Here’s some information about this, I was dealing with this last month.
I fixed it by setting both variables (DISCOURSE_S3_CDN_URL and DISCOURSE_CDN_URL) and creating two CloudFront distributions, one for the uploads with origin the S3 bucket, and one for the assets with origin the server.
Here’s the code we use for this
- Cloudfront distribution with S3 as origin https://github.com/debtcollective/infra/blob/master/live/prod/services/discourse/cloudfront.tf#L18-L26
- Cloudfront distribution with Server as origin https://github.com/debtcollective/infra/blob/master/live/prod/services/discourse/cloudfront.tf#L87-L98
Here’s our app.yml (we named it web.yml), we replace variables at build time https://github.com/debtcollective/infra/blob/master/modules/services/discourse/web.yml