A detailed example and guide for integrating with S3 cloud storage. We're going to connect cloud storage to:
- Django admin
- Serve static files using S3
- Access cloud storage via APIs (DRF)
- Access secure content via pre-signed URLs
- Show-case large file handling
- Writing unit tests using Moto
- CloudFront pre-signed URLs - https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#cloudfront-signed-urls
You'll learn how to integrate these two:
- LocalStack-S3
- Django-Storages
- Moto (Mock for Boto3)
Ensure you have the following installed on your system:
- Docker
- LocalStack - We recommend
brew install
orpip install
to get LocalStack on your machine. As long as you have Docker installed, everything should just work
Create a super user for test purposes: python manage.py createsuperuser
awslocal s3api create-bucket --bucket "django-localstack"
localstack status services
awslocal s3api list-objects --bucket django-localstack
docker network create django-localstack
docker network connect django-localstack localstack-main
docker build . -t django-localstack --load && \
docker run --network django-localstack -p 8000:8000 \
-v $(pwd):/code/ -t django-localstack
docker network connect django-localstack django-localstack
-
What happens without cloud storage?
- Gets stored in local file storage or wherever you point it.
- Replaces creates new stuff
- Deletes don't delete the actual file
-
Demonstrate how to configure LocalStack for the project.
- It's very easy.
-
Demonstrate how to serve static files using cloud storage.
- There are optimizations to be made here, but it is what it is.
- Make Debug=False