Newbie in AWS Glacier - how to connect to my storage and upload files there via PowerShell?

96 Views Asked by At

I'm a newbie with S3 and would like to know step by step how to connect, upload and read file(s) to my S3 Glacier storage via PowerShell? Link https://docs.aws.amazon.com/powershell/latest/reference/items/New-GLCVault.html looks very uninformative and convoluted regarding credentials to be used for connecting, and also has no samples to play with. Could anybody describe me step by step how to connect from my PowerShell console and do all the described steps for S3? AWSPowerShell.NetCore was installed on my Win machine, so cmdlets seem to be available. Thanks in advance!

1

There are 1 best solutions below

4
SerhiiH On

Updated.

To create a vault and upload files to AWS Glacier using PowerShell, you can follow these steps:

  • Configure AWS Tools: You need to set up your AWS credentials (access key ID, secret access key, region).

    Set-AWSCredential -AccessKey <your-access-key> -SecretKey <your-secret-key> -StoreAs <credential-name>
    Set-AWSCredential -ProfileName <credential-name>
    
  • Create a Vault: Use the New-GLCVault command to create a vault in Glacier. Replace vault-name with your desired vault name.

    New-GLCVault -VaultName <vault-name>
    
  • Upload Files to the Vault: Use the aws glacier upload-archive command to upload files to the vault. Replace vault-name with your vault name and file-path with the path to the file you want to upload.

    $filePath = "<file-path>"
    $folderPath = "<folder-path>"
    $vaultName = "<vault-name>" 
    Write-GLCArchive -VaultName $vaultName -FilePath $filePath -FolderPath $folderPath
    

    If you want to specify a description for the uploaded archive, you can use the -Description parameter:

    $archiveDescription = "Your description here"
    Write-GLCArchive -VaultName $vaultName -FilePath $filePath -FolderPath $folderPath -Description $archiveDescription
    
  • Initiate a Job: In order to start to read, its required to initiate job first. Use the Start-GlacierJob cmdlet to initiate a job in Glacier. You will need to specify the vault name, job type (ArchiveRetrieval or InventoryRetrieval), and any additional parameters required for the job type. Here's an example of initiating an archive retrieval job:

    $vaultName = "<vault-name>"
    $jobParameters = @{
        Type = "<job-type>"
        Description = "My inventory retrieval job"
    }
    Start-GlacierJob -VaultName $vaultName -JobParameters $jobParameters
    
  • Read Data from Glacier: Use the Get-GlacierJobOutput cmdlet to read data from Glacier. You will need the job ID of the retrieval job that you initiated to retrieve the data from Glacier. Replace <vault-name> with your vault name and <job-id> with your job ID:

    $vaultName = "<vault-name>"
    $jobId = "<job-id>"
    Get-GlacierJobOutput -VaultName $vaultName -JobID $jobId -FilePath "<your-local-path>"
    

    This cmdlet will download the output of the Glacier retrieval job to the specified file path on your local machine.

Please note that Glacier is a cold storage service, and retrieving data from Glacier can take several hours. It's designed for long-term storage of data that is infrequently accessed.