58

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 }
peterh
  • 11,875
  • 18
  • 85
  • 108
  • can you add your config.json file (hide the real credentials)? – xShirase Oct 09 '14 at 17:12
  • One interesting thing, I'm using sns to send me an email when things are sent to my bucket (my backup). He is sending me the same error. How he can access the sns if the credentials are wrong? –  Oct 09 '14 at 17:16
  • may i know ,what comes in 'file'?(Key: file)..whether 'tmp/filename' or our defined filepath?Is it possible to directly upload our files to aws s3 instead getting uploaded initially to our tmp folder and getting transferred to aws s3??? – Jagadeesh Jun 27 '17 at 09:39

7 Answers7

83

Try hardcoding your params and see if you get the error again :

AWS.config.update({
    accessKeyId: "YOURKEY",
    secretAccessKey: "YOURSECRET"
}); 

//for simplicity. In prod, use loadConfigFromFile, or env variables, or if logged in using 

var s3 = new AWS.S3({ region: "sa-east-1" }); //region can be set in here

var params = {
    Bucket: 'makersquest',
    Key: 'mykey.txt',
    Body: "HelloWorld"
};

s3.putObject(params, function (err, res) {
    if (err) {
        console.log("Error uploading data: ", err);
    } else {
        console.log("Successfully uploaded data to myBucket/myKey");
    }
});

Good resource here

DesignMonkeyJim
  • 1,875
  • 1
  • 10
  • 23
xShirase
  • 11,975
  • 4
  • 53
  • 85
  • 4
    I still get this error using the correct keys. Any other ideas? – mylord Jul 15 '15 at 12:39
  • 1
    For me it says XMLHttpRequest cannot load https://mybucketnamehere.s3.amazonaws.com/mykey.txt. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://mypage_on_localhost' is therefore not allowed access. The response had HTTP status code 403. I set CORS to allow this domain. Any ideas? – trainoasis Aug 10 '16 at 07:12
  • 4
    The link is broken. – Aanchal1103 May 22 '17 at 04:50
  • I had this same issue, i resolved this using my accesskey and secret access key like described here. thanks a lot. – Oswaldo Zapata Sep 15 '17 at 16:36
  • @xShirase Awesome man. Was facing issue for 3 hours. This helped me a lot. Thank you very much :) – Mahesh Gaikwad Jan 30 '19 at 12:46
  • This solution worked for me too. What I did was removing region setting – Sanjana Ekanayake May 12 '22 at 13:54
  • Please note `sessionToken` may also be required in addition to the `accessKeyId` and `secretAccessKey`. The field has `@deprecated` mark but it worked for me. – Konstantin Oct 02 '22 at 14:42
61

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();
Hugh McKee
  • 611
  • 5
  • 2
12

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

Dipankar Biswas
  • 141
  • 1
  • 3
  • Thanks. This worked for me. Any idea why this env variable name matters ? Ideally, we should be specifying any env variable name and while doing aws update only json key should matter. – Ramachandran Mani Oct 11 '21 at 01:16
12

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.

Tim Siwula
  • 966
  • 11
  • 15
0

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";
Gopal Shukla
  • 157
  • 1
  • 2
  • 10
0

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);
0

This resolved my issue .

  1. Used the sample code from the Cognito Console and added it to the of the document.

  2. Enabled Unauthenticated access on the identity pool.

Most important

  1. Fixed the Trust Relationship policy in the unauth role so the Cognito Service could assume the role.

  2. Do not hard code credential in the file .

Sudarshan kumar
  • 1,503
  • 4
  • 36
  • 83