'S3 bucket objects are not getting deleted by s3.deleteObject() method

I've used the s3.deleteObject() method to delete the uploaded file on AWS S3 bucket. But in response, I'm getting no error but still not deletion of that file. I thought it could be permission issue but, I'm not event getting permission error and this file is already uploaded by multerS3.

const aws = require('aws-sdk');

aws.config.update({
  accessKeyId: accessKeyId,
  secretAccessKey: secretAccessKey
});
const s3 = new aws.S3();

(async () => {
  let params = {
    Bucket: 'bucket',
    Key: 'https://bucket.s3.amazonaws.com/profiles/1648634140824-xyz.png'
  };

  console.log(`params ->> `, params);

  s3.deleteObject(params, function (error, data) {
    if (error) {
      console.log(`\nDeleteImageFromS3 error ->> ${error}`);
      return;
    } else {
      console.log('\ns3.deleteObject data ->> ', data);
      return;
    }
  });
})();

In response, I'm getting below log and file is still existing in S3 bucket

s3.deleteObject data ->>  { DeleteMarker: true,
  VersionId: 'DtD9ccuW2zl1ylWvQTrjJfk3yVa_Ze1A' }

Thank you advance



Solution 1:[1]

Please change the key part, you wont have have to define the domain of aws s3 (all these things are handled by aws-sdk only), just the file name present inside that bucket.

 let params = {
    Bucket: 'bucket',
    Key: 'profiles/1648634140824-xyz.png'
  };

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ashishssoni