View a markdown version of this page

Amazon Glacier examples using AWS CLI - AWS SDK Code Examples

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

Amazon Glacier examples using AWS CLI

The following code examples show you how to perform actions and implement common scenarios by using the AWS Command Line Interface with Amazon 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 abort-multipart-upload.

AWS CLI

The following command deletes an in-progress multipart upload to a vault named my-vault:

aws glacier abort-multipart-upload --account-id - --vault-name my-vault --upload-id 19gaRezEXAMPLES6Ry5YYdqthHOC_kGRCT03L9yetr220UmPtBYKk-OssZtLqyFu7sY1_lR7vgFuJV6NtcV5zpsJ

This command does not produce any output. Amazon Glacier requires an account ID argument when performing operations, but you can use a hyphen to specify the in-use account. The upload ID is returned by the aws glacier initiate-multipart-upload command and can also be obtained by using aws glacier list-multipart-uploads.

For more information on multipart uploads to Amazon Glacier using the AWS CLI, see Using Amazon Glacier in the AWS CLI User Guide.

The following code example shows how to use abort-vault-lock.

AWS CLI

To abort an in-progress vault lock process

The following abort-vault-lock example deletes a vault lock policy from the specified vault and resets the lock state of the vault lock to unlocked.

aws glacier abort-vault-lock \ --account-id - \ --vault-name MyVaultName

This command produces no output.

For more information, see Abort Vault Lock (DELETE lock-policy) in the Amazon Glacier API Developer Guide.

The following code example shows how to use add-tags-to-vault.

AWS CLI

The following command adds two tags to a vault named my-vault:

aws glacier add-tags-to-vault --account-id - --vault-name my-vault --tags id=1234,date=july2015

Amazon Glacier requires an account ID argument when performing operations, but you can use a hyphen to specify the in-use account.

The following code example shows how to use complete-multipart-upload.

AWS CLI

The following command completes multipart upload for a 3 MiB archive:

aws glacier complete-multipart-upload --archive-size 3145728 --checksum 9628195fcdbcbbe76cdde456d4646fa7de5f219fb39823836d81f0cc0e18aa67 --upload-id 19gaRezEXAMPLES6Ry5YYdqthHOC_kGRCT03L9yetr220UmPtBYKk-OssZtLqyFu7sY1_lR7vgFuJV6NtcV5zpsJ --account-id - --vault-name my-vault

Amazon Glacier requires an account ID argument when performing operations, but you can use a hyphen to specify the in-use account.

The upload ID is returned by the aws glacier initiate-multipart-upload command and can also be obtained by using aws glacier list-multipart-uploads. The checksum parameter takes a SHA-256 tree hash of the archive in hexadecimal.

For more information on multipart uploads to Amazon Glacier using the AWS CLI, including instructions on calculating a tree hash, see Using Amazon Glacier in the AWS CLI User Guide.

The following code example shows how to use complete-vault-lock.

AWS CLI

To complete an in-progress vault lock process

The following complete-vault-lock example completes the in-progress locking progress for the specified vault and sets the lock state of the vault lock to Locked. You get the value for the lock-id parameter when you run initiate-lock-process.

aws glacier complete-vault-lock \ --account-id - \ --vault-name MyVaultName \ --lock-id 9QZgEXAMPLEPhvL6xEXAMPLE

This command produces no output.

For more information, see Complete Vault Lock (POST lockId) in the Amazon Glacier API Developer Guide.

The following code example shows how to use create-vault.

AWS CLI

The following command creates a new vault named my-vault:

aws glacier create-vault --vault-name my-vault --account-id -

Amazon Glacier requires an account ID argument when performing operations, but you can use a hyphen to specify the in-use account.

  • For API details, see CreateVault in AWS CLI Command Reference.

The following code example shows how to use delete-archive.

AWS CLI

To delete an archive from a vault

The following delete-archive example removes the specified archive from example_vault.

aws glacier delete-archive \ --account-id 111122223333 \ --vault-name example_vault \ --archive-id Sc0u9ZP8yaWkmh-XGlIvAVprtLhaLCGnNwNl5I5x9HqPIkX5mjc0DrId3Ln-Gi_k2HzmlIDZUz117KSdVMdMXLuFWi9PJUitxWO73edQ43eTlMWkH0pd9zVSAuV_XXZBVhKhyGhJ7w

This command produces no output.

  • For API details, see DeleteArchive in AWS CLI Command Reference.

The following code example shows how to use delete-vault-access-policy.

AWS CLI

To remove the access policy of a vault

The following delete-vault-access-policy example removes the access policy for the specified vault.

aws glacier delete-vault-access-policy \ --account-id 111122223333 \ --vault-name example_vault

This command produces no output.

The following code example shows how to use delete-vault-notifications.

AWS CLI

To remove the SNS notifications for a vault

The following delete-vault-notifications example removes notifications sent by Amazon Simple Notification Service (Amazon SNS) for the specified vault.

aws glacier delete-vault-notifications \ --account-id 111122223333 \ --vault-name example_vault

This command produces no output.

The following code example shows how to use delete-vault.

AWS CLI

The following command deletes a vault named my-vault:

aws glacier delete-vault --vault-name my-vault --account-id -

This command does not produce any output. Amazon Glacier requires an account ID argument when performing operations, but you can use a hyphen to specify the in-use account.

  • For API details, see DeleteVault in AWS CLI Command Reference.

The following code example shows how to use describe-job.

AWS CLI

The following command retrieves information about an inventory retrieval job on a vault named my-vault:

aws glacier describe-job --account-id - --vault-name my-vault --job-id zbxcm3Z_3z5UkoroF7SuZKrxgGoDc3RloGduS7Eg-RO47Yc6FxsdGBgf_Q2DK5Ejh18CnTS5XW4_XqlNHS61dsO4CnMW

Output:

{ "InventoryRetrievalParameters": { "Format": "JSON" }, "VaultARN": "arn:aws:glacier:us-west-2:0123456789012:vaults/my-vault", "Completed": false, "JobId": "zbxcm3Z_3z5UkoroF7SuZKrxgGoDc3RloGduS7Eg-RO47Yc6FxsdGBgf_Q2DK5Ejh18CnTS5XW4_XqlNHS61dsO4CnMW", "Action": "InventoryRetrieval", "CreationDate": "2015-07-17T20:23:41.616Z", "StatusCode": "InProgress" }

The job ID can be found in the output of aws glacier initiate-job and aws glacier list-jobs. Amazon Glacier requires an account ID argument when performing operations, but you can use a hyphen to specify the in-use account.

  • For API details, see DescribeJob in AWS CLI Command Reference.

The following code example shows how to use describe-vault.

AWS CLI

The following command retrieves data about a vault named my-vault:

aws glacier describe-vault --vault-name my-vault --account-id -

Amazon Glacier requires an account ID argument when performing operations, but you can use a hyphen to specify the in-use account.

  • For API details, see DescribeVault in AWS CLI Command Reference.

The following code example shows how to use get-data-retrieval-policy.

AWS CLI

The following command gets the data retrieval policy for the in-use account:

aws glacier get-data-retrieval-policy --account-id -

Output:

{ "Policy": { "Rules": [ { "BytesPerHour": 10737418240, "Strategy": "BytesPerHour" } ] } }

Amazon Glacier requires an account ID argument when performing operations, but you can use a hyphen to specify the in-use account.

The following code example shows how to use get-job-output.

AWS CLI

The following command saves the output from a vault inventory job to a file in the current directory named output.json:

aws glacier get-job-output --account-id - --vault-name my-vault --job-id zbxcm3Z_3z5UkoroF7SuZKrxgGoDc3RloGduS7Eg-RO47Yc6FxsdGBgf_Q2DK5Ejh18CnTS5XW4_XqlNHS61dsO4CnMW output.json

The job-id is available in the output of aws glacier list-jobs. Note that the output file name is a positional argument that is not prefixed by an option name. Amazon Glacier requires an account ID argument when performing operations, but you can use a hyphen to specify the in-use account.

Output:

{ "status": 200, "acceptRanges": "bytes", "contentType": "application/json" }

output.json:

{"VaultARN":"arn:aws:glacier:us-west-2:0123456789012:vaults/my-vault","InventoryDate":"2015-04-07T00:26:18Z","ArchiveList":[{"ArchiveId":"kKB7ymWJVpPSwhGP6ycSOAekp9ZYe_--zM_mw6k76ZFGEIWQX-ybtRDvc2VkPSDtfKmQrj0IRQLSGsNuDp-AJVlu2ccmDSyDUmZwKbwbpAdGATGDiB3hHO0bjbGehXTcApVud_wyDw","ArchiveDescription":"multipart upload test","CreationDate":"2015-04-06T22:24:34Z","Size":3145728,"SHA256TreeHash":"9628195fcdbcbbe76cdde932d4646fa7de5f219fb39823836d81f0cc0e18aa67"}]}
  • For API details, see GetJobOutput in AWS CLI Command Reference.

The following code example shows how to use get-vault-access-policy.

AWS CLI

To retrieve the access policy of a vault

The following get-vault-access-policy example retrieves the access policy for the specified vault.

aws glacier get-vault-access-policy \ --account-id 111122223333 \ --vault-name example_vault

Output:

{ "policy": { "Policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"arn:aws:iam::444455556666:root\"},\"Action\":\"glacier:ListJobs\",\"Resource\":\"arn:aws:glacier:us-east-1:111122223333:vaults/example_vault\"},{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"arn:aws:iam::444455556666:root\"},\"Action\":\"glacier:UploadArchive\",\"Resource\":\"arn:aws:glacier:us-east-1:111122223333:vaults/example_vault\"}]}" } }