2015-07-25 16 views
12

Sto cercando di utilizzare AWS SimpleDB Javascript SDK. Ecco la pagina web con il mio script:Errori con 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> 

Quando ho eseguito questa pagina web ottengo questo errore:

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.

Penso che questo sia a causa della politica CORS. Ma non riesco a trovare un modo per configurare CORS per SimpleDB, quindi ho installato uno AddOn nel browser che consente di richiedere qualsiasi sito con ajax da qualsiasi fonte.

Con l'addon acceso ottengo un errore diverso:

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

ho provato a fare funzionare questo script da un file locale e ospitato su AWS S3. Ho ancora lo stesso errore. Sono sicuro che il database esiste sul mio account e posso accedervi con altri strumenti. Ma ho bisogno di accedervi con JavaScript. Che cosa sto facendo di sbagliato?

Edit:More information from the browser console

+1

Può essere correlato- http://stackoverflow.com/questions/20433655/no-access-control-allow-origin-header-is-present-on-the-requested-resource-or –

+0

Potresti postare il tuo richiesta al server e risposta del server? Potrebbe essere possibile che alcune intestazioni siano mancanti o errate per un motivo o per un altro. –

+0

@VaughnOkerlund Non sono sicuro esattamente da dove ottenere queste informazioni. Ma ho fatto una copia di tutto ciò che ho trovato nella console del browser: https://dl.dropboxusercontent.com/u/4111969/log.txt – Lev

risposta

3

Secondo this post sul forum:

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

scopre che è attualmente impossibile usare SimpleDB AWS SDK su HTTP. Il request per aggiungere il supporto CORS è stato inviato il 27 febbraio 2014, ma sembra che non sia stato ancora implementato.