Skip to content

Instantly share code, notes, and snippets.

@tjukic
Created July 9, 2024 07:23
Show Gist options
  • Save tjukic/3206de41d9850c3218d8ceb54de2c0d4 to your computer and use it in GitHub Desktop.
Save tjukic/3206de41d9850c3218d8ceb54de2c0d4 to your computer and use it in GitHub Desktop.
Run an AWS S3 Glacier retrieval per file
# Set variables
$bucket = "your-bucket-name"
$s3Path = "your/s3/path/"
$retrievalDays = 1 # Number of days the restored object will be available
# Function to initiate Glacier retrieval for a file
function Start-GlacierRetrieval {
param (
[string]$Key
)
Write-Host "Initiating Glacier retrieval for: $Key"
aws s3api restore-object --bucket $bucket --key $Key --restore-request "{`"Days`":$retrievalDays,`"GlacierJobParameters`":{`"Tier`":`"Standard`"}}"
}
# List all objects in the S3 path recursively
$objects = aws s3api list-objects-v2 --bucket $bucket --prefix $s3Path --query "Contents[].Key" --output json | ConvertFrom-Json
# Iterate through each object and initiate Glacier retrieval
foreach ($object in $objects) {
Start-GlacierRetrieval -Key $object
}
Write-Host "Glacier retrieval initiated for all files in $s3Path"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment