Digital Ocean¶
Example configuration for using the AWS backend with Digital Ocean Spaces.
Usage¶
You can use the models/storage backends/views/etc from the blog post below to create a test site (called mysite) to try this out. Testing locally using runserver works.
See the folder “s3-example-public-and-private” from the GitHub repo for that blog post: https://github.com/sibtc/simple-s3-setup
To get the access key and secret key, follow the getting started guide from DigitalOcean: https://www.digitalocean.com/community/tutorials/managing-access-to-digitalocean-spaces#option-1-%E2%80%94-sharing-access-to-spaces-with-access-keys
Public Configuration¶
Put these values in your main settings.py file or whichever “public” configuration system you use (e.g. secure key/value storage).
Some of these values are built-in, some of them are used by the code linked to in “Usage” above.
Name | Description | Example value |
---|---|---|
AWS_STORAGE_BUCKET_NAME | The name of the storage bucket. | mysite |
AWS_S3_ENDPOINT_URL | The endpoint url excluding the bucket name. | https://nyc3.digitaloceanspaces.com |
AWS_S3_OBJECT_PARAMETERS | Default params for objects. | { ‘CacheControl’: ‘max-age=86400’ } |
AWS_LOCATION | The folder within the space to store files. | mysite |
AWS_S3_SIGNATURE_VERSION | Signature version. DigitalOcean only support v2 for pre-signed urls. | s3=s3v2 (Version 2), s3v4=s3v4 (Version 4) |
AWS_STATIC_LOCATION | The folder within the space to store static files. | ‘%s/static’ % AWS_LOCATION |
STATICFILES_STORAGE | The storage backend to use for static files. | ‘mysite.storage_backends.StaticStorage’ |
STATIC_URL | The base URL for generating URLs to static files included in rendered pages. | “https://%s/%s/” % (AWS_S3_ENDPOINT_URL, AWS_STATIC_LOCATION) |
AWS_PUBLIC_MEDIA_LOCATION | The folder within the space to store public media files. | ‘%s/media/public’ % AWS_LOCATION |
DEFAULT_FILE_STORAGE | The storage backend to use for public media files. | ‘mysite.storage_backends.PublicMediaStorage’ |
AWS_PRIVATE_MEDIA_LOCATION | The folder within the space to store private media files. | ‘%s/media/private’ % AWS_LOCATION |
PRIVATE_FILE_STORAGE | The storage backend to use for private media files. | ‘mysite.storage_backends.PrivateMediaStorage’ |
Private Configuration¶
Put these values in your private settings file or whichever “private” configuration system you use (e.g. secure key/value storage).
Don’t push these settings to any Git repository or any other public site. Do not share them.
Name | Description |
---|---|
AWS_ACCESS_KEY_ID | The access key for the storage API. Although this can be public, it’s useful to store it with the secret key to force the server admin to think about / change it, at the same time as changing the secret. |
AWS_SECRET_ACCESS_KEY | The secret key for the storage API. Never reveal this to anyone :) |