当我尝试向 S3 存储桶 (Node.js) 发送内容时,AWS 缺少凭证 [英] AWS Missing credentials when I try send something to my S3 Bucket (Node.js)
本文介绍了当我尝试向 S3 存储桶 (Node.js) 发送内容时,AWS 缺少凭证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从昨天开始就遇到这个问题,我很难找到解决方案.
I'm having this issue since yesterday, and I'm having trouble for find a solution.
我正在尝试向我的 S3 存储桶发送一些内容,但是当我尝试时,此消息出现在我的控制台中:
I'm trying to send somethings to my S3 bucket, but this message appear in my console when I try:
{ [CredentialsError: Missing credentials in config]
message: 'Missing credentials in config',
code: 'CredentialsError',
errno: 'Unknown system errno 64',
syscall: 'connect',
time: Thu Oct 09 2014 14:03:56 GMT-0300 (BRT),
originalError:
{ message: 'Could not load credentials from any providers',
code: 'CredentialsError',
errno: 'Unknown system errno 64',
syscall: 'connect',
time: Thu Oct 09 2014 14:03:56 GMT-0300 (BRT),
originalError:
{ code: 'Unknown system errno 64',
errno: 'Unknown system errno 64',
syscall: 'connect',
message: 'connect Unknown system errno 64' } } }
这是我的代码:
var s3 = new AWS.S3();
AWS.config.loadFromPath('./AwsConfig.json');
s3.putObject(params, function(err) {
if(err) {
console.log(err);
}
else {
console.log("Succes");
}
});
凭据正确.有谁知道可以是什么?我已经搜索过,但找不到任何解决方案.
The credentials are correct. Does anyone know what can be? I've searching but I not find anywhere the solution.
我的凭据(假):
{
"accessKeyId": "BLALBLALBLALLBLALB",
"secretAccessKey": "BLABLALBLALBLALBLLALBLALLBLALB",
"region": "sa-east-1",
"apiVersions": {
"s3": "2006-03-01",
"ses": "2010-12-01"
}
}
求助,所有代码:
var fs = require('fs');
var AWS = require('aws-sdk');
var s3 = new AWS.S3();
AWS.config.loadFromPath('./MYPATH.json'); //this is my path to the aws credentials.
var params = {
Bucket: 'testing-dev-2222',
Key: file,
Body: fs.createReadStream(file)
};
s3.putObject(params, function(err) {
if(err) {
console.log(err);
}
else {
console.log("Success");
}
});
新错误:
New err:
Error uploading data: { [PermanentRedirect: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.]
message: 'The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.',
code: 'PermanentRedirect',
time: Thu Oct 09 2014 14:50:02 GMT-0300 (BRT),
statusCode: 301,
retryable: false }
推荐答案
尝试对参数进行硬编码,看看是否再次出现错误:
Try hardcoding your params and see if you get the error again :
AWS.config.update({
accessKeyId: "YOURKEY",
secretAccessKey: "YOURSECRET",
"region": "sa-east-1" <- If you want send something to your bucket, you need take off this settings, because the S3 are global.
}); // for simplicity. In prod, use loadConfigFromFile, or env variables
var s3 = new AWS.S3();
var params = {
Bucket: 'makersquest',
Key: 'mykey.txt',
Body: "HelloWorld"
};
s3.putObject(params, function (err, res) {
if (perr) {
console.log("Error uploading data: ", err);
} else {
console.log("Successfully uploaded data to myBucket/myKey");
}
});
这篇关于当我尝试向 S3 存储桶 (Node.js) 发送内容时,AWS 缺少凭证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文