title: loading and serving static and media files with django and aws S3
body: <p>I am trying to configure my Django app to load static and media files to aws s3 buckets.</p>
  
  <p>I have set up the following file structure:</p>
  
  <p>settings.py:</p>
  
  <pre><code>AWS_ACCESS_KEY_ID = '&lt;my_key&gt;'
  AWS_SECRET_ACCESS_KEY = '&lt;my_access_key&gt;'
  AWS_STORAGE_BUCKET_NAME = '&lt;my_bucket_name&gt;'
  AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
  AWS_S3_OBJECT_PARAMETERS = {
      'CacheControl': 'max-age=86400',
  }
  AWS_LOCATION = 'static'
  
  STATICFILES_DIRS = [
      os.path.join(BASE_DIR, 'static'),
  ]
  STATIC_URL = 'https://%s/%s/' % (AWS_S3_CUSTOM_DOMAIN, AWS_LOCATION)
  STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
  </code></pre>
  
  <p>I have set up a user and a bucket on AWS per the instructions <a href="https://simpleisbetterthancomplex.com/tutorial/2017/08/01/how-to-setup-amazon-s3-in-a-django-project.html" rel="nofollow noreferrer">here</a>.</p>
  
  <p>When I run <code>python3 manage.py collectstatic</code> the staticfiles compile locally in a staticfiles folder but not on AWS. I'm using Python 3.</p>