AWS S3 Glacier Vault Deletion

April 6th 2020

AWS S3 Glacier provides a cost effective way to store large amounts of data in a cloud infrastructure that delivers 99.999999999% durability, and provide comprehensive security and compliance capabilities. Since S3 Glacier cost are low – up too $1 per terabyte per month – the retrieval for archived data is limited and throttled.

Standard retrievals typically complete between 3-5 hours, and work well for less time-sensitive needs like backup data, media editing, or long-term analytics. Bulk retrievals are the lowest-cost retrieval option, returning large amounts of data within 5-12 hours.

The AWS Developer Console does provide some high level access to your Glacier vaults but it doesn’t allow you to access the vaults “inventory” which are typically archives of data. One common issue is that when it comes to deleting a vault, the vault has to be empty and all archives have to first be deleted before you can delete a vault. Unfortunately, you can’t use the AWS developer console to manage or delete your archives so we need to turn to another method:

You cannot delete an archive using the Amazon S3 Glacier (S3 Glacier) management console. To delete an archive you must use the AWS Command Line Interface (CLI) or write code to make a delete request using either the REST API directly or the AWS SDK for Java and .NET wrapper libraries.

In this tutorial we will look at using the aws cli to get our glacier vault’s inventory by initiating a job of type inventory-retrieval, get the output of our job we initiated in JSON format, extract our archive ID’s from the JSON output file, and create a bash script to delete all the archives in our vault. Finally, we’re able to delete the vault once the inventory (archives) have been deleted.

Setting Up AWS CLI

The AWS CLI has good documentation and package installation scripts for the major operating systems. Navigate to and select the type of operating system you are installing the cli. Once you are done with the installation we can configure the aws cli. Before we can configure we will need to log on to our aws console and create a root access key ID and secret access key. You can login to your aws at and then navigate to and you can toggle “Access Keys” dropdown to see a list of your root access key ID and secret access keys. Once you have obtained your access key ID and secret you will want to also take note of the region that your glacier vault is located under. In your terminal you can type: aws configure and you will be prompt with the configuration options for your cli:

AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-west-2
Default output format [None]: json

You can fill in the credentials using your access key ID secret access key and the default region. You can double check the configuration by typing: aws glacier help to see the information and command options for the aws glacier service. Now that we have the aws cli configured we can move on to initiating a job to retrieve our inventory for our vault.

AWS Initiate Job Vault Inventory Retrieval

To keep cost low for storage S3 Glacier requires you to queue jobs that will be run at specific interval times (usually between 3 – 5 hours). To get a list of our archives on the vault we will initiate a job of type “inventory-retrieval” which will be queued up for us. We can initiate a job with the command:

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

For account id you can use a - for aws cli to use the default account that is associated with the credentials otherwise you can find your account id by logging in to the aws developer console and navigating to: You will also need the name of the vault that you want to delete. Once the job is initiated we can copy the jobId that is returned to us in our response object from the cli call. Now that we have aa job initiated we can check on the status of the job by using the command:

aws glacier describe-job --account-id - --vault-name my-vault --job-id zbxcm3Z_3z5UkoroF7SuZKrxgGoDc3RloGduS7Eg-RO47Yc6FxsdGBgf_Q2DK5Ejh18CnTS5XW4_XqlNHS61dsO4CnMW

Make sure you replace the --job-id with the jobId field that was returned in the initate-job call. You should see an output like this:

    "InventoryRetrievalParameters": {
        "Format": "JSON"
    "VaultARN": "arn:aws:glacier:us-west-2:0123456789012:vaults/my-vault",
    "Completed": false,
    "JobId": "zbxcm3Z_3z5UkoroF7SuZKrxgGoDc3RloGduS7Eg-RO47Yc6FxsdGBgf_Q2DK5Ejh18CnTS5XW4_XqlNHS61dsO4CnMW",
    "Action": "InventoryRetrieval",
    "CreationDate": "2019-07-17T20:23:41.616Z",
    "StatusCode": "InProgress"

If we wait for 3 – 5 hours we can run this command again to check the Completed field to see if it changed to true and the StatusCode is Succeeded. Once those field show that our job is completed we’re ready to use the aws glacier get-job-output to get the output file in JSON format for our inventory retrieval job:

aws glacier get-job-output --account-id - --vault-name my-vault --job-id zbxcm3Z_3z5UkoroF7SuZKrxgGoDc3RloGduS7Eg-RO47Yc6FxsdGBgf_Q2DK5Ejh18CnTS5XW4_XqlNHS61dsO4CnMW archives.json

We are calling the output file archives.json since we are getting the list of archives. You should now have a file that looks similar to:

         "ArchiveDescription":"multipart upload test",

You can see we have an key called "ArchiveList" which is an array of archives. If you had automated backups for your glacier vault your archive list will probably be in the thousands of archives. We are going to extract the values of "ArchiveList" into a separate file with an ArchiveId each on there separate line. To do this we’re going to use a utility called jq

The jq utility is included in all the major Linux distributions repositories, therefore installing it is very easy: we just need to use our favorite package manager. If we are using Debian, or a Debian-based distribution such as Ubuntu or Linux Mint, we can use apt.

You can find installation instructions by going to: and selecting your operating system. Once jq is installed navigate to the folder that you created your archives.json file in. We are going to extract all the ArchiveId fields into their own file by using the jq utility to create a new file called archiveIds.txt. In the command line type:

jq '.ArchiveList[] | .ArchiveId' archives.json > archiveIds.txt

We should now have a file archiveIds.txt that should look similar to:


We can now use this file to loop through all of the lines of the file using each line to make a call to aws to delete the archive using aws glacier delete-archive. Let’s use a bash script to loop through the lines in our file and initiate the call to aws to delete our archive. In the same folder that archiveIds.txt is in you can create file called



# If file exists
if [[ -f "$file" ]]
  while IFS= read -r line
    echo "Deleting Archive $line"
    echo "Count: $count"
    aws glacier delete-archive --account-id - --vault-name $vault --archive-id=$line 
  done < "$file"

We are storing the first argument $1 in a variable called vault which is our vault name and the second argument $2 the file that we are using to loop through – in our case archiveIds.txt. We are then making sure that the file exists and if so we are looping through the file using the Internal Field Separator (IFS) to read each line and storing the line as a variable accessible via $line. We are then using the command: aws glacier delete-archive --account-id - --vault-name $vault --archive-id=$line which will call the command we want to delete our inventory. We can now use this bash script by navigating to the folder archiveIds.txt is in and running:

bash my-vault $(pwd)/archiveIds.txt 

Make sure you are replacing my-vault with the name of your vault. Depending on how many archives you need to delete this command can take awhile to loop through all of the ArchiveId fields and you can monitor the output of the file and the count of how many archives were deleted in the terminal. Once the script is complete you will have to wait 3 – 5 hours for the inventory in the AWS Developer Console to update for your vault.

Deleting the AWS Glacier Vault

Once all of the archives for the vault are deleted and there is no more data on the vault you are able to delete your vault. You can do this through the AWS Developer Console by navigating to Amazon S3 Glacier Vaults in your console and selecting the vault you want to delete before clicking “Delete Vault”. You can also use the aws cli to delete the vault by running: aws glacier delete-vault --vault-name my-vault --account-id -

It is a lot of steps to take to delete a vault on AWS S3 Glacier but hopefully this tutorial helps walk you through the steps to remove the archives and delete the vault from your AWS account. Until next time, stay curious, stay creative!