samedi 25 juillet 2015

Errors with AWS SimpleDB Javascript SDK

I'm trying to use AWS SimpleDB Javascript SDK. Here's the web page with my script:

  <!doctype html>
  <html>
      <head>
          <meta charset="utf-8">
          <title></title>
      </head>
      <body>
        <script src="http://ift.tt/1Jl4s4h"></script>
        <script type="text/javascript">
           AWS.config.update({accessKeyId: 'MYKEY', secretAccessKey: 'MYSECRET'});
           AWS.config.region = 'us-east-1';
           AWS.config.logger = console;
        </script>

        <script>
           var simpledb = new AWS.SimpleDB({region:'us-east-1'});
           var params = { MaxNumberOfDomains: 1 };

           simpledb.listDomains(params, function(err, data) {
              if (err) console.log(err, err.stack); 
              else console.log(data);           
           });
        </script>

      </body>
  </html>

When I run this web page I get this error:

XMLHttpRequest cannot load http://ift.tt/1i6rhY3. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 400.

I think this is due to CORS policy. But I can't find a way to setup CORS for SimpleDB so I installed an AddOn into the browser which allows to request any site with ajax from any source.

With the AddOn turned on I get a different error:

XMLHttpRequest cannot load http://ift.tt/1i6rhY3. Invalid HTTP status code 400

I tried running this script from a local file and hosted it on AWS S3. I still get the same error. I'm sure the database exist on my account and I can access it with other tools. But I need to access it with JavaScript. What am I doing wrong?




Aucun commentaire:

Enregistrer un commentaire