Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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="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

like image 911
Lev Avatar asked Jul 25 '15 09:07

Lev


People also ask

Does AWS support JavaScript?

The AWS SDK for JavaScript supports three runtimes: JavaScript for browser, Node. js for server, React Native for mobile development. It also supports cross-runtime: a service client package can be run on browsers, Node. js, and React-Native without code change.

Is Amazon SimpleDB NoSQL?

Amazon SimpleDB is a highly available NoSQL data store that offloads the work of database administration. Developers simply store and query data items via web services requests and Amazon SimpleDB does the rest.

What is SimpleDB used for?

Amazon Simple Database Service (SimpleDB), also known as a key value data store, is a highly available and flexible non-relational database that allows developers to request and store data, with minimal database management and administrative responsibility.


1 Answers

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.

like image 184
Lev Avatar answered Oct 17 '22 14:10

Lev