AmazonS3Exception: Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied;

38 Views Asked by At

com.amazonaws.services.s3.model.AmazonS3Exception: Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied;

I want to delete the file from the s3 bucket using sprint boot api. I think the api is working fine. I must be making some mistake, not sure. I am trying to do this action as a root user.

This is my code to delete the file from S3. Key is the name of the file. public void deleteImage(String key) {

try {
    getS3Object.deleteObject(bucketName, key);
} catch (AmazonServiceException e) {
    throw new CommonException(HttpStatus.INTERNAL_SERVER_ERROR, "Failed to delete file from     S3");
   }
}

I have set the S3 bucket policy as "Action": [ "s3:PutObject", "s3:GetObject", "s3:DeleteObject" ],

I tried by enabling ACL and also bucket versioning. Please help me solve this.

0

There are 0 best solutions below