Storing Files on Amazon S3
If you are using containers for deployment (including Docker and Heroku), avoid storing files in the container’s volatile filesystem.
This integration allows you to delegate storing such files to Amazon’s S3 service.
Base configuration
AWS_ACCESS_KEY_ID
- Your AWS access key.AWS_SECRET_ACCESS_KEY
- Your AWS secret access key.
Serving media files with an S3 bucket
If you want to store and serve media files, set the following environment variable to use S3 as a media bucket:
AWS_MEDIA_BUCKET_NAME
- The S3 bucket name to use for media files.
If you wish to use a custom domain for your media S3 bucket, you can set this environment variable to your custom S3 media domain:
AWS_MEDIA_CUSTOM_DOMAIN
- The S3 custom domain to use for the media bucket.
Note
The media files are all data uploaded through the dashboard (product images, category images, etc.).
Serving static files with an S3 bucket
By default, static files (such as CSS and JS files required to display your pages) will be served by the application server.
If you also wish to use S3 for your static files, set an additional environment variable:
AWS_STORAGE_BUCKET_NAME
- The S3 bucket name to use for static files.
If you wish to use a custom domain for your static S3 bucket, you can set this environment variable to your custom S3 domain:
AWS_STATIC_CUSTOM_DOMAIN
- The S3 custom domain to use for the static bucket.
Note
You need to configure your S3 bucket to allow cross-origin requests for some files to be properly served (SVG files, Javascript files, etc.). Follow the below instructions in your S3 Bucket’s permissions tab, under the CORS section.
<?xml version="1.0" encoding="UTF-8"?> <CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <CORSRule> <AllowedOrigin>*</AllowedOrigin> <AllowedMethod>GET</AllowedMethod> <AllowedMethod>HEAD</AllowedMethod> <MaxAgeSeconds>3000</MaxAgeSeconds> <AllowedHeader>*</AllowedHeader> </CORSRule> </CORSConfiguration>