Search code examples
djangoamazon-s3vs-web-site-project

Failed GET requests to AWS S3 from website running on local host


Problem: I am developing a website using django, with images and static content stored in S3. I get 403 forbidden errors when I run my site on local host.

GET https://mybucket.s3.amazonaws.com/static/image.jpg 403 (Forbidden)

What I have tried so far:

  • Configured CORS on my S3 bucket
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>GET</AllowedMethod>
    <AllowedMethod>PUT</AllowedMethod>
    <AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
  • Stored S3 credentials in environment variables. I have been able to run python manage.py collectstatic to upload static files to S3, so I know this connection is established.

Does anyone know what I am missing?


Solution

  • This was resolved by fixing the structure of my django project. It was not obvious, but BASE_DIR was pointing to the incorrect directory.