AWS Missing credentials when i try send something to my S3 Bucket (Node.js)

匿名 (未验证) 提交于 2019-12-03 02:45:02

问题:

Hei!

I'm having this issue since yesterday, and I'm having trouble for find a solution.

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' } } } 

And this is my code:

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.


My credentials(fake):

{     "accessKeyId": "BLALBLALBLALLBLALB",     "secretAccessKey": "BLABLALBLALBLALBLLALBLALLBLALB",     "region": "sa-east-1",     "apiVersions": {       "s3": "2006-03-01",       "ses": "2010-12-01"     } } 

EDIT:

For help, all the code:

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 } 

回答1:

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

Good resource here



回答2:

I had the same problem until I reversed the two lines:

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

to this:

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


回答3:

Try changing the user in my aws config file from a specific user to [default].

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

If you do not have this file, create it and get your keys or generate new one from aws iam user keys.



回答4:

I was having the same error. But I found the issue. I was using wrong Environment variable name. From NodeJS to S3, I need to use the following variable names:

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

Once I corrected the variable names, it just ran fine. regards, Dipankar



回答5:

I tried above option and even that did not work, so I created new config object and this below code worked

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


回答6:

I had a similar issue when trying to load the config file from anywhere other than the root directory.

I was able to load the json file natively in node, then just pass the object that was parsed to AWS.config.update()

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


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!