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