S3 Glacier examples using Tools for PowerShell - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

S3 Glacier examples using Tools for PowerShell

The following code examples show you how to perform actions and implement common scenarios by using the AWS Tools for PowerShell with S3 Glacier.

Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.

Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.

Topics

Actions

The following code example shows how to use Get-GLCJob.

Tools for PowerShell

Example 1: Returns details of the specified job. When the job completes successfully the Read-GCJobOutput cmdlet can be used to retrieve the contents of the job (an archive or inventory list) to the local file system.

Get-GLCJob -VaultName myvault -JobId "op1x...JSbthM"

Output:

Action : ArchiveRetrieval ArchiveId : o9O9j...X-TpIhQJw ArchiveSHA256TreeHash : 79f3ea754c02f58...dc57bf4395b ArchiveSizeInBytes : 38034480 Completed : False CompletionDate : 1/1/0001 12:00:00 AM CreationDate : 12/13/2018 11:00:14 AM InventoryRetrievalParameters : InventorySizeInBytes : 0 JobDescription : JobId : op1x...JSbthM JobOutputPath : OutputLocation : RetrievalByteRange : 0-38034479 SelectParameters : SHA256TreeHash : 79f3ea754c02f58...dc57bf4395b SNSTopic : StatusCode : InProgress StatusMessage : Tier : Standard VaultARN : arn:aws:glacier:us-west-2:012345678912:vaults/test
  • For API details, see DescribeJob in AWS Tools for PowerShell Cmdlet Reference.

The following code example shows how to use New-GLCVault.

Tools for PowerShell

Example 1: Creates a new vault for the user's account. As no value was supplied to the -AccountId parameter the cmdlets uses a default of "-" indicating the current account.

New-GLCVault -VaultName myvault

Output:

/01234567812/vaults/myvault
  • For API details, see CreateVault in AWS Tools for PowerShell Cmdlet Reference.

The following code example shows how to use Read-GLCJobOutput.

Tools for PowerShell

Example 1: Downloads the archive content that was scheduled for retrieval in the specified job and stores the contents into a file on disk. The download validates the checksum for you, if one is available. If desired the entire response including the checksum can be returned by specifying -Select '*'.

Read-GLCJobOutput -VaultName myvault -JobId "HSWjArc...Zq2XLiW" -FilePath "c:\temp\blue.bin"
  • For API details, see GetJobOutput in AWS Tools for PowerShell Cmdlet Reference.

The following code example shows how to use Start-GLCJob.

Tools for PowerShell

Example 1: Starts a job to retrieve an archive from the specified vault owned by the user. The status of the job can be checked using the Get-GLCJob cmdlet. When the job completes successfully the Read-GCJobOutput cmdlet can be used to retrieve the contents of the archive to the local file system.

Start-GLCJob -VaultName myvault -JobType "archive-retrieval" -JobDescription "archive retrieval" -ArchiveId "o9O9j...TX-TpIhQJw"

Output:

JobId JobOutputPath Location ----- ------------- -------- op1x...JSbthM /012345678912/vaults/test/jobs/op1xe...I4HqCHkSJSbthM
  • For API details, see InitiateJob in AWS Tools for PowerShell Cmdlet Reference.

The following code example shows how to use Write-GLCArchive.

Tools for PowerShell

Example 1: Uploads a single file to the specified vault, returning the archive ID and computed checksum.

Write-GLCArchive -VaultName myvault -FilePath c:\temp\blue.bin

Output:

FilePath ArchiveId Checksum -------- --------- -------- C:\temp\blue.bin o9O9jUUs...TTX-TpIhQJw 79f3e...f4395b

Example 2: Uploads the contents of a folder hierarchy to the specified vault in the user's account. For each file uploaded the cmdlet emits the filename, corresponding archive ID and the computed checksum of the archive.

Write-GLCArchive -VaultName myvault -FolderPath . -Recurse

Output:

FilePath ArchiveId Checksum -------- --------- -------- C:\temp\blue.bin o9O9jUUs...TTX-TpIhQJw 79f3e...f4395b C:\temp\green.bin qXAfOdSG...czo729UHXrw d50a1...9184b9 C:\temp\lum.bin 39aNifP3...q9nb8nZkFIg 28886...5c3e27 C:\temp\red.bin vp7E6rU_...Ejk_HhjAxKA e05f7...4e34f5 C:\temp\Folder1\file1.txt _eRINlip...5Sxy7dD2BaA d0d2a...c8a3ba C:\temp\Folder2\file2.iso -Ix3jlmu...iXiDh-XfOPA 7469e...3e86f1
  • For API details, see UploadArchive in AWS Tools for PowerShell Cmdlet Reference.