Setup Static Files Hosting
Static files are essential files that don’t need any dynamic changes, like static HTML, CSS, js, fonts, etc.
It’s best practice to host static files from another source and not include them in the application bundle itself.
You can have a look at the Static Files Hosting config in todo/settings/prod.py.
# Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.0/howto/static-files/ STATIC_URL = '/static/' USE_S3 = bool(os.environ.get("USE_S3_STATIC", "False")) if USE_S3 is True: AWS_ACCESS_KEY_ID = os.environ.get("CUSTOM_AWS_ACCESS_KEY_ID") AWS_SECRET_ACCESS_KEY = os.environ.get("CUSTOM_AWS_SECRET_ACCESS_KEY") AWS_STORAGE_BUCKET_NAME = os.environ.get("AWS_STORAGE_BUCKET_NAME") AWS_DEFAULT_ACL = 'public-read' AWS_S3_CUSTOM_DOMAIN = f'{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com' AWS_S3_OBJECT_PARAMETERS = {'CacheControl': 'max-age=86400'} # s3 static settings AWS_LOCATION = 'static' STATIC_URL = f'https://{AWS_S3_CUSTOM_DOMAIN}/{AWS_LOCATION}/' STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' else: MEDIA_URL = '/mediafiles/' MEDIA_ROOT = os.path.join(BASE_DIR, 'mediafiles')
How to Deploy Django Application in AWS Lambda?
Django is a Python web framework that makes it easy to build web applications quickly and securely. It has a large and helpful community that provides support and contributes to its development.
AWS Lambda is a serverless computing platform that runs your code in Docker containers, provides us with the best possible speed, and there is a number of third-party apps, and tools that make Lambda usage much easier, in this tutorial we gonna use one such tool.