title: Amazon S3 javascript sdk for Browser throwing 403 error
body: <p>I am using Amazon s3 javascript sdk for one of my applications. I am getting the following error:</p>
  
  <pre><code>XMLHttpRequest cannot load https://s3.amazonaws.com/. Response for preflight has invalid HTTP status code 403
  </code></pre>
  
  <p>I see that the preflight requests are failing in my case.</p>
  
  <p>I am using Angular2 for my application and I am trying to get the list of buckets. This is the code I wrote:</p>
  
  <pre><code>getBuckets(comp: any) {
          var s3 = this.getS3();
          var params = {};
          s3.listBuckets(params, function(err, response) {
              if (err) {
                  console.log(err);
                  console.log('error from list buckets');
              }
              else {
                  comp.buckets = response.Buckets;
              }
          })
      }
  </code></pre>
  
  <p>this.getS3() is a method I wrote to create an S3 instance. This is how it looks:</p>
  
  <pre><code>private getS3() {
          var currentUser = this.accountInfoService.getCurrentUser();
          AWS.config.update({ accessKeyId: currentUser.accessKeyId, secretAccessKey: currentUser.secretAccessKey });
          var Logger = { log: function(line) { console.log(line) } };
          if (currentUser.isECS) {
              console.log(currentUser.isECS);
              var ep = new AWS.Endpoint('http://' + currentUser.endPoint);
              var s3 = new AWS.S3({ endpoint: ep, s3ForcePathStyle: true, logger: Logger, sslEnabled: false });
          }
          else {
              var s3 = new AWS.S3();
          }
          return s3;
      }
  </code></pre>
  
  <p>Can someone please tell me what I am doing wrong here.</p>