AWS尝试将消息发送给我的S3 Bucket(Node.js)

喜!

我从昨天开始就遇到这个问题,而且我很难find一个解决scheme。

我试图发送一些东西到我的S3桶,但是当我尝试时,这个消息出现在我的控制台:

{ [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"); } }); 

凭据是正确的。 有谁知道可以是什么? 我正在寻找,但我找不到解决scheme。


我的凭据(假):

 { "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"); } }); 

新的错误:

 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 } 

尝试硬编码你的参数,看看你是否再次得到错误:

 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. }); 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"); } }); 

这里有很好的资源

我有同样的问题,直到我扭转了两条线:

 var s3 = new AWS.S3(); AWS.config.loadFromPath('./AwsConfig.json'); 

对此:

 AWS.config.loadFromPath('./AwsConfig.json'); var s3 = new AWS.S3(); 

尝试将用户从我的awsconfiguration文件中从特定用户更改为[默认]。

 $nano .aws/credentials [default] aws_access_key_id = xyz aws_secret_access_key = xyz 

如果你没有这个文件,创build它并获取你的密钥或从aws iam用户密钥生成新的。

你的问题只是你以错误的顺序调用这两行:

 var s3 = new AWS.S3(); AWS.config.loadFromPath('./AwsConfig.json'); 

你应该打电话

 var s3 = new AWS.S3(); 

加载您的凭据后

我有同样的错误。 但是我发现这个问题。 我正在使用错误的环境variables名称。 从NodeJS到S3,我需要使用下面的variables名称:

 process.env.AWS_ACCESS_KEY_ID = 'XXXXXXXXXXXXXXXXXXX'; process.env.AWS_SECRET_ACCESS_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXX'; process.env.AWS_REGION = 'us-east-1'; 

一旦我更正了variables名称,它运行的很好。 问候,Dipankar

我试过上面的选项,甚至没有工作,所以我创build了新的configuration对象,这下面的代码工作

  AWS.config = new AWS.Config(); AWS.config.accessKeyId = "AccessKey"; AWS.config.secretAccessKey = "SecretAccessKey"; 

当试图从根目录以外的任何地方加载configuration文件时,我遇到了类似的问题。

我能够在节点中本地加载json文件,然后将分析的对象传递给AWS.config.update()

 import AWS from 'aws-sdk' import config from '../aws.json' AWS.config.update(config);