This video is available to students only

Using S3 for static files

Serve static files from an S3 bucket

Create an S3 bucket#

This bucket should be fairly simple, but there are several settings you'll need to configure to ensure everything is working.

Bucket settings#

  • Bucket name: This should be something unique. For this lesson, we'll use the bucket name serverless-course-static-bucket. Pretty long, but it has to be unique.

  • Region: Make sure the region matches where you've deployed your Zappa project.

  • Public Access Settings:

    • Uncheck Block all public access.

    • Acknowledge that the contents of this bucket will be public - after all, that's what we're trying to achieve!

Configure the S3 bucket#

We'll need to add a CORS policy for this bucket. If you're not familiar with CORS then you can think of CORS as a set of permission instructions for web browsers to apply to any web page trying to load resources from that web server. The CORS policy is the set of permission instructions and the S3 bucket will need a CORS policy since it holds your static file resources.

While we could rely on the default CORS policy, it won't work for some static files like fonts. So it's better for us to specify our own CORS policy. And it's pretty easy to do.

Click on the bucket then click on the 'Permissions' tab. Under CORS, add the following text:

Note that this CORS policy is very open and simple. If you have a production site, you will probably want to narrow the scope of the CORS policy. It is possible that other websites could link to your static files and potentially attempt to duplicate your site.


This page is a preview of Serverless Django with Zappa

Start a new discussion. All notification go to the author.