Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

How do you fix unable to locate credentials you can configure credentials by running AWS configure?

An "Unable to locate credentials" error indicates that Amazon S3 can't find the credentials to authenticate AWS API calls. To resolve this issue, make sure that your AWS credentials are correctly configured in the AWS CLI.


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

Good resource here


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

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


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.