Delete an Archive in S3 Glacier by Using the Amazon CLI - Amazon S3 Glacier
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

If you're new to archival storage in Amazon Simple Storage Service (Amazon S3), we recommend that you start by learning more about the S3 Glacier storage classes in Amazon S3, S3 Glacier Instant Retrieval, S3 Glacier Flexible Retrieval, and S3 Glacier Deep Archive. For more information, see S3 Glacier storage classes and Storage classes for archiving objects in the Amazon S3 User Guide.

Delete an Archive in S3 Glacier by Using the Amazon CLI

You can delete archives in Amazon S3 Glacier by using the Amazon Command Line Interface (Amazon CLI).

(Prerequisite) Setting Up the Amazon CLI

  1. Download and configure the Amazon CLI. For instructions, see the following topics in the Amazon Command Line Interface User Guide:

    Installing the Amazon Command Line Interface

    Configuring the Amazon Command Line Interface

  2. Verify your Amazon 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-vaults command. Replace 123456789012 with your Amazon Web Services account ID.

      aws glacier list-vaults --account-id 123456789012
    • To see the current configuration data for the Amazon CLI, use the aws configure list command.

      aws configure list

Example: Deleting an Archive by Using the Amazon CLI

  1. Use the initiate-job command to start an inventory retrieval job. For more information on the initiate-job command, see Initiate Job.

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

    Expected output:

    { "location": "/111122223333/vaults/awsexamplevault/jobs/*** jobid ***", "jobId": "*** jobid ***" }
  2. Use the describe-job command to check the status of the previous retrieval job. For more information on the describe-job command, see Describe Job.

    aws glacier describe-job --vault-name awsexamplevault --account-id 111122223333 --job-id *** jobid ***

    Expected output:

    { "InventoryRetrievalParameters": { "Format": "JSON" }, "VaultARN": "*** vault arn ***", "Completed": false, "JobId": "*** jobid ***", "Action": "InventoryRetrieval", "CreationDate": "*** job creation date ***", "StatusCode": "InProgress" }
  3. 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.

  4. When the job is complete, use the get-job-output command to download the retrieval job to the file output.json. For more information on the get-job-output command, see Get Job Output.

    aws glacier get-job-output --vault-name awsexamplevault --account-id 111122223333 --job-id *** jobid *** output.json

    This 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 }
  5. Use the delete-archive command to delete each archive from a vault until none remain.

    aws glacier delete-archive --vault-name awsexamplevault --account-id 111122223333 --archive-id="*** archiveid ***"

For more information on the delete-archive command, see Delete Archive.