Skip to content

Add option to serve S3 media from a custom domain#2928

Open
mbertrand wants to merge 2 commits intomainfrom
mb/s3_custom_domain
Open

Add option to serve S3 media from a custom domain#2928
mbertrand wants to merge 2 commits intomainfrom
mb/s3_custom_domain

Conversation

@mbertrand
Copy link
Member

@mbertrand mbertrand commented Feb 5, 2026

What are the relevant tickets?

Related to https://github.com/mitodl/hq/issues/9046 and mitodl/ol-infrastructure#3979

Description (What does it do?)

  • Adds a new setting AWS_S3_CUSTOM_DOMAIN
  • If the above is not blank, the MEDIA_URL setting is updated to include the domain

How can this be tested?

  • Set MITOL_USE_S3=True if it isn't already.
  • With AWS_S3_CUSTOM_DOMAIN blank/null (default), everything should work as before
  • In Django Admin, look at the details for one of the Testimonials. If MITOL_USE_S3=True was already true, the avatar and banner images if not blank should have S3 urls. If they don't, upsert a new image. When done it should have an S3 url.
  • Set AWS_S3_PREFIX to something like "mymedia/" and restart
  • Go back to an Attestation object and upload a new image. Check that the S3 url for it has "mymedia" as part of the URL right after the domain
  • Set AWS_S3_CUSTOM_DOMAIN to something like fakefastllycdn.com and restart the containers
  • Go back to Django Admin and look at the urls for the avatar images, they should start with https://fakefastllycdn.com

@mbertrand mbertrand added the Needs Review An open Pull Request that is ready for review label Feb 5, 2026
@shanbady shanbady self-requested a review February 6, 2026 15:33
Copy link
Contributor

@shanbady shanbady left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 looks good

small question i had is why not just make the MEDIA_URL itself configurable via env var instead of creating a new flag

@shanbady shanbady added Waiting on author and removed Needs Review An open Pull Request that is ready for review labels Feb 6, 2026
@mbertrand
Copy link
Member Author

@shanbady I decided to modernize how this is set since Django 4.2 - https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html

and updated the testing instructions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants