Juned Ansari
Juned Ansari

Reputation: 5283

CredentialsError: Missing credentials in config in nodejs aws-sdk

I am trying to upload file in aws-s3 but it shows me some error like enter image description here

NodeCode:

const AWS = require('aws-sdk');
const uploadFile = async (file) => {

    const s3 = new AWS.S3({
        accessKeyId: "<AWSS3_AccessKey>",
        secretAccessKey: "<AWSS3_SecretKey>",
        region: "ap-south-1"
    });

    const params = {
        Bucket: "test123", // pass your bucket name
        Key: file.name, //filename
        Body: file.data, //data
    };
    s3.upload(params, function(s3Err, data) {
        if (s3Err) throw s3Err
        //console.log(`File uploaded successfully at ${data.Location}`)
    });
};

var files = [];
var fileKeys = Object.keys(req.files);

fileKeys.forEach(function(key) {
    var file = req.files[key];
    files.push(file.name);
    uploadFile(file);
});

Upvotes: 2

Views: 8936

Answers (1)

varnit
varnit

Reputation: 1897

your aws cli config file in not configured properly the location of config file is

at ~/.aws/config on Linux, macOS, or Unix, or at C:\Users\USERNAME.aws\config on Windows.

you need to setup this file before you use any sdk to call aws services i'm posting a link which will guide you how to setup aws cli in different operating systems

Setup AWS CLI

Upvotes: 2

Related Questions