There are more AWS SDK examples available in the AWS Doc SDK Examples
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-namemy-vault--upload-id19gaRezEXAMPLES6Ry5YYdqthHOC_kGRCT03L9yetr220UmPtBYKk-OssZtLqyFu7sY1_lR7vgFuJV6NtcV5zpsJThis 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-uploadcommand and can also be obtained by usingaws 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.
-
For API details, see AbortMultipartUpload
in AWS CLI Command Reference.
-
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-lockexample 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-nameMyVaultNameThis command produces no output.
For more information, see Abort Vault Lock (DELETE lock-policy) in the Amazon Glacier API Developer Guide.
-
For API details, see AbortVaultLock
in AWS CLI Command Reference.
-
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-namemy-vault--tagsid=1234,date=july2015Amazon 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 AddTagsToVault
in AWS CLI Command Reference.
-
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-size3145728--checksum9628195fcdbcbbe76cdde456d4646fa7de5f219fb39823836d81f0cc0e18aa67--upload-id19gaRezEXAMPLES6Ry5YYdqthHOC_kGRCT03L9yetr220UmPtBYKk-OssZtLqyFu7sY1_lR7vgFuJV6NtcV5zpsJ--account-id - --vault-namemy-vaultAmazon 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-uploadcommand and can also be obtained by usingaws 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.
-
For API details, see CompleteMultipartUpload
in AWS CLI Command Reference.
-
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-lockexample completes the in-progress locking progress for the specified vault and sets the lock state of the vault lock toLocked. You get the value for thelock-idparameter when you runinitiate-lock-process.aws glacier complete-vault-lock \ --account-id - \ --vault-nameMyVaultName\ --lock-id9QZgEXAMPLEPhvL6xEXAMPLEThis command produces no output.
For more information, see Complete Vault Lock (POST lockId) in the Amazon Glacier API Developer Guide.
-
For API details, see CompleteVaultLock
in AWS CLI Command Reference.
-
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-namemy-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-archiveexample removes the specified archive fromexample_vault.aws glacier delete-archive \ --account-id111122223333\ --vault-nameexample_vault\ --archive-idSc0u9ZP8yaWkmh-XGlIvAVprtLhaLCGnNwNl5I5x9HqPIkX5mjc0DrId3Ln-Gi_k2HzmlIDZUz117KSdVMdMXLuFWi9PJUitxWO73edQ43eTlMWkH0pd9zVSAuV_XXZBVhKhyGhJ7wThis 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-policyexample removes the access policy for the specified vault.aws glacier delete-vault-access-policy \ --account-id111122223333\ --vault-nameexample_vaultThis command produces no output.
-
For API details, see DeleteVaultAccessPolicy
in AWS CLI Command Reference.
-
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-notificationsexample removes notifications sent by Amazon Simple Notification Service (Amazon SNS) for the specified vault.aws glacier delete-vault-notifications \ --account-id111122223333\ --vault-nameexample_vaultThis command produces no output.
-
For API details, see DeleteVaultNotifications
in AWS CLI Command Reference.
-
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-namemy-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-namemy-vault--job-idzbxcm3Z_3z5UkoroF7SuZKrxgGoDc3RloGduS7Eg-RO47Yc6FxsdGBgf_Q2DK5Ejh18CnTS5XW4_XqlNHS61dsO4CnMWOutput:
{ "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-jobandaws 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-namemy-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.
-
For API details, see GetDataRetrievalPolicy
in AWS CLI Command Reference.
-
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-namemy-vault--job-idzbxcm3Z_3z5UkoroF7SuZKrxgGoDc3RloGduS7Eg-RO47Yc6FxsdGBgf_Q2DK5Ejh18CnTS5XW4_XqlNHS61dsO4CnMWoutput.jsonThe
job-idis available in the output ofaws 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-policyexample retrieves the access policy for the specified vault.aws glacier get-vault-access-policy \ --account-id111122223333\ --vault-nameexample_vaultOutput:
{ "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\"}]}" } }