DEV Community

loading...

How to delete file from aws s3 bucket

Md. Abdul Halim Rafi
・1 min read
const s3 = new AWS.S3({
  accessKeyId: process.env.AWS_ID,
  secretAccessKey: process.env.AWS_SECRET,
});

const params = {
    Bucket: process.env.AWS_BUCKET_NAME,
    Key: `folder/subfolder/filename.fileExtension`
};

s3.deleteObject(params, (error, data) => {
  if (error) {
    res.status(500).send(error);
  }
  res.status(200).send("File has been deleted successfully");
});

Discussion (1)

Collapse
tezechi profile image
Tochukwu Ezechi

Hello Md. Abdul Halim Rafi
Can you show other AWS s3 object operations like update/edit object, upload object.
Thanks