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
-
To abort a multipart upload
The following
abort-multipart-uploadexample deletes an in-progress multipart upload to a vault namedmy-vault.aws glacier abort-multipart-upload \ --account-id - \ --vault-namemy-vault\ --upload-id19gaRezEXAMPLES6Ry5YYdqthHOC_kGRCT03L9yetr220UmPtBYKk-OssZtLqyFu7sY1_lR7vgFuJV6NtcV5zpsJThis command produces no 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 in the AWS CLI User Guide.
For more information, see Uploading Large Archives in Parts (Multipart Upload) in the Amazon Glacier Developer 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
-
To add tags to a vault
The following
add-tags-to-vaultexample adds two tags to a vault namedmy-vault.aws glacier add-tags-to-vault \ --account-id - \ --vault-namemy-vault\ --tagsid=1234,date=july2015This command produces no output.
Amazon Glacier requires an account ID argument when performing operations, but you can use a hyphen to specify the in-use account.
For more information, see Tagging Amazon Glacier Resources in the Amazon Glacier Developer Guide.
-
For API details, see AddTagsToVault
in AWS CLI Command Reference.
-
The following code example shows how to use complete-multipart-upload.
- AWS CLI
-
To complete a multipart upload
The following
complete-multipart-uploadexample 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-vaultOutput:
{ "location": "/123456789012/vaults/my-vault/archives/kKB7ymWJVpPSwhGP6ycSOAekp9ZYe_--zM_mw6k76ZFGEIWQX-ybtRDvc2VkPSDtfKmQrj0IRQLSGsNuDp-AJVlu2ccmDSyDUmZwKbwbpAdGATGDiB3hHO0bjbGehXTcApVud_wyDw", "checksum": "9628195fcdbcbbe76cdde456d4646fa7de5f219fb39823836d81f0cc0e18aa67", "archiveId": "kKB7ymWJVpPSwhGP6ycSOAekp9ZYe_--zM_mw6k76ZFGEIWQX-ybtRDvc2VkPSDtfKmQrj0IRQLSGsNuDp-AJVlu2ccmDSyDUmZwKbwbpAdGATGDiB3hHO0bjbGehXTcApVud_wyDw" }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. 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 in the AWS CLI User Guide.
For more information, see Uploading Large Archives in Parts (Multipart Upload) in the Amazon Glacier Developer 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
-
To create a vault
The following
create-vaultexample creates a new vault namedmy-vault.aws glacier create-vault \ --vault-namemy-vault\--account-id -Output:
{ "location": "/123456789012/vaults/my-vault" }Amazon Glacier requires an account ID argument when performing operations, but you can use a hyphen to specify the in-use account.
For more information, see Creating a Vault in Amazon Glacier Using the AWS Command Line Interface in the Amazon Glacier Developer Guide.
-
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-id123456789012\ --vault-nameexample_vault\ --archive-idSc0u9ZP8yaWkmh-XGlIvAVprtLhaLCGnNwNl5I5x9HqPIkX5mjc0DrId3Ln-Gi_k2HzmlIDZUz117KSdVMdMXLuFWi9PJUitxWO73edQ43eTlMWkH0pd9zVSAuV_XXZBVhKhyGhJ7wThis command produces no output.
For more information, see Deleting an Archive in Amazon Glacier in the Amazon Glacier Developer Guide.
-
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-id123456789012\ --vault-nameexample_vaultThis command produces no output.
For more information, see Vault Access Policies in the Amazon Glacier Developer Guide.
-
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-id123456789012\ --vault-nameexample_vaultThis command produces no output.
For more information, see Configuring Vault Notifications in Amazon Glacier in the Amazon Glacier Developer Guide.
-
For API details, see DeleteVaultNotifications
in AWS CLI Command Reference.
-
The following code example shows how to use delete-vault.
- AWS CLI
-
To delete a vault
The following
delete-vaultexample deletes a vault namedmy-vault.aws glacier delete-vault \ --vault-namemy-vault\--account-id -This command produces no output. Amazon Glacier requires an account ID argument when performing operations, but you can use a hyphen to specify the in-use account.
For more information, see Deleting a Vault in Amazon Glacier Using the AWS Command Line Interface in the Amazon Glacier Developer Guide.
-
For API details, see DeleteVault
in AWS CLI Command Reference.
-
The following code example shows how to use describe-job.
- AWS CLI
-
To describe a job
The following
describe-jobexample retrieves information about an inventory retrieval job on a vault namedmy-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 more information, see Downloading a Vault Inventory in Amazon Glacier in the Amazon Glacier Developer Guide.
-
For API details, see DescribeJob
in AWS CLI Command Reference.
-
The following code example shows how to use describe-vault.
- AWS CLI
-
To describe a vault
The following
describe-vaultexample retrieves data about a vault namedmy-vault.aws glacier describe-vault \ --vault-namemy-vault\--account-id -Output:
{ "VaultARN": "arn:aws:glacier:us-west-2:123456789012:vaults/my-vault", "VaultName": "my-vault", "CreationDate": "2015-07-17T19:22:31.123Z", "LastInventoryDate": "2015-07-18T03:41:12.456Z", "NumberOfArchives": 1, "SizeInBytes": 3178496 }Amazon Glacier requires an account ID argument when performing operations, but you can use a hyphen to specify the in-use account.
For more information, see Retrieving Vault Metadata in Amazon Glacier Using the AWS Command Line Interface in the Amazon Glacier Developer Guide.
-
For API details, see DescribeVault
in AWS CLI Command Reference.
-
The following code example shows how to use get-data-retrieval-policy.
- AWS CLI
-
To get the data retrieval policy for an account
The following
get-data-retrieval-policyexample 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 more information, see Amazon Glacier Data Retrieval Policies in the Amazon Glacier Developer Guide.
-
For API details, see GetDataRetrievalPolicy
in AWS CLI Command Reference.
-
The following code example shows how to use get-job-output.
- AWS CLI
-
To get the output of a job
The following
get-job-outputexample saves the output from a vault inventory job to a file in the current directory namedoutput.json.aws glacier get-job-outputoutput.json\--account-id - \ --vault-namemy-vault\ --job-idzbxcm3Z_3z5UkoroF7SuZKrxgGoDc3RloGduS7Eg-RO47Yc6FxsdGBgf_Q2DK5Ejh18CnTS5XW4_XqlNHS61dsO4CnMWThe
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 more information, see Downloading a Vault Inventory in Amazon Glacier in the Amazon Glacier Developer Guide.
-
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-id123456789111\ --vault-nameexample_vaultOutput:
{ "policy": { "Policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"arn:aws:iam::123456789222:root\"},\"Action\":\"glacier:ListJobs\",\"Resource\":\"arn:aws:glacier:us-west-2:123456789111:vaults/example_vault\"},{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"arn:aws:iam::123456789222:root\"},\"Action\":\"glacier:UploadArchive\",\"Resource\":\"arn:aws:glacier:us-west-2:123456789111:vaults/example_vault\"}]}" } }For more information, see Vault Access Policies in the Amazon Glacier Developer Guide.
-
For API details, see GetVaultAccessPolicy
in AWS CLI Command Reference.
-
The following code example shows how to use get-vault-lock.
- AWS CLI
-
To get the details of a vault lock
The following
get-vault-lockexample retrieved the details about the lock for the specified vault.aws glacier get-vault-lock \ --account-id - \ --vault-nameMyVaultNameOutput:
{ "Policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"Define-vault-lock\",\"Effect\":\"Deny\",\"Principal\":{\"AWS\":\"arn:aws:iam::123456789012:root\"},\"Action\":\"glacier:DeleteArchive\",\"Resource\":\"arn:aws:glacier:us-west-2:99999999999:vaults/MyVaultName\",\"Condition\":{\"NumericLessThanEquals\":{\"glacier:ArchiveAgeinDays\":\"365\"}}}]}", "State": "Locked", "CreationDate": "2019-07-29T22:25:28.640Z" }For more information, see Get Vault Lock (GET lock-policy) in the Amazon Glacier API Developer Guide.
-
For API details, see GetVaultLock
in AWS CLI Command Reference.
-
The following code example shows how to use get-vault-notifications.
- AWS CLI
-
To get the notification configuration for a vault
The following
get-vault-notificationsexample gets a description of the notification configuration for a vault namedmy-vault.aws glacier get-vault-notifications \ --account-id - \ --vault-namemy-vaultOutput:
{ "vaultNotificationConfig": { "Events": [ "InventoryRetrievalCompleted", "ArchiveRetrievalCompleted" ], "SNSTopic": "arn:aws:sns:us-west-2:0123456789012:my-vault" } }If no notifications have been configured for the vault, an error is returned. Amazon Glacier requires an account ID argument when performing operations, but you can use a hyphen to specify the in-use account.
For more information, see Configuring Vault Notifications in Amazon Glacier in the Amazon Glacier Developer Guide.
-
For API details, see GetVaultNotifications
in AWS CLI Command Reference.
-
The following code example shows how to use initiate-job.
- AWS CLI
-
To start an inventory retrieval job
The following
initiate-jobexample initiates a job to get an inventory of the vaultmy-vault.aws glacier initiate-job \ --account-id - \ --vault-namemy-vault\ --job-parameters '{"Type": "inventory-retrieval"}'Output:
{ "location": "/0123456789012/vaults/my-vault/jobs/zbxcm3Z_3z5UkoroF7SuZKrxgGoDc3RloGduS7Eg-RO47Yc6FxsdGBgf_Q2DK5Ejh18CnTS5XW4_XqlNHS61dsO4CnMW", "jobId": "zbxcm3Z_3z5UkoroF7SuZKrxgGoDc3RloGduS7Eg-RO47Yc6FxsdGBgf_Q2DK5Ejh18CnTS5XW4_XqlNHS61dsO4CnMW" }Amazon Glacier requires an account ID argument when performing operations, but you can use a hyphen to specify the in-use account.
For more information, see Downloading a Vault Inventory in Amazon Glacier in the Amazon Glacier Developer Guide.
The following
initiate-jobexample initiates a job to retrieve an archive from the vaultmy-vault.aws glacier initiate-job \ --account-id - \ --vault-namemy-vault\ --job-parametersfile://job-archive-retrieval.jsonjob-archive-retrieval.jsonis a JSON file in the local folder that specifies the type of job, archive ID, and some optional parameters.Contents of
job-archive-retrieval.json:{ "Type": "archive-retrieval", "ArchiveId": "kKB7ymWJVpPSwhGP6ycSOAekp9ZYe_--zM_mw6k76ZFGEIWQX-ybtRDvc2VkPSDtfKmQrj0IRQLSGsNuDp-AJVlu2ccmDSyDUmZwKbwbpAdGATGDiB3hHO0bjbGehXTcApVud_wyDw", "Description": "Retrieve archive on 2015-07-17", "SNSTopic": "arn:aws:sns:us-west-2:0123456789012:my-topic" }Archive IDs are available in the output of
aws glacier upload-archiveandaws glacier get-job-output.Output:
{ "location": "/123456789012/vaults/mwunderl/jobs/l7IL5-EkXyEY9Ws95fClzIbk2O5uLYaFdAYOi-azsX_Z8V6NH4yERHzars8wTKYQMX6nBDI9cMNHzyZJO59-8N9aHWav", "jobId": "l7IL5-EkXy2O5uLYaFdAYOiEY9Ws95fClzIbk-azsX_Z8V6NH4yERHzars8wTKYQMX6nBDI9cMNHzyZJO59-8N9aHWav" }For more information, see Retrieving Amazon Glacier Archives in the Amazon Glacier Developer Guide.
-
For API details, see InitiateJob
in AWS CLI Command Reference.
-
The following code example shows how to use initiate-multipart-upload.
- AWS CLI
-
To start a multipart upload
The following
initiate-multipart-uploadexample initiates a multipart upload to a vault namedmy-vaultwith a part size of 1 MiB (1024 x 1024 bytes) per file.aws glacier initiate-multipart-upload \ --account-id - \ --part-size1048576\ --vault-namemy-vault\ --archive-description"multipart upload test"Output:
{ "location": "/123456789012/vaults/my-vault/multipart-uploads/19gaRezEXAMPLES6Ry5YYdqthHOC_kGRCT03L9yetr220UmPtBYKk-OssZtLqyFu7sY1_lR7vgFuJV6NtcV5zpsJ", "uploadId": "19gaRezEXAMPLES6Ry5YYdqthHOC_kGRCT03L9yetr220UmPtBYKk-OssZtLqyFu7sY1_lR7vgFuJV6NtcV5zpsJ" }The archive description parameter is optional. Amazon Glacier requires an account ID argument when performing operations, but you can use a hyphen to specify the in-use account.
This command outputs an upload ID when successful. Use the upload ID when uploading each part of your archive with
aws glacier upload-multipart-part. For more information on multipart uploads to Amazon Glacier using the AWS CLI, see Using Amazon Glacier in the AWS CLI in the AWS CLI User Guide.-
For API details, see InitiateMultipartUpload
in AWS CLI Command Reference.
-
The following code example shows how to use initiate-vault-lock.
- AWS CLI
-
To initiate the vault locking process
The following
initiate-vault-lockexample installs a vault lock policy on the specified vault and sets the lock state of the vault lock toInProgress. You must complete the process by callingcomplete-vault-lockwithin 24 hours to set the state of the vault lock toLocked.aws glacier initiate-vault-lock \ --account-id - \ --vault-nameMyVaultName\ --policyfile://vault_lock_policy.jsonContents of
vault_lock_policy.json:{"Policy":"{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"Define-vault-lock\",\"Effect\":\"Deny\",\"Principal\":{\"AWS\":\"arn:aws:iam::123456789012:root\"},\"Action\":\"glacier:DeleteArchive\",\"Resource\":\"arn:aws:glacier:us-west-2:123456789012:vaults/examplevault\",\"Condition\":{\"NumericLessThanEquals\":{\"glacier:ArchiveAgeinDays\":\"365\"}}}]}"}Output:
{ "lockId": "9QZgEXAMPLEPhvL6xEXAMPLE" }The output is the vault lock ID that you can use to complete the vault lock process.
For more information, see Initiate Vault Lock (POST lock-policy) in the Amazon Glacier API Developer Guide.
-
For API details, see InitiateVaultLock
in AWS CLI Command Reference.
-
The following code example shows how to use list-jobs.
- AWS CLI
-
To list the jobs for a vault
The following
list-jobsexample lists in-progress and recently completed jobs for a vault namedmy-vault.aws glacier list-jobs \ --account-id - \ --vault-namemy-vaultOutput:
{ "JobList": [ { "VaultARN": "arn:aws:glacier:us-west-2:0123456789012:vaults/my-vault", "RetrievalByteRange": "0-3145727", "SNSTopic": "arn:aws:sns:us-west-2:0123456789012:my-vault", "Completed": false, "SHA256TreeHash": "9628195fcdbcbbe76cdde932d4646fa7de5f219fb39823836d81f0cc0e18aa67", "JobId": "l7IL5-EkXyEY9Ws95fClzIbk2O5uLYaFdAYOi-azsX_Z8V6NH4yERHzars8wTKYQMX6nBDI9cMNHzyZJO59-8N9aHWav", "ArchiveId": "kKB7ymWJVpPSwhGP6ycSOAekp9ZYe_--zM_mw6k76ZFGEIWQX-ybtRDvc2VkPSDtfKmQrj0IRQLSGsNuDp-AJVlu2ccmDSyDUmZwKbwbpAdGATGDiB3hHO0bjbGehXTcApVud_wyDw", "JobDescription": "Retrieve archive on 2015-07-17", "ArchiveSizeInBytes": 3145728, "Action": "ArchiveRetrieval", "ArchiveSHA256TreeHash": "9628195fcdbcbbe76cdde932d4646fa7de5f219fb39823836d81f0cc0e18aa67", "CreationDate": "2015-07-17T21:16:13.840Z", "StatusCode": "InProgress" }, { "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" } ] }Amazon Glacier requires an account ID argument when performing operations, but you can use a hyphen to specify the in-use account.
For more information, see Retrieving Amazon Glacier Archives in the Amazon Glacier Developer Guide.
-
For API details, see ListJobs
in AWS CLI Command Reference.
-
The following code example shows how to use list-multipart-uploads.
- AWS CLI
-
To list the in-progress multipart uploads for a vault
The following
list-multipart-uploadsexample shows all of the in-progress multipart uploads for a vault namedmy-vault.aws glacier list-multipart-uploads \ --account-id - \ --vault-namemy-vaultOutput:
{ "UploadsList": [ { "MultipartUploadId": "19gaRezEXAMPLES6Ry5YYdqthHOC_kGRCT03L9yetr220UmPtBYKk-OssZtLqyFu7sY1_lR7vgFuJV6NtcV5zpsJ", "VaultARN": "arn:aws:glacier:us-west-2:123456789012:vaults/my-vault", "ArchiveDescription": "multipart upload test", "PartSizeInBytes": 1048576, "CreationDate": "2015-07-18T00:05:23.830Z" } ] }Amazon Glacier requires an account ID argument when performing operations, but you can use a hyphen to specify the in-use account.
For more information on multipart uploads to Amazon Glacier using the AWS CLI, see Using Amazon Glacier in the AWS CLI in the AWS CLI User Guide.
-
For API details, see ListMultipartUploads
in AWS CLI Command Reference.
-
The following code example shows how to use list-parts.
- AWS CLI
-
To list the uploaded parts of a multipart upload
The following
list-partsexample lists the uploaded parts for a multipart upload to a vault namedmy-vault.aws glacier list-parts \ --account-id - \ --vault-namemy-vault\ --upload-id"SYZi7qnL-YGqGwAm8Kn3BLP2ElNCvnB-5961R09CSaPmPwkYGHOqeN_nX3-Vhnd2yF0KfB5FkmbnBU9GubbdrCs8ut-D"Output:
{ "MultipartUploadId": "SYZi7qnL-YGqGwAm8Kn3BLP2ElNCvnB-5961R09CSaPmPwkYGHOqeN_nX3-Vhnd2yF0KfB5FkmbnBU9GubbdrCs8ut-D", "Parts": [ { "RangeInBytes": "0-1048575", "SHA256TreeHash": "e1f2a7cd6e047350f69b9f8cfa60fa606fe2f02802097a9a026360a7edc1f553" }, { "RangeInBytes": "1048576-2097151", "SHA256TreeHash": "43cf3061fb95796aed99a11a6aa3cd8f839eed15e655ab0a597126210c36aee6" } ], "VaultARN": "arn:aws:glacier:us-west-2:0123456789012:vaults/my-vault", "CreationDate": "2015-07-18T00:05:23.830Z", "PartSizeInBytes": 1048576 }Amazon Glacier requires an account ID argument when performing operations, but you can use a hyphen to specify the in-use account.
For more information on multipart uploads to Amazon Glacier using the AWS CLI, see Using Amazon Glacier in the AWS CLI in the AWS CLI User Guide.
-
For API details, see ListParts
in AWS CLI Command Reference.
-
The following code example shows how to use list-provisioned-capacity.
- AWS CLI
-
To retrieve the provisioned capacity units
The following
list-provisioned-capacityexample retrieves details for any provisioned capacity units for the specified account.aws glacier list-provisioned-capacity \ --account-id123456789012Output:
{ "ProvisionedCapacityList": [ { "CapacityId": "HpASAuvfRFiVDbOjMfEIcr8K", "ExpirationDate": "2020-03-18T19:59:24.000Z", "StartDate": "2020-02-18T19:59:24.912Z" } ] }For more information, see Retrieving Amazon Glacier Archives in the Amazon Glacier Developer Guide.
-
For API details, see ListProvisionedCapacity
in AWS CLI Command Reference.
-
The following code example shows how to use list-tags-for-vault.
- AWS CLI
-
To list the tags for a vault
The following
list-tags-for-vaultexample lists the tags applied to a vault namedmy-vault.aws glacier list-tags-for-vault \ --account-id - \ --vault-namemy-vaultOutput:
{ "Tags": { "date": "july2015", "id": "1234" } }Amazon Glacier requires an account ID argument when performing operations, but you can use a hyphen to specify the in-use account.
For more information, see Tagging Amazon Glacier Resources in the Amazon Glacier Developer Guide.
-
For API details, see ListTagsForVault
in AWS CLI Command Reference.
-
The following code example shows how to use list-vaults.
- AWS CLI
-
To list the vaults
The following
list-vaultsexample lists the vaults in the default account and region.aws glacier list-vaults \ --account-id -Output:
{ "VaultList": [ { "SizeInBytes": 3178496, "VaultARN": "arn:aws:glacier:us-west-2:0123456789012:vaults/my-vault", "LastInventoryDate": "2015-04-07T00:26:19.028Z", "VaultName": "my-vault", "NumberOfArchives": 1, "CreationDate": "2015-04-06T21:23:45.708Z" } ] }Amazon Glacier requires an account ID argument when performing operations, but you can use a hyphen to specify the in-use account.
For more information, see Retrieving Vault Metadata in Amazon Glacier in the Amazon Glacier Developer Guide.
-
For API details, see ListVaults
in AWS CLI Command Reference.
-
The following code example shows how to use purchase-provisioned-capacity.
- AWS CLI
-
To purchase a provisioned capacity unit
The following
purchase-provisioned-capacityexample purchases a provisioned capacity unit.aws glacier purchase-provisioned-capacity \ --account-id123456789012Output:
{ "capacityId": "HpASAuvfRFiVDbOjMfEIcr8K" }For more information, see Retrieving Amazon Glacier Archives in the Amazon Glacier Developer Guide.
-
For API details, see PurchaseProvisionedCapacity
in AWS CLI Command Reference.
-
The following code example shows how to use remove-tags-from-vault.
- AWS CLI
-
To remove a tag from a vault
The following
remove-tags-from-vaultexample removes a tag with the keydatefrom a vault namedmy-vault.aws glacier remove-tags-from-vault \ --account-id - \ --vault-namemy-vault\ --tag-keysdateThis command produces no output.
Amazon Glacier requires an account ID argument when performing operations, but you can use a hyphen to specify the in-use account.
For more information, see Tagging Amazon Glacier Resources in the Amazon Glacier Developer Guide.
-
For API details, see RemoveTagsFromVault
in AWS CLI Command Reference.
-
The following code example shows how to use set-data-retrieval-policy.
- AWS CLI
-
To set the data retrieval policy for an account
The following
set-data-retrieval-policyexample configures a data retrieval policy for the in-use account.aws glacier set-data-retrieval-policy \ --account-id - \ --policyfile://data-retrieval-policy.jsonThis command produces no output.
data-retrieval-policy.jsonis a JSON file in the current folder that specifies a data retrieval policy.Contents of
data-retrieval-policy.json:{ "Rules": [ { "Strategy": "BytesPerHour", "BytesPerHour": 10737418240 } ] }Amazon Glacier requires an account ID argument when performing operations, but you can use a hyphen to specify the in-use account.
The following
set-data-retrieval-policyexample sets the data retrieval policy toFreeTierusing inline JSON.aws glacier set-data-retrieval-policy \ --account-id - \ --policy '{"Rules":[{"Strategy":"FreeTier"}]}'For more information, see Amazon Glacier Data Retrieval Policies in the Amazon Glacier Developer Guide.
-
For API details, see SetDataRetrievalPolicy
in AWS CLI Command Reference.
-
The following code example shows how to use set-vault-access-policy.
- AWS CLI
-
To set the access policy of a vault
The following
set-vault-access-policyexample attaches a permission policy to the specified vault.aws glacier set-vault-access-policy \ --account-id123456789111\ --vault-nameexample_vault\ --policy '{"Policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"arn:aws:iam::123456789222:root\"},\"Action\":\"glacier:ListJobs\",\"Resource\":\"arn:aws:glacier:us-west-2:123456789111:vaults/example_vault\"},{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"arn:aws:iam::123456789222:root\"},\"Action\":\"glacier:UploadArchive\",\"Resource\":\"arn:aws:glacier:us-west-2:123456789111:vaults/example_vault\"}]}"}'This command produces no output.
For more information, see Vault Access Policies in the Amazon Glacier Developer Guide.
-
For API details, see SetVaultAccessPolicy
in AWS CLI Command Reference.
-
The following code example shows how to use set-vault-notifications.
- AWS CLI
-
To configure SNS notifications for a vault
The following
set-vault-notificationsexample configures SNS notifications for a vault namedmy-vault.aws glacier set-vault-notifications \ --account-id - \ --vault-namemy-vault\ --vault-notification-configfile://notificationconfig.jsonThis command produces no output.
notificationconfig.jsonis a JSON file in the current folder that specifies an SNS topic and the events to publish.Contents of
notificationconfig.json:{ "SNSTopic": "arn:aws:sns:us-west-2:0123456789012:my-vault", "Events": ["ArchiveRetrievalCompleted", "InventoryRetrievalCompleted"] }Amazon Glacier requires an account ID argument when performing operations, but you can use a hyphen to specify the in-use account.
For more information, see Configuring Vault Notifications Using the AWS Command Line Interface in the Amazon Glacier Developer Guide.
-
For API details, see SetVaultNotifications
in AWS CLI Command Reference.
-
The following code example shows how to use upload-archive.
- AWS CLI
-
To upload an archive to a vault
The following
upload-archiveexample uploads an archive in the current folder namedarchive.zipto a vault namedmy-vault.aws glacier upload-archive \ --account-id - \ --vault-namemy-vault\ --bodyarchive.zipOutput:
{ "archiveId": "kKB7ymWJVpPSwhGP6ycSOAekp9ZYe_--zM_mw6k76ZFGEIWQX-ybtRDvc2VkPSDtfKmQrj0IRQLSGsNuDp-AJVlu2ccmDSyDUmZwKbwbpAdGATGDiB3hHO0bjbGehXTcApVud_wyDw", "checksum": "969fb39823836d81f0cc028195fcdbcbbe76cdde932d4646fa7de5f21e18aa67", "location": "/0123456789012/vaults/my-vault/archives/kKB7ymWJVpPSwhGP6ycSOAekp9ZYe_--zM_mw6k76ZFGEIWQX-ybtRDvc2VkPSDtfKmQrj0IRQLSGsNuDp-AJVlu2ccmDSyDUmZwKbwbpAdGATGDiB3hHO0bjbGehXTcApVud_wyDw" }Amazon Glacier requires an account ID argument when performing operations, but you can use a hyphen to specify the in-use account.
To retrieve an uploaded archive, initiate a retrieval job with the aws glacier initiate-job command.
For more information, see Uploading an Archive in Amazon Glacier in the Amazon Glacier Developer Guide.
-
For API details, see UploadArchive
in AWS CLI Command Reference.
-
The following code example shows how to use upload-multipart-part.
- AWS CLI
-
To upload a part of an archive
The following
upload-multipart-partexample uploads the first 1 MiB (1024 x 1024 bytes) part of an archive.aws glacier upload-multipart-part \ --bodypart1\ --range 'bytes 0-1048575/*' \--account-id - \ --vault-namemy-vault\ --upload-id19gaRezEXAMPLES6Ry5YYdqthHOC_kGRCT03L9yetr220UmPtBYKk-OssZtLqyFu7sY1_lR7vgFuJV6NtcV5zpsJOutput:
{ "checksum": "e1f2a7cd6e047fa606fe2f0280350f69b9f8cfa602097a9a026360a7edc1f553" }Amazon Glacier requires an account ID argument when performing operations, but you can use a hyphen to specify the in-use account.
The body parameter takes a path to a part file on the local filesystem. The range parameter takes an HTTP content range indicating the bytes that the part occupies in the completed archive. 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 in the AWS CLI User Guide.
-
For API details, see UploadMultipartPart
in AWS CLI Command Reference.
-