[英]AWS&Node.js : Setting up Credentials using Browserify
我想在Javascript中使用aws-sdk。 所以我用nam install安装了browserify和aws-sdk。 在终端中,我写道
browserify project/project.js > browser-app.js
它为我创建了一个browser-app.js。 现在,我想在浏览器中运行以下代码:
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);
});
我的凭证文件在〜/ .aws / config中
然后我运行代码,得到以下错误消息:
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)
我还尝试使用aws.config对我的凭据进行硬编码,如下所示:
AWS.config.update({
accessKeyId: "MYKEY",
secretAccessKey: "MYSECRETKEY",
"region": "eu-central-1"
});
我仍然遇到相同的错误。 有人知道我该怎么做吗?
从浏览器上下文执行时,您可以使用以下选项进行身份验证
确保设置了AWS.config.update({ accessKeyId: "MYKEY", secretAccessKey: "MYSECRETKEY", "region": "eu-central-1" });
在实例化sqs对象之前。
参考: http : //docs.aws.amazon.com/AWSJavaScriptSDK/guide/browser-configuring.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.