0

I have a lambda function with the following policy

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": [
                "s3:ListBucket"
            ],
            "Resource": [
                "arn:aws:s3:::my-bucket"
            ],
            "Effect": "Allow"
        },
        {
            "Action": [
                "s3:GetObject",
                "s3:PutObject",
                "s3:DeleteObject"
            ],
            "Resource": [
                "arn:aws:s3:::my-bucket/*"
            ],
            "Effect": "Allow"
        }
    ]
}

I am calling the listObjectsV2 without problem but when I want to call the upload method I have ERROR AccessDenied: Access Denied

This is my code

const addImage = (name, image) => {
    name = `${Image.getPrefix()}/${name}.${crypto.randomBytes(3).toString('hex')}.${image.originalname.split('.').pop()}`;

    return s3.upload({
        Bucket: process.env.S3_BUCKET_IMAGE,
        ACL: 'public-read',
        Body: image.buffer,
        Key: name
    }).promise()
    .then(result => new Image(result))
}
1
  • Share a snippet of your lambda that's uploading. From the cli I can upload to a bucket with the permissions you're using.
    – kenlukas
    Dec 26 '19 at 18:48
0

I found a solution

Using lambda you have to add a policy on the bucket too

https://aws.amazon.com/fr/premiumsupport/knowledge-center/access-denied-lambda-s3-bucket/

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::AccountA:role/AccountARole"
            },
            "Action": [
                "s3:PutObject",
                "s3:PutObjectAcl"
            ],
            "Resource": [
                "arn:aws:s3:::AccountBBucketName/*"
            ]
        }
    ]
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.