question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add Digital Ocean spaces as storage option

See original GitHub issue

Description

those who do not use AWS s3 but use Digitalocean spaces have trouble deploying static and media, the configurations are a little different.

Solution

AWS_S3_ENDPOINT_URL = env(DJANGO_AWS_S3_ENDPOINT_URL)
AWS_LOCATION = env(DJANGO_AWS_LOCATION)

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
stefanitskycommented, Sep 27, 2019

I think i found a solution, but need to be reproduced again. First of all need to update DO settings (Spaces -> Select a space -> Settings -> CORS Configurations): 2019-09-27-210821_548x363_scrot

My .envs/.production/.django:

# DigitalOcean Spaces
DJANGO_AWS_ACCESS_KEY_ID=key is here (removed)
DJANGO_AWS_SECRET_ACCESS_KEY=key is here (removed)
DJANGO_AWS_STORAGE_BUCKET_NAME=storage name
#DJANGO_AWS_S3_REGION_NAME=fra1
DJANGO_AWS_S3_ENDPOINT_URL=https://(storage name).fra1.digitaloceanspaces.com
DJANGO_AWS_LOCATION=fra1

My production config settings for STATIC and MEDIA (config/settings/production.py):

# STORAGES
# ------------------------------------------------------------------------------
# https://django-storages.readthedocs.io/en/latest/#installation
INSTALLED_APPS += ["storages"]  # noqa F405
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
AWS_ACCESS_KEY_ID = env("DJANGO_AWS_ACCESS_KEY_ID")
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
AWS_SECRET_ACCESS_KEY = env("DJANGO_AWS_SECRET_ACCESS_KEY")
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
AWS_STORAGE_BUCKET_NAME = env("DJANGO_AWS_STORAGE_BUCKET_NAME")
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
AWS_QUERYSTRING_AUTH = False
# DO NOT change these unless you know what you're doing.
_AWS_EXPIRY = 60 * 60 * 24 * 7
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
AWS_S3_OBJECT_PARAMETERS = {
    "CacheControl": f"max-age={_AWS_EXPIRY}, s-maxage={_AWS_EXPIRY}, must-revalidate"
}
#  https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
AWS_DEFAULT_ACL = None
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
AWS_S3_REGION_NAME = env("DJANGO_AWS_S3_REGION_NAME", default=None)
AWS_S3_ENDPOINT_URL = env('DJANGO_AWS_S3_ENDPOINT_URL')
AWS_LOCATION = env('DJANGO_AWS_LOCATION')

# STATIC
# ------------------------------------------------------------------------------
STATICFILES_STORAGE = "config.settings.production.StaticRootS3Boto3Storage"
STATIC_URL = f"https://{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com/static/"

# MEDIA
# ------------------------------------------------------------------------------
# region http://stackoverflow.com/questions/10390244/
# Full-fledge class: https://stackoverflow.com/a/18046120/104731
from storages.backends.s3boto3 import S3Boto3Storage  # noqa E402


class StaticRootS3Boto3Storage(S3Boto3Storage):
    location = "static"
    default_acl = "public-read"


class MediaRootS3Boto3Storage(S3Boto3Storage):
    location = "media"
    default_acl = "public-read"
    #file_overwrite = False


# endregion
DEFAULT_FILE_STORAGE = "config.settings.production.MediaRootS3Boto3Storage"
MEDIA_URL = f"https://{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com/media/"

I don’t know, what is right solution, because i also removed file_overwrite = False.

2reactions
vladdostercommented, Apr 14, 2019

Is this still a requested feature @jeanluc243? I could knock this out this week.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I add storage space? - DigitalOcean
There are two ways to add extra storage to your Droplet. First one being adding an extra Volumes and next being resizing the...
Read more >
DigitalOcean Spaces | S3-Compatible Cloud Object Storage
S3-compatible object storage with a built-in CDN that makes scaling easy, reliable, and affordable. $5/mo.
Read more >
Spaces - DigitalOcean Documentation
Spaces is an S3-compatible object storage service that lets you store and serve large amounts of data. The free, built-in Spaces CDN minimizes...
Read more >
How to Create Spaces - DigitalOcean Documentation
DigitalOcean Spaces allows you to store and serve large amounts of data. Each Spaces bucket you create within an account has its own...
Read more >
Storage - DigitalOcean Documentation
Spaces is an S3-compatible object storage service that lets you store and serve large amounts of data. The free, built-in Spaces CDN minimizes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found