简体   繁体   English

如何使用 Nodejs 永久删除最新版本的 S3 Object

[英]How to permanently delete latest version of S3 Object using Nodejs

I have an S3 bucket with versioning enabled.我有一个启用了版本控制的 S3 存储桶。 Whenever i make a deleteObject call using the aws sdk for javascript it will mark the object with a delete marker .每当我使用 aws sdk for javascript 进行deleteObject调用时,它都会用删除标记标记object。 As specified in the documentation , for deleting s3 object permanently, the "VersionId" should be specified.文档中所述,要永久删除 s3 object,应指定“VersionId”。
From S3 documentation for making the delete call:从 S3 文档中进行删除调用:

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.我想(永久)删除最新版本的 object。 I know that, in order to do so:我知道,为了这样做:

  • The versions need to be fetched.需要获取版本。
  • Call "deleteObject" for that version with the "VersionId".使用“VersionId”为该版本调用“deleteObject”。

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.上述方法需要 2 个 API 调用(第一个用于获取版本,第二个用于删除 object 版本)我已经经历了几种解决方案,它们具有与上述相同的方法。
I'm trying to reduce the API calls to one.我正在尝试将 API 调用减少到一个。

  • 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?有没有一种方法可以让我在请求的“VersionId”参数中为最新版本指定一个占位符,以便 aws 将其解析为最新版本?
  • Is there any other way which would require one API call?有没有其他方法需要一个 API 调用?

Nope.没有。 You'll need to make the two calls.您需要拨打这两个电话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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