title: AWS S3 Bucket - Access Denied when trying to upload a file
body: <p>I'm trying to upload a File to AWS S3 amazon from an HTTP request in my frontend app but I'm receiving the following error in my browser: 
  Response {type: "cors", url: "<a href="https://my-bucket.s3-sa-east-1.amazonaws.com/08" rel="nofollow noreferrer">https://my-bucket.s3-sa-east-1.amazonaws.com/08</a>…nedHeaders=host%3Bx-amz-acl&amp;x-amz-acl=public-read", redirected: false, status: 403, ok: false, …}
  In the Network tab it shows: "Access Denied" Error</p>
  
  <p>So, I think there is an issue with the Policy of my bucket:
    This is what I've configured in my bucket Policy:</p>
  
  <pre><code>{
  "Version": "2012-10-17",
  "Id": "Policy1544564620007",
  "Statement": [
      {
          "Sid": "Stmt1544564832145",
          "Effect": "Allow",
          "Principal": {
              "AWS": [
                  "arn:aws:iam::&lt;account-number&gt;:root"
              ]
          },
          "Action": "s3:*",
          "Resource": "arn:aws:s3:::my-bucket"
      }
  ]
  </code></pre>
  
  <p>}</p>
  
  <p>Also, The CORS configuration of the bucket is the following:
  
  </p>
  
  <pre><code>&lt;CORSRule&gt;
     &lt;AllowedOrigin&gt;http://localhost&lt;/AllowedOrigin&gt;
     &lt;AllowedOrigin&gt;http://*&lt;/AllowedOrigin&gt;
     &lt;AllowedOrigin&gt;*&lt;/AllowedOrigin&gt;
     &lt;AllowedMethod&gt;GET&lt;/AllowedMethod&gt;
     &lt;AllowedMethod&gt;POST&lt;/AllowedMethod&gt;
     &lt;AllowedMethod&gt;PUT&lt;/AllowedMethod&gt;
     &lt;AllowedHeader&gt;*&lt;/AllowedHeader&gt;
  &lt;/CORSRule&gt;
  &lt;/CORSConfiguration&gt;
  </code></pre>
  
  <p>I'm using ASW SDK in my backend server (node.js using express) to get my signed URL:</p>
  
  <pre><code>     var AWS = require('aws-sdk');
      .....
      app.post('/requestUploadURL', function(request, response) {
       var s3 = new AWS.S3(
          {accessKeyId: "&lt;my AWS Access Key Id here&gt;",
           secretAccessKey: "&lt;my AWS Secret Key here&gt;",
           endpoint: 's3-sa-east-1.amazonaws.com',
           signatureVersion: 'v4',
           region: 'sa-east-1'} 
         );
  
      var params = request.body;
  
      var s3Params = {
        Bucket: 'my-bucket', 
        Key:  params.name, //file name
        ContentType: params.type, // file type
        ACL: 'public-read'
      };
  
      var uploadURL = s3.getSignedUrl('putObject', s3Params);
  
      response.status(200).json({
           uploadURL: uploadURL
        })
   }
  </code></pre>
  
  <p>And in my front end app (vue.js) I have this code to upload the file using the pre-signed URL obtained from my backend:</p>
  
  <pre><code>  ...
   submitFile(e){
     e.preventDefault();
     var file = this.$refs.file.files[0];
     var reader = new FileReader();
     reader.addEventListener('loadend', function(e) {
       axios.post("http://localhost:3000/requestUploadURL", {
            name: file.name,
            type: file.type
        }) // end Api().post
       .then(response =&gt; {
          console.log('Upload file to AWS ')
          console.log(response)
          console.log(reader)
          var url = response.data.uploadURL
          fetch(url, {
             method: 'PUT',
             body: new Blob([reader.result], {type: file.type})
          })
          .then(res =&gt; {
              console.log('Uploaded successfull ')
              console.log(res)
            }).catch((error) =&gt; {
              console.log('Upload error: ')
              console.log(error)
            })
        }) // end first .then(response =&gt;
     }) // end reader.addEventListener
  
      reader.readAsArrayBuffer(file);
      return false
   } // end submit
  </code></pre>
  
  <p>I've to open Chorme using --args --disable-web-security because since I'm running locally the front end app (localhost:8081) and also the backend (localhost:3000). If not Chrome didn't allow to send the HTTP request due to CORS issue. </p>
  
  <p>So, please take in account I'm running this locally, and I'm using my root AWS account KEY and Secret KEY in my backend to set up the backend express servers (for getting the signed URL). I'm not using USER's (IAM)</p>
  
  <p>Do you know what could be my issue? I'm setting up the Bucket Policy wrongly? Please advice.</p>
  
  <p>Thanks!</p>