ERROR IN NODE Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1

1k Views Asked by At

I'm using multer for image upload while uploading an image it's showing the error. I searched so much but can't able to find solution. Please suggest me some blog or documentation so that I can follow them to know about this stuff

  var aws = require("aws-sdk"),
      multerS3 = require("multer-s3");
    s3 = new aws.S3({
      accessKeyId: process.env.ACCESS_KEY_ID,
      accessSecretKey: process.env.ACCESS_SECRET_KEY,
      region:process.env.REGION,
      Bucket: process.env.AWS_BUCKET_NAME,
    });
    var upload = multer({
      storage: multerS3({
        
        s3: s3,
        bucket: "******",
        metadata: function (req, file, cb) {
          cb(null, { fieldName: file.fieldname });
        },
        key: function (req, file, cb) {
          const uniqueSuffix =
            "myfile" + Date.now() + "-" + Math.round(Math.random() * 1e9);
          cb(null, uniqueSuffix + file.originalname);
        },
      }),
    });

My bucket policy

    {
        "Version": "2012-10-17",
        "Id": "Policy****",
        "Statement": [
            {
                "Sid": "*****",
                "Effect": "Allow",
                "Principal": "*",
                "Action": "s3:GetObject",
                "Resource": [
                    "arn:aws:s3:::******/*",
                    "arn:aws:s3:::******"
                ]
            }
        ]
    }

    <?xml version="1.0" encoding="UTF-8"?>
    <CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>POST</AllowedMethod>
        <AllowedMethod>PUT</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <AllowedHeader>Authorization</AllowedHeader>
    </CORSRule>
    </CORSConfiguration>
0

There are 0 best solutions below