AWS SimpleDB Javascript SDK 错误

Errors with AWS SimpleDB Javascript SDK

我正在尝试使用 AWS SimpleDB Javascript SDK。 这是包含我的脚本的网页:

  <!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>

当我 运行 这个网页时,我得到这个错误:

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.

我认为这是由于 CORS 政策。但是我找不到为 SimpleDB 设置 CORS 的方法,所以我在浏览器中安装了一个 AddOn,它允许从任何来源请求具有 ajax 的任何站点。

打开 AddOn 后出现不同的错误:

XMLHttpRequest cannot load https://sdb.amazonaws.com/. Invalid HTTP status code 400

我尝试 运行从本地文件中安装此脚本并将其托管在 AWS S3 上。我仍然遇到同样的错误。我确定该数据库存在于我的帐户中,并且我可以使用其他工具访问它。但我需要使用 JavaScript 访问它。我做错了什么?

编辑: More information from the browser console

根据 this 论坛 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

事实证明,目前无法通过 http 使用 SimpleDB AWS SDK。 添加 CORS 支持的 request 已于 2014 年 2 月 27 日提交,但似乎尚未实施。