Please enable JS

Blog

An error occurred (AccessDenied) when calling the PutObject operation: Access Denied

Published on April 29, 2019, 12:31 p.m.

Django + DRF + Django-Storages + S3

Exception:
An error occurred (AccessDenied) when calling the PutObject operation: Access Denied

 

For this to work in your application, click ‘Add CORS Configuration’ and enter the following XML:

<code><?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
   <CORSRule>
        <AllowedOrigin>yourdomain.com</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>POST</AllowedMethod>
        <AllowedMethod>PUT</AllowedMethod>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>
</code>

Add policy as for bucket as well.

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": [
        "s3:PutObject",
        "s3:PutObjectAcl"
      ],
      "Resource": [
        "arn:aws:s3:::foo/bar*"
      ],
      "Effect": "Allow",
      "Principal": "*"
    }
  ]
}