Errors with AWS SimpleDB Javascript SDK
Asked Answered
M

1

12

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="https://dl.dropboxusercontent.com/u/4111969/aws-sdk-2.1.39.js"></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 https://sdb.amazonaws.com/. 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 https://sdb.amazonaws.com/. 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?

Edit: More information from the browser console

Mumble answered 25/7, 2015 at 9:54 Comment(5)
May be related- #20434155Srini
Could you possibly post your request to the server and the server's response? It may be possible that some headers are missing or incorrect for one reason or another.Month
@VaughnOkerlund I'm not sure exactly where to get that information from. But I made a copy of everything I could find in the browser console: dl.dropboxusercontent.com/u/4111969/log.txtMumble
Possibly related: AWS Support says CORS isn't supported on SimpleDB circa 2014.Kabyle
@Kabyle Thanks to your link I found an answer: The AWS Javascript SDK is actually built for both browser and server-side usage, which is why many services which do not include explicit CORS support are available. The Javascript in the Browser SDK explicitly supports the following services: DynamoDB, SNS, STS, S3, SQSMumble
M
3

According to this forum post:

While it is possible to use SimpleDB with the Javascript in the browser SDK, as you have noted, this requires CORS to be disabled on the client side.

The AWS Javascript SDK is actually built for both browser and server-side usage, which is why many services which do not include explicit CORS support are available.

The Javascript in the Browser SDK explicitly supports the following services: DynamoDB, SNS, STS, S3, SQS

Turns out it's currently impossible to use SimpleDB AWS SDK over http. The request to add CORS support was submitted on 27 Feb 2014, but looks like it hasn't been implemented yet.

Mumble answered 31/7, 2015 at 9:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.