Skip to content

Instantly share code, notes, and snippets.

@codingmatty
Last active January 16, 2022 15:21
Show Gist options
  • Save codingmatty/435d98dea7f91c92ba469450e957d0cd to your computer and use it in GitHub Desktop.
Save codingmatty/435d98dea7f91c92ba469450e957d0cd to your computer and use it in GitHub Desktop.
AWS Glacier Vault Prepare for Deletion

The files contained in this gist are based on the AWS Instructions on preparing an S3 Glacier Vault for deletion.

There are some important details left out though.

Summary

A Glacier Vault consists of multiple "archives". You can not delete a vault until all archives are deleted. This is a manual process and can take multiple hours of waiting for AWS to finish tasks.

Steps

To delete a vault, follow these steps:

  1. Install and Configure AWS CLI
    • Run aws configure to provide Access Key and Secret Key to a user with Full Access to S3 Glacier
  2. Hydrate Glacier Vault
    • This is asynchronous and can take hours, but you will not need to keep your terminal open.
  3. Fetch results of Vault hydration to JSON file
  4. Delete archives
    • This could take some time depending on how many archives are in the vault.
    • Important: Once you make the call to delete the archives, they won't actually be deleted yet. This could take another few hours to actually clear the archives before allowing you to delete the vault.
  5. Delete vault via AWS Console
## This file is not meant to be run
## It's just a list of commands to use
# Command variables that will be reused
AWS_GLACIER_VAULT_NAME=
AWS_ACCOUNT_ID=
AWS_REGION=
# Hydrate vault
aws glacier initiate-job --vault-name $AWS_GLACIER_VAULT_NAME --account-id $AWS_ACCOUNT_ID --job-parameters '{"Type": "inventory-retrieval"}'
# Get results of hydration
# Next steps need to wait until completed flag is true
aws glacier list-jobs --vault-name $AWS_GLACIER_VAULT_NAME --account-id $AWS_ACCOUNT_ID --region $AWS_REGION
# Set $GLACIER_HYDRATION_JOB_ID to `.JobList[0].JobId` from the above output
# This will save results to archives.json
aws glacier get-job-output --vault-name $AWS_GLACIER_VAULT_NAME --account-id $AWS_ACCOUNT_ID --job-id $GLACIER_HYDRATION_JOB_ID archives.json
#!/bin/sh
# After running all of the commands above, this file can be run to automatically call delete-archive on all archives output in archives.json
cat archives.json | jq -c '.ArchiveList[] | .ArchiveId' | while read line; do
echo "Deleting Archive $line"
aws glacier delete-archive --vault-name $AWS_GLACIER_VAULT_NAME --account-id $AWS_ACCOUNT_ID --region $AWS_REGION --archive-id $line
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment