Question

Spaces CDN read VS write files and Django settings?

On the how-to for deploying Scalable Django app., there are instructions for the settings, adding.

AWS_S3_CUSTOM_DOMAIN = 'spaces_edge_endpoint_URL'

What is not clear to me, does this URL allow writing to the also? Or do I need to somehow configure separate read and write URLs?

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-scalable-django-app-with-digitalocean-managed-databases-and-spaces#enabling-cdn-optional


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
September 8, 2023

Hi there,

When integrating Django with DigitalOcean Spaces using the CDN, the AWS_S3_CUSTOM_DOMAIN typically refers to the CDN endpoint of the Space for reading (i.e., serving static/media files). The purpose of using the CDN endpoint is to distribute the content globally to reduce latency for users fetching those assets.

For writing (i.e., uploading files to the Space), Django will use a different endpoint which will be the DigitalOcean Space’s endpoint (not the CDN endpoint). This distinction is managed internally by the libraries you use (like django-storages with the S3 backend).

To clarify:

  1. Reading Files (Serving): Your Django app will serve static and media files using the CDN endpoint (e.g., your-space-name.nyc3.cdn.digitaloceanspaces.com). This is where AWS_S3_CUSTOM_DOMAIN comes into play when you want to serve these assets using the CDN.

  2. Writing Files (Uploading): When your Django app needs to upload a file to the Space, it will use the endpoint associated with your Space directly (e.g., nyc3.digitaloceanspaces.com). This is typically managed through the AWS_STORAGE_BUCKET_NAME and AWS_S3_REGION_NAME settings in conjunction with the library.

To answer your concern directly: No, you don’t need to configure separate read and write URLs in your Django settings when using the typical django-storages setup for DigitalOcean Spaces. The AWS_S3_CUSTOM_DOMAIN is primarily for reading (serving) files through the CDN, while writing (uploading) is managed internally by the library.

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel