How To Use Linode's Object Storage For Staticfiles

Article by Wayne Fagan. Published on 29 Nov, 2020.

Recently Linode has released an alternative to AWS's S3 object storage service, called Object Storage. It uses a similar S3 architecture to AWS's offering, albeit with a much more simplified GUI and easier setup process.

Due to this similarity, I wanted to find out how easy it was to integrate this service into a Django project.

Once you have created a bucket within the GUI the rest of the setup is rather simple.

You will need to install and setup `django-storages` within the project. Next you will want to configure the project to use the bucket.

In `settings.py` you will need to add something similar to the following:

AWS_S3_REGION_NAME = 'eu-central-1'
AWS_S3_ENDPOINT_URL = f'https://{AWS_S3_REGION_NAME}.linodeobjects.com/'
AWS_STORAGE_BUCKET_NAME = 'bucket-name'
AWS_ACCESS_KEY_ID = 'ZQH8F5IRGTFPLVB1CSEC'
AWS_SECRET_ACCESS_KEY = 'CLZyacF1Dbkmi62pUJMnDn93xSjz2dtzmxis0f9S'
AWS_S3_FILE_OVERWRITE = False
AWS_DEFAULT_ACL = None
AWS_S3_USE_SSL = True

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

One of the initial things you will need to be aware of is how the `AWS_S3_ENDPOINT_URL` is formatted. Linode will generate an endpoint which looks similar to `bucket-name.eu-central-1.linodeobjects.com`, in order to use this endpoint you will need to remove the bucket name, `bucket-name`, from the endpoint. So, you'll end up with `eu-central-1.linodeobjects.com` as your endpoint.

At this point you can now run `manage.py collectstatic` to push your static files to the bucket.

Although this is a relatively simple transition, creating a bucket and pushing objects, unfortunately this is where the bottlenecks (at the time of writing) start to appear.

Fortunately you are able to set ACLs and CORs in the GUI. But, if you alter the ACL on a bucket before running `manage.py collectstatic` the resulting objects do not inherit that ACL. CORs are a simple toggle button, but it's not clear as to what the settings are.

Also, you are unable to create or delete directories from the GUI.

This may seem like show stoppers but the solution is to use `s3cmd`, using this unlocks the power of Linode's object storage. s3cmd is a terminal based tool which enables you to gain more control of the object storage from Linode. One of the main benefits to `s3cmd` is that it is simple enough to use and has thorough documentation.

Apart from the immaturity of the service, in terms of the GUI's feature set, it is competitively priced, and it is being actively developed by a well established and revered company. If your willing to use `s3cmd` then it is a worthy alternative to AWS's offering for a Django project.