0

Je souhaite utiliser aws-sdk dans Javascript. J'ai donc installé browserify et aws-sdk avec l'installation de nam. Dans les Terminaux que j'ai écritsAWS & Node.js: Configuration des informations d'identification à l'aide de Browserify

browserify project/project.js > browser-app.js 

Il crée un navigateur-app.js pour moi. Maintenant, je veux courir un code comme celui-ci dans mon navigateur:

var AWS = require('aws-sdk'); 
var sqs = new AWS.SQS() 
var params = { 
       MessageBody: JSON.stringify(SOMEJson), 
       QueueUrl: QueueURL 
      }; 
sqs.sendMessage(params,function(err, data){ 
       if (err) console.log(err, err.stack); 
       else  console.log(data); 
      }); 

Mon fichier d'informations d'identification est dans ~/.AWS/config

Puis je lance le code que je reçois le message d'erreur suivant:

Error: Missing credentials in config 
at credError (http://localhost:63343/urfado-regex/browser-app.js:1018:40) 
at Config.getCredentials (http://localhost:63343/urfado-regex/browser-app.js:1057:14) 
at Request.VALIDATE_CREDENTIALS (http://localhost:63343/urfado-regex/browser-app.js:3111:26) 
at Request.callListeners (http://localhost:63343/urfado-regex/browser-app.js:7214:18) 
at Request.emit (http://localhost:63343/urfado-regex/browser-app.js:7190:10) 
at Request.emit (http://localhost:63343/urfado-regex/browser-app.js:6042:14) 
at Request.transition (http://localhost:63343/urfado-regex/browser-app.js:5449:10) 
at AcceptorStateMachine.runTo (http://localhost:63343/urfado-regex/browser-app.js:9740:12) 
at Request.runTo (http://localhost:63343/urfado-regex/browser-app.js:5821:15) 
at Request.send (http://localhost:63343/urfado-regex/browser-app.js:5785:10) CredentialsError: Missing credentials in config 
at credError (http://localhost:63343/urfado-regex/browser-app.js:1018:40) 
at Config.getCredentials (http://localhost:63343/urfado-regex/browser-app.js:1057:14) 
at Request.VALIDATE_CREDENTIALS (http://localhost:63343/urfado-regex/browser-app.js:3111:26) 
at Request.callListeners (http://localhost:63343/urfado-regex/browser-app.js:7214:18) 
at Request.emit (http://localhost:63343/urfado-regex/browser-app.js:7190:10) 
at Request.emit (http://localhost:63343/urfado-regex/browser-app.js:6042:14) 
at Request.transition (http://localhost:63343/urfado-regex/browser-app.js:5449:10) 
at AcceptorStateMachine.runTo (http://localhost:63343/urfado-regex/browser-app.js:9740:12) 
at Request.runTo (http://localhost:63343/urfado-regex/browser-app.js:5821:15) 
at Request.send (http://localhost:63343/urfado-regex/browser-app.js:5785:10) 

J'ai aussi essayé hardcode mes lettres de créance avec aws.config comme ceci:

AWS.config.update({ 
       accessKeyId: "MYKEY", 
       secretAccessKey: "MYSECRETKEY", 
       "region": "eu-central-1" 
     }); 

Je reçois toujours le même erreur. Quelqu'un sait ce que je pourrais faire de mal?

Répondre

0

Lors de l'exécution d'un contexte de navigateur que vous disposez des options suivantes pour authentifier

  • Utiliser Amazon Cognito pour authentifier les utilisateurs
  • En utilisant la fédération d'identité Web pour authentifier les utilisateurs
  • codées en dur dans votre application

Assurez-vous de régler AWS.config.update({ accessKeyId: "MYKEY", secretAccessKey: "MYSECRETKEY", "region": "eu-central-1" });

avant d'instancier l'objet sqs.

Référence: http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/browser-configuring.html

+0

J'ai aussi un titres de compétence fichier dans .AWS Et je suis sûr que je mis en place la configuration avant la mise en place de l'objet sis :( – TomHere

+0

je ne savais pas que vous invoquez à partir du contexte du navigateur – Shibashis

+0

seule option que vous avez est Hard-Coding Credentials .. vérifiez que vous avez les autorisations appropriées pour la configuration accesskey sur aws IAM – Shibashis