如何在AWS SDK v3 S3 ListObjectVersionsCommand中检查已删除的版本。

huangapple go评论60阅读模式
英文:

How to check for deleted versions in AWS SDK v3 S3 ListObjectVersionsCommand

问题

以下是您要翻译的代码部分:

const command = new ListObjectVersionsCommand({
  Bucket: s3Bucket,
  Prefix: fullPath
});

const response = await s3Client.send(command);

response 具有以下结构:

{
    "$metadata": {
        "httpStatusCode": number,
        "requestId": string,
        "extendedRequestId": string,
        "cfId": string,
        "attempts": number,
        "totalRetryDelay": number
    },
    "DeleteMarkers": [
        {
            "Owner": {
                "DisplayName": string,
                "ID": string
            },
            "Key": string,
            "VersionId": string,
            "IsLatest": boolean,
            "LastModified": string
        }
    ],
    "IsTruncated": boolean,
    "KeyMarker": string,
    "MaxKeys": number,
    "Name": string,
    "Prefix": string,
    "VersionIdMarker": string,
    "Versions": [
        {
            "ETag": string,
            "Size": number,
            "StorageClass": string,
            "Key": string,
            "VersionId": string,
            "IsLatest": boolean,
            "LastModified": string,
            "Owner": {
                "DisplayName": string,
                "ID": string
            }
        }
    ]
}

您的问题是,如何检查哪个版本已被删除?我看到 response.DeleteMarkers 但它似乎没有与 response.Versions 之间的关联。我已经搜索了一段时间,甚至向 ChatGPT 寻求帮助,但它只会产生虚构的答案并将它们呈现为事实,我从中得到的答案都是错误的,而我的搜索结果也没有给我提供答案。

response.DeleteMarkers.VersionIdresponse.Versions.VersionId 是不同的,彼此不相关,似乎它们是各个条目的 Id

当我从S3存储桶查看时,似乎 DeleteMarker 应该在每个版本中有引用。

但我收到的JSON响应不反映这一点。

示例响应:

{
  "$metadata": {
    "httpStatusCode": 200,
    "requestId": "5ZWDEPHH55T26MBM",
    "extendedRequestId": "Ww6lV9BFYu5ZJ4ySVg0FVvGTolvwiQfLkmkXfUJnHRdzLBqx0xyNyNgvvYPfEYOBcSvgXHp3u3c=",
    "cfId": "yKku_yzmm53yfJJqeLCZBA7uRRzmuTxjkZo3nw7Oy7vDANvgGbP6Vg==",
    "attempts": 1,
    "totalRetryDelay": 0
  },
  "DeleteMarkers": [
    {
      "Owner": [Object],
      "Key": "clients/647eddb692097dc08e54a33d/test.txt",
      "VersionId": "EFEHxShryx7An1wB316DhGIgLqV1pv8m",
      "IsLatest": false,
      "LastModified": "2023-06-16T02:01:17.000Z"
    },
    // 其他 DeleteMarkers
  ],
  "IsTruncated": false,
  "KeyMarker": "",
  "MaxKeys": 1000,
  "Name": "dev-bourkehood-hub-test-bucket",
  "Prefix": "clients/647eddb692097dc08e54a33d/test.txt",
  "VersionIdMarker": "",
  "Versions": [
    {
      "ETag": "\"098f6bcd4621d373cade4e832627b4f6\"",
      "Size": 4,
      "StorageClass": "STANDARD",
      "Key": "clients/647eddb692097dc08e54a33d/test.txt",
      "VersionId": "70zachRrDvFuT7Vv1hm6lpQZoLtK78Vp",
      "IsLatest": true,
      "LastModified": "2023-06-16T02:33:55.000Z",
      "Owner": [Object]
    },
    // 其他 Versions
  ]
}

希望这对您有所帮助。如果您有任何其他问题,请随时提出。

英文:

The following code retrieves versions of a specific object in s3 (using Prefix).

const command = new ListObjectVersionsCommand({
  Bucket: s3Bucket,
  Prefix: fullPath
});

const response = await s3Client.send(command);

response has the following shape:

{
    "$metadata": {
        "httpStatusCode": number,
        "requestId": string,
        "extendedRequestId": string,
        "cfId": string,
        "attempts": number,
        "totalRetryDelay": number
    },
    "DeleteMarkers": [
        {
            "Owner": {
                "DisplayName": string,
                "ID": string
            },
            "Key": string,
            "VersionId": string,
            "IsLatest": boolean,
            "LastModified": string
        }
    ],
    "IsTruncated": boolean,
    "KeyMarker": string,
    "MaxKeys": number,
    "Name": string,
    "Prefix": string,
    "VersionIdMarker": string,
    "Versions": [
        {
            "ETag": string,
            "Size": number,
            "StorageClass": string,
            "Key": string,
            "VersionId": string,
            "IsLatest": boolean,
            "LastModified": string,
            "Owner": {
                "DisplayName": string,
                "ID": string
            }
        }
    ]
}

My question is, how do I check which version has been deleted? I saw response.DeleteMarkers but it's pretty useless as it does not have any reference in or to response.Versions. I have been googling for a while now and even asked ChatGPT as well for help, but it just keeps on hallucinating answers and presenting them as facts, the answers I got from it are all wrong (https://chat.openai.com/share/5c1e8cfc-d8dd-45fa-a9e0-615ebf8119a6) and my search results hasn't presented me with an answer.

response.DeleteMarkers.VersionId and response.Versions.VersionId are different and not related to each other, seems like they are Ids of the individual entries.

When I look at it from the S3 Bucket, I can see that it seems like the DeleteMarker is supposed to have reference in each versions.

如何在AWS SDK v3 S3 ListObjectVersionsCommand中检查已删除的版本。

But the JSON response I get doesn't reflect this.

Example response:

{
'$metadata': {
httpStatusCode: 200,
requestId: '5ZWDEPHH55T26MBM',
extendedRequestId: 'Ww6lV9BFYu5ZJ4ySVg0FVvGTolvwiQfLkmkXfUJnHRdzLBqx0xyNyNgvvYPfEYOBcSvgXHp3u3c=',
cfId: 'yKku_yzmm53yfJJqeLCZBA7uRRzmuTxjkZo3nw7Oy7vDANvgGbP6Vg==',
attempts: 1,
totalRetryDelay: 0
},
DeleteMarkers: [
{
Owner: [Object],
Key: 'clients/647eddb692097dc08e54a33d/test.txt',
VersionId: 'EFEHxShryx7An1wB316DhGIgLqV1pv8m',
IsLatest: false,
LastModified: 2023-06-16T02:01:17.000Z
},
{
Owner: [Object],
Key: 'clients/647eddb692097dc08e54a33d/test.txt',
VersionId: 'MjuTh1iTW5mqTSjDX_kCtthHr0_crBUw',
IsLatest: false,
LastModified: 2023-06-16T01:46:45.000Z
},
{
Owner: [Object],
Key: 'clients/647eddb692097dc08e54a33d/test.txt',
VersionId: 'adY0h6KPkVlvpkUN_Qb7V4HT8ZFIdMsF',
IsLatest: false,
LastModified: 2023-06-16T00:58:51.000Z
},
{
Owner: [Object],
Key: 'clients/647eddb692097dc08e54a33d/test.txt',
VersionId: 'EXo0b3gRDiQoHKS7QcCT2ewIu4e9C0BK',
IsLatest: false,
LastModified: 2023-06-16T00:40:04.000Z
}
],
IsTruncated: false,
KeyMarker: '',
MaxKeys: 1000,
Name: 'dev-bourkehood-hub-test-bucket',
Prefix: 'clients/647eddb692097dc08e54a33d/test.txt',
VersionIdMarker: '',
Versions: [
{
ETag: '"098f6bcd4621d373cade4e832627b4f6"',
Size: 4,
StorageClass: 'STANDARD',
Key: 'clients/647eddb692097dc08e54a33d/test.txt',
VersionId: '70zachRrDvFuT7Vv1hm6lpQZoLtK78Vp',
IsLatest: true,
LastModified: 2023-06-16T02:33:55.000Z,
Owner: [Object]
},
{
ETag: '"098f6bcd4621d373cade4e832627b4f6"',
Size: 4,
StorageClass: 'STANDARD',
Key: 'clients/647eddb692097dc08e54a33d/test.txt',
VersionId: 'T6R5QDuElzyptmIDvdLSBwrFHd5Mvfv.',
IsLatest: false,
LastModified: 2023-06-16T02:33:35.000Z,
Owner: [Object]
},
{
ETag: '"098f6bcd4621d373cade4e832627b4f6"',
Size: 4,
StorageClass: 'STANDARD',
Key: 'clients/647eddb692097dc08e54a33d/test.txt',
VersionId: 'uHst7UpguHknpHRZEclsLi0LeFxZad4r',
IsLatest: false,
LastModified: 2023-06-16T02:24:02.000Z,
Owner: [Object]
},
{
ETag: '"098f6bcd4621d373cade4e832627b4f6"',
Size: 4,
StorageClass: 'STANDARD',
Key: 'clients/647eddb692097dc08e54a33d/test.txt',
VersionId: 'NE_zEN6oDC6mvpJVsrBnwJ.ZVzJbuRJ8',
IsLatest: false,
LastModified: 2023-06-16T02:23:45.000Z,
Owner: [Object]
},
{
ETag: '"098f6bcd4621d373cade4e832627b4f6"',
Size: 4,
StorageClass: 'STANDARD',
Key: 'clients/647eddb692097dc08e54a33d/test.txt',
VersionId: 'uwouMWFBqrLlT3cC_inY5w8UB0F07wzK',
IsLatest: false,
LastModified: 2023-06-16T02:02:17.000Z,
Owner: [Object]
},
{
ETag: '"098f6bcd4621d373cade4e832627b4f6"',
Size: 4,
StorageClass: 'STANDARD',
Key: 'clients/647eddb692097dc08e54a33d/test.txt',
VersionId: 'WVktjgHtAYPm60Csb_IuQWDGI305YJek',
IsLatest: false,
LastModified: 2023-06-16T02:01:43.000Z,
Owner: [Object]
},
{
ETag: '"098f6bcd4621d373cade4e832627b4f6"',
Size: 4,
StorageClass: 'STANDARD',
Key: 'clients/647eddb692097dc08e54a33d/test.txt',
VersionId: 'qT6vlzOqLTmq9tKtKSAbvfGdOz29BsJo',
IsLatest: false,
LastModified: 2023-06-16T02:01:30.000Z,
Owner: [Object]
},
{
ETag: '"098f6bcd4621d373cade4e832627b4f6"',
Size: 4,
StorageClass: 'STANDARD',
Key: 'clients/647eddb692097dc08e54a33d/test.txt',
VersionId: 'oHefQ6AnKcTUaxyCKMYzJszPb_8MGbYW',
IsLatest: false,
LastModified: 2023-06-16T01:50:33.000Z,
Owner: [Object]
},
{
ETag: '"098f6bcd4621d373cade4e832627b4f6"',
Size: 4,
StorageClass: 'STANDARD',
Key: 'clients/647eddb692097dc08e54a33d/test.txt',
VersionId: 'N3gvDTkIVa3C8JbPOyfMvvdGTSecZBsC',
IsLatest: false,
LastModified: 2023-06-16T01:48:38.000Z,
Owner: [Object]
},
{
ETag: '"098f6bcd4621d373cade4e832627b4f6"',
Size: 4,
StorageClass: 'STANDARD',
Key: 'clients/647eddb692097dc08e54a33d/test.txt',
VersionId: 'LPdfQ.gBc1f.jBixDYg.muRYRxnCHe1H',
IsLatest: false,
LastModified: 2023-06-16T01:47:18.000Z,
Owner: [Object]
},
{
ETag: '"38b0d2ff1c03df82aea67222983d337e"',
Size: 6,
StorageClass: 'STANDARD',
Key: 'clients/647eddb692097dc08e54a33d/test.txt',
VersionId: '_S1xv6r63Md6yOOZEX4pagUhWNwzsDWG',
IsLatest: false,
LastModified: 2023-06-16T01:19:13.000Z,
Owner: [Object]
},
{
ETag: '"098f6bcd4621d373cade4e832627b4f6"',
Size: 4,
StorageClass: 'STANDARD',
Key: 'clients/647eddb692097dc08e54a33d/test.txt',
VersionId: 'Ggy7wq8XnoZLsrtw.3Z1Rp7Q8I2Z_B7g',
IsLatest: false,
LastModified: 2023-06-16T01:19:03.000Z,
Owner: [Object]
},
{
ETag: '"38b0d2ff1c03df82aea67222983d337e"',
Size: 6,
StorageClass: 'STANDARD',
Key: 'clients/647eddb692097dc08e54a33d/test.txt',
VersionId: 'Y9RlaB9i0uq06.SWuQ5moXzB18YNvFNm',
IsLatest: false,
LastModified: 2023-06-16T00:59:48.000Z,
Owner: [Object]
},
{
ETag: '"098f6bcd4621d373cade4e832627b4f6"',
Size: 4,
StorageClass: 'STANDARD',
Key: 'clients/647eddb692097dc08e54a33d/test.txt',
VersionId: 'Sa4za24jIQVCZoSIqPTyRBMCMXlluWpw',
IsLatest: false,
LastModified: 2023-06-16T00:59:27.000Z,
Owner: [Object]
},
{
ETag: '"098f6bcd4621d373cade4e832627b4f6"',
Size: 4,
StorageClass: 'STANDARD',
Key: 'clients/647eddb692097dc08e54a33d/test.txt',
VersionId: '5MKHhqE9c.dXQNOX08Xe1HWAz9eFcocm',
IsLatest: false,
LastModified: 2023-06-16T00:55:45.000Z,
Owner: [Object]
},
{
ETag: '"38b0d2ff1c03df82aea67222983d337e"',
Size: 6,
StorageClass: 'STANDARD',
Key: 'clients/647eddb692097dc08e54a33d/test.txt',
VersionId: 'dCA6e.5VeDRpWvjxg4L1p3_SUaOEeuW5',
IsLatest: false,
LastModified: 2023-06-16T00:23:10.000Z,
Owner: [Object]
},
{
ETag: '"098f6bcd4621d373cade4e832627b4f6"',
Size: 4,
StorageClass: 'STANDARD',
Key: 'clients/647eddb692097dc08e54a33d/test.txt',
VersionId: '3ZaLnwr63vNpeVrzjP14AGM5LuW9c0og',
IsLatest: false,
LastModified: 2023-06-16T00:06:21.000Z,
Owner: [Object]
}
]
}

答案1

得分: 1

当特定版本的对象被删除时,它将从Amazon S3中移除,不会出现在任何列表中。

当在启用版本控制的S3存储桶中删除对象时,会添加一个删除标记作为“最新版本”。这使得对象看起来好像已被删除,但先前的版本仍然被保留。

如果对象的当前版本是一个删除标记,那么该对象不会出现在普通对象列表中,但会出现在 ListObjectVersions() 中。

英文:

When a specific Version of an object is deleted, it is removed from Amazon S3. It will not appear in any listing.

When an object is deleted in a version-enabled S3 bucket, a Delete Marker is added as the 'latest version'. This makes the object 'appear' as if it has been deleted, but previous versions have still been retained.

If the current version of an object is a Delete Marker, then the object will not appear in a normal listing of objects, but it will appear in ListObjectVersions().

huangapple
  • 本文由 发表于 2023年6月16日 10:37:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76486637.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定