使用 AWS CLI 列出 Glacier 中的文件

List files in Glacier with AWS CLI

我需要删除存储在 Glacier Vault 中的文件,但 AWS CLI 需要对象 ID,而我无法执行正确的命令来获取此 ID。

有人知道使用 AWS CLI 查看文件 ID 的命令吗?

使用 aws glacier initiate-job 获取 Amazon Glacier 保管库的清单。

来自Amazon Glacier documentation

The following command initiates a job to get an inventory of the vault my-vault:

aws glacier initiate-job --account-id - --vault-name my-vault --job-parameters '{"Type": "inventory-retrieval"}'

作业完成后,您可以调用 aws glacier get-job-output。清单将包括 archive-id(文件在 Glacier 中称为 archives)。

这是 get-job-output documentation:

的示例输出
{"VaultARN":"arn:aws:glacier:us-west-2:0123456789012:vaults/my-vault","InventoryDate":"2015-04-07T00:26:18Z","ArchiveList":[{"ArchiveId":"kKB7ymWJVpPSwhGP6ycSOAekp9ZYe_--zM_mw6k76ZFGEIWQX-ybtRDvc2VkPSDtfKmQrj0IRQLSGsNuDp-AJVlu2ccmDSyDUmZwKbwbpAdGATGDiB3hHO0bjbGehXTcApVud_wyDw","ArchiveDescription":"multipart upload test","CreationDate":"2015-04-06T22:24:34Z","Size":3145728,"SHA256TreeHash":"9628195fcdbcbbe76cdde932d4646fa7de5f219fb39823836d81f0cc0e18aa67"}]}

没关系

aws glacier initiate-job --account-id - --vault-name my-vault --job-parameters "{ \"Type\": \"inventory-retrieval\" }"

一个问题是如何引用字符串取决于您使用的是 Linux 还是 Mac 或者 Powershell 还是 Windows。参见 AWS doc on quoting strings

对于 Windows 命令提示符,这有效:

aws glacier initiate-job --account-id 123456789012  --vault-name myvault --job-parameters "{\"Type\": \"inventory-retrieval\"}"

对于 PowerShell,在 JSON 周围使用单引号,但仍然转义双引号。使用 Linux 和 Mac 你不需要转义双引号。