I thought it would be good to share with others facing the incovenient process of deleting AWS Glacier Vaults - it was always something that kept me paying AWS for file archives I no longer needed for years! Now I finally decided to eliminate this waste.
I've written my own because I couldn't find a convenient one to use, this script needs only an account id, aws region and vault name to do its job for you (after you've followed the pre-requisites).
I've borrowed a lot from a previous gist, mentioned in the acknowledgements (including a number of comments from others that used it) but decided to build something more end-to-end and remove any manual steps so I could start it and leave it alone. Hope that's useful to you too!
- I've run this on Mac and Linux (AWS) - I ended up running it on an EC2 instance as it can be a very long running process.
- Install jq https://stedolan.github.io/jq/download/
- Install the AWS CLI v2 https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html
- Create an IAM that has full access to AWS Glacier resources (
AmazonGlacierFullAccess
policy) - Copy the IAM's Access Key ID and Secret Access Key for your cli configuration.
- Run
aws configure
and provide your IAM's Access Key ID and Secret Access Key and default output format to JSON (region in this case is not so important as I've decided to have it as a parameter on the script itself).
- Copy the attached file named:
delete-aws-glacier-vault-archives.sh
- Make it executable by running
$ chmod 744 ./delete-aws-glacier-vault-archives.sh
This script take three parameters to run: AWS Account ID
, AWS Region
for the Glacier Vault in Question and the Vault Name
you want to delete archives from.
Based on comments from the gist mentioned in my early acknowledgments, a good way to run it is to keep it running in background and make it log to a file so you can check on progress which can be achieved running the command below:
$ nohup ./delete-aws-glacier-vault-archives.sh AWS_ACCOUNT_ID AWS_REGION AWS_GLACIER_VAULT_NAME > delete_AWS_ACCOUNT_ID_AWS_REGION_AWS_GLACIER_VAULT_NAME.log 2>&1 &
Please note that you should replace the AWS_ACCOUNT_ID
, AWS_REGION
and AWS_GLACIER_VAULT_NAME
on the script and log file name to be able to monitor and run multiple process in parallel in case you need to delete multiple vaults.
Hope it works out for you as it did for me :)
- It will try and avoid creating unecessary
inventory-retrieve
tasks, so it creates a file to store the job information against a given vault. - It will create files for the job output (which contains the JSON returned from Glacier containing all archives on the vault).
- It will create an input file containing only the archive ids extracted from the previous JSON file.
- Logs will give you a sense of where you are and will contain each archive id deleted.
Even after you delete all your archives they will still show as if nothing has happened in the AWS Glacier console as the information there is only computed daily by AWS. You will only be able to delete the Vault in the console after AWS refreshes its information and show as an empty vault... Annoying but nothing I can do about it.
- Vincent Meijer gist at https://gist.github.com/veuncent/ac21ae8131f24d3971a621fac0d95be5
- https://gist.github.com/johandebeurs for commenting on the previous version on differences between Mac and Linux regarding number of processing units for parallelism - I've incorporated the feedback.
- https://gist.github.com/kellyatkinson for feedback on how to improve status messages (adding timestamps on pauses). Incorporated the feedback.
@dmabamboo, many thanks!
the only issues I had is caused by AWS, though I will mention them:
aws glacier get-job-output ...
produced an empty file(*). The timing was not an issue, I've tried many hours later with the same result. After rerun, with newinventory retrieved
job - all was good. Maybe it's because I've tried it on a recently created vault?inventory retrieved
job for glacier to understand that now the vault is empty.export AWS_PROFILE=<My_AWS_Profile>
(*) first inventory file just makes no sense: