简体   繁体   中英

How to permanently delete latest version of S3 Object using Nodejs

I have an S3 bucket with versioning enabled. Whenever i make a deleteObject call using the aws sdk for javascript it will mark the object with a delete marker . As specified in the documentation , for deleting s3 object permanently, the "VersionId" should be specified.
From S3 documentation for making the delete call:

var params = {
     Bucket: 'STRING_VALUE', /* required */
     Key: 'STRING_VALUE', /* required */
     BypassGovernanceRetention: true || false,
     MFA: 'STRING_VALUE',
     RequestPayer: requester,
     VersionId: 'STRING_VALUE'
};
s3.deleteObject(params, function(err, data) {
     i.f (err) console.log(err, err.stack); // an error occurred
     else     console.log(data);           // successful response
});

I want to (permanently)delete the latest version of the object. I know that, in order to do so:

  • The versions need to be fetched.
  • Call "deleteObject" for that version with the "VersionId".

The above approach requires 2 API calls (first for fetching the versions and second for deleting the object version) I have gone through several solutions and they had the same approach as specified above.
I'm trying to reduce the API calls to one.

  • Is there a way where i can specify a place holder for latest version in "VersionId" paramater of the request so that aws will resolve it to the latest version?
  • Is there any other way which would require one API call?

Nope. You'll need to make the two calls.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM