当我尝试向S3 Bucket(Node.js)发送内容时,AWS缺少凭据

44 amazon-s3 amazon-web-services node.js

喜!

我从昨天起就遇到了这个问题,而我找不到解决方案的麻烦.

我正在尝试将某些东西发送到我的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' } } }
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

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

    s3.putObject(params, function(err) {
        if(err) {
            console.log(err);
        }
        else {
            console.log("Succes");
        }
});
Run Code Online (Sandbox Code Playgroud)

凭证是正确的.有谁知道会是什么?我正在搜索,但我找不到任何解决方案.


我的凭据(假):

{
    "accessKeyId": "BLALBLALBLALLBLALB",
    "secretAccessKey": "BLABLALBLALBLALBLLALBLALLBLALB",
    "region": "sa-east-1",
    "apiVersions": {
      "s3": "2006-03-01",
      "ses": "2010-12-01"
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑:

求助,所有代码:

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");
    }
});
Run Code Online (Sandbox Code Playgroud)

新错误:

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 }
Run Code Online (Sandbox Code Playgroud)

xSh*_*ase 57

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

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");
    }
});
Run Code Online (Sandbox Code Playgroud)

这里资源很好

  • 我仍然使用正确的密钥得到此错误.还有其他想法吗? (4认同)
  • 链接坏了. (4认同)

小智 54

我有同样的问题,直到我颠倒了两行:

var s3 = new AWS.S3();
AWS.config.loadFromPath('./AwsConfig.json'); 
Run Code Online (Sandbox Code Playgroud)

对此:

AWS.config.loadFromPath('./AwsConfig.json'); 
var s3 = new AWS.S3();
Run Code Online (Sandbox Code Playgroud)

  • 这是正确的解决方案,可以避免对凭据进行硬编码。 (2认同)
  • 为什么这样做?...因为在创建变量之前未加载凭据。 (2认同)

小智 6

我遇到了同样的错误.但我发现了这个问题.我使用了错误的环境变量名称.从NodeJS到S3,我需要使用以下变量名称:

process.env.AWS_ACCESS_KEY_ID = 'XXXXXXXXXXXXXXXXXXX';
process.env.AWS_SECRET_ACCESS_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXX';
process.env.AWS_REGION = 'us-east-1';
Run Code Online (Sandbox Code Playgroud)

一旦我更正了变量名称,它就运行正常.问候,Dipankar


Tim*_*ula 6

尝试将我的aws配置文件中的用户从特定用户更改为[default].

$nano .aws/credentials

[default]
aws_access_key_id = xyz
aws_secret_access_key = xyz
Run Code Online (Sandbox Code Playgroud)

如果您没有此文件,请创建它并获取密钥或从aws iam用户密钥生成新密钥.