1

I'm trying to upload a file to S3 using multer-s3, but got AccessDenied Error. Here I configure aws service:

const s3 = new aws.S3({
  secretAccessKey: process.env.AWS_ACCESS_KEY,
  accessKeyId: process.env.AWS_KEY_ID,
  region: process.env.AWS_REGION,
});

const upload = multer({
  storage: multerS3({
    s3,
    bucket: 'my-bucket-name',
    dirname: '/images',
    acl: 'public-read',
    metadata: function (req, file, cb) {
      cb(null, { fieldName: file.fieldname });
    },
    key: function (req, file, cb) {
      cb(null, Date.now().toString());
    },
  }),
});

Even if I defined this policy for my User:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "s3:*",
            "Resource": "*"
        }
    ]
}

I'm still getting the same error.

loonskai
  • 90
  • 1
  • 2
  • 15
  • You can use the `Policy Generator` tool to create the policy: https://awspolicygen.s3.amazonaws.com/policygen.html and also make sure that your `IAM` profile has the required access (`AmazonS3FullAccess`). – Nikhil Dec 26 '18 at 13:09

0 Answers0