title: AWS S3 and Django returns "An error occurred (AccessDenied) when calling the PutObject operation"
body: <p>I am trying to set up media and static files storage in an AWS S3 bucket, in a Django app, and am getting the following error when I try to run <code>python manage.py collectstatic</code> to put the static files into the bucket:</p>
  
  <blockquote>
    <p>botocore.exceptions.ClientError: An error occurred (AccessDenied) when calling the PutObject operation: Access Denied</p>
  </blockquote>
  
  <p>I am running boto3 and django storages. I have trawled through the other answers on here and tried the ideas in there first. My access key etc is correct as I can connect to SES OK. I have CORS configured in the bucket.</p>
  
  <p>My bucket policy is</p>
  
  <pre><code>{
  "Id": "Policyxxx",
  "Version": "2012-10-17",
  "Statement": [
      {
          "Sid": "Stmtxxx",
          "Action": "s3:*",
          "Effect": "Allow",
          "Resource": [
              "arn:aws:s3:::bucketname/*",
              "arn:aws:s3:::bucketname"
          ],
          "Principal": {
              "AWS": [
                  "arn:aws:iam::xxxx:user/xxxx"
              ]
          }
      }
  ]
  }
  </code></pre>
  
  <p>My IAM user has AmazonS3FullAccess as below:</p>
  
  <pre><code>{
  "Version": "2012-10-17",
  "Statement": [
      {
          "Effect": "Allow",
          "Action": "s3:*",
          "Resource": "*"
      }
  ]
  }
  </code></pre>
  
  <p>I have also tried creating my own policy and attaching that to the IAM user as follows:</p>
  
  <pre><code>{
  "Version": "2012-10-17",
  "Statement": [
      {
          "Effect": "Allow",
          "Action": "s3:*",
          "Resource": [
              "arn:aws:s3:::bucketname",
              "arn:aws:s3:::bucketname/*"
          ]
      }
  ]
  }
  </code></pre>
  
  <p>None of these work so I am clearly missing something.</p>