Skip to content

Instantly share code, notes, and snippets.

@eksiscloud
Created January 14, 2020 17:25
Show Gist options
  • Save eksiscloud/28ce84b914d3a37ca58dd67031f5786a to your computer and use it in GitHub Desktop.
Save eksiscloud/28ce84b914d3a37ca58dd67031f5786a to your computer and use it in GitHub Desktop.
How to delete AWS S3 Glacier vault
1. aws glacier initiate-job --job-parameters '{"Type": "inventory-retrieval"}' --vault-name YOUR_VAULT_NAME --account-id YOUR_ACCOUNT_ID --region YOUR_REGION
2. aws glacier list-jobs --vault-name YOUR_VAULT_NAME --region YOUR_REGION --account-id YOUR_ACCOUNT_ID
try again and again until you get "Completed": true, and "StatusCode": "Succeeded"
it can take several hours or days
3. aws glacier get-job-output --job-id YOUR_JOB_ID --vault-name YOUR_VAULT_NAME --region YOUR_REGION --account-id YOUR_ACCOUNT_ID ./output.json
copy job_id from the output of the second step
4. nano glacier.php
<?php
$file = './output.json' ;
$accountId = 'YOUR_ACCOUNT_ID' ;
$region = 'YOUR_REGION' ;
$vaultName = 'YOUR_VAULT_NAME' ;
$string = file_get_contents ( $file ) ;
$json = json_decode($string, true ) ;
foreach ( $json [ 'ArchiveList' ] as $jsonArchives )
{
echo 'Delete Archive: ' . $jsonArchives [ 'ArchiveId' ] . "\n" ;
exec ( 'aws glacier delete-archive --archive-id="' . $jsonArchives [ 'ArchiveId' ] . '" --vault-name ' . $vaultName . ' --account-id ' . $accountId . ' --region ' . $region , $output ) ;
echo $output ;
}
5. aws glacier delete-vault --vault-name YOUR_VAULT_NAME --account-id YOUR_ACCOUNT_ID --region YOUR_REGION
##Job done and the vault is deleted
@eksiscloud
Copy link
Author

Done for linking purposes.

The original is here: https://gist.github.com/Remiii/507f500b5c4e801e4ddc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment