Delete an Archive in S3 Glacier by Using the AWS CLI
You can delete archives in Amazon S3 Glacier by using the AWS Command Line Interface (AWS CLI).
(Prerequisite) Setting Up the AWS CLI
-
Download and configure the AWS CLI. For instructions, see the following topics in the AWS Command Line Interface User Guide:
-
Verify your AWS CLI setup by entering the following commands at the command prompt. These commands don't provide credentials explicitly, so the credentials of the default profile are used.
-
Try using the help command.
aws help -
To get a list of S3 Glacier vaults on the configured account, use the
list-vaultscommand. Replace123456789012with your AWS account ID.aws glacier list-vaults --account-id123456789012 -
To see the current configuration data for the AWS CLI, use the
aws configure listcommand.aws configure list
-
Example: Deleting an Archive by Using the AWS CLI
-
Use the
initiate-jobcommand to start an inventory retrieval job. For more information on theinitiate-jobcommand, see Initiate Job.aws glacier initiate-job --vault-nameawsexamplevault--account-id111122223333--job-parameters='{"Type": "inventory-retrieval"}'Expected output:
{ "location": "/111122223333/vaults/awsexamplevault/jobs/*** jobid ***", "jobId": "*** jobid ***" } -
Use the
describe-jobcommand to check the status of the previous retrieval job. For more information on thedescribe-jobcommand, see Describe Job.aws glacier describe-job --vault-nameawsexamplevault--account-id111122223333--job-id*** jobid ***Expected output:
{ "InventoryRetrievalParameters": { "Format": "JSON" }, "VaultARN": "*** vault arn ***", "Completed": false, "JobId": "*** jobid ***", "Action": "InventoryRetrieval", "CreationDate": "*** job creation date ***", "StatusCode": "InProgress" } -
Wait for the job to be completed.
You must wait until the job output is ready for you to download. If you set a notification configuration on the vault or specified an Amazon Simple Notification Service (Amazon SNS) topic when you initiated the job, S3 Glacier sends a message to the topic after it completes the job.
You can set notification configuration for specific events on the vault. For more information, see Configuring Vault Notifications in Amazon S3 Glacier. S3 Glacier sends a message to the specified Amazon SNS topic anytime the specific event occurs.
-
When the job is complete, use the
get-job-outputcommand to download the retrieval job to the fileoutput.json. For more information on theget-job-outputcommand, see Get Job Output.aws glacier get-job-output --vault-nameawsexamplevault--account-id111122223333--job-id*** jobid ***output.jsonThis command produces a file with the following fields.
{ "VaultARN":"arn:aws:glacier:region:111122223333:vaults/awsexamplevault", "InventoryDate":""*** job completion date ***"", "ArchiveList":[{ {"ArchiveId":""*** archiveid ***"", "ArchiveDescription":"*** archive description (if set) ***", "CreationDate":""*** archive creation date ***"", "Size":""*** archive size (in bytes) ***"", "SHA256TreeHash":"*** archive hash ***" }], "ArchiveId": 123456789 } -
Use the
delete-archivecommand to delete each archive from a vault until none remain.aws glacier delete-archive --vault-nameawsexamplevault--account-id111122223333--archive-id="*** archiveid ***"
For more information on the delete-archive command, see Delete Archive.