Amazon Glacier: Create Vault
See more Amazon Glacier Examples
For existing Amazon Glacier vault customers. The standalone vault service is closed to new customers. These examples use its REST API version 2012-06-01, not the S3 bucket APIs used by S3 Glacier storage classes. See AWS service guidance.
Creates a vault for an eligible existing customer. The returned Location identifies the vault.
Uses AWS Signature Version 4 with service glacier. Set the region once; the example builds the commercial AWS endpoint. Other partitions require the appropriate endpoint suffix. /-/ selects the signing account; change the vault name and IDs to your own resources. Load private qa_data/aws/glacier.json with string fields access_key, secret_key, and session_token for temporary credentials. Prefer short-lived role credentials. This sample does not discover profiles or refresh credentials. TLS certificate verification is enabled explicitly.
Checks transport completion, the operation-specific HTTP status, and parsed data separately. Inspect full diagnostics privately. Renew expired credentials; use bounded backoff with jitter for retryable reads. Uploads and job initiation can succeed before a connection fails, so do not blindly resubmit them. Configure IAM permissions for only the required operations and vault resources.
Chilkat Tcl Downloads
load ./chilkat.dll
# Assumes Chilkat is unlocked. See Global Unlock Sample.
set success 0
# Private configuration, not a file in public web content or source control.
# Load current IAM credentials authorized for the Glacier operation.
set credentials [new_CkJsonObject]
CkJsonObject_put_Strict $credentials 1
set success [CkJsonObject_LoadFile $credentials "qa_data/aws/glacier.json"]
if {$success != 1} then {
puts "Could not load private AWS credentials."
delete_CkJsonObject $credentials
exit
}
if {expr [[CkJsonObject_JsonTypeOf $credentials "access_key"] != 1] || [[CkJsonObject_stringOf $credentials "access_key"] == ""]} then {
puts "Missing or invalid access_key."
delete_CkJsonObject $credentials
exit
}
if {expr [[CkJsonObject_JsonTypeOf $credentials "secret_key"] != 1] || [[CkJsonObject_stringOf $credentials "secret_key"] == ""]} then {
puts "Missing or invalid secret_key."
delete_CkJsonObject $credentials
exit
}
# Set this once to the region containing the vault.
set region "us-west-2"
set endpoint [new_CkStringBuilder]
CkStringBuilder_Append $endpoint "glacier."
CkStringBuilder_Append $endpoint $region
CkStringBuilder_Append $endpoint ".amazonaws.com"
set aws [new_CkAuthAws]
CkAuthAws_put_AccessKey $aws [CkJsonObject_stringOf $credentials "access_key"]
CkAuthAws_put_SecretKey $aws [CkJsonObject_stringOf $credentials "secret_key"]
CkAuthAws_put_Region $aws $region
CkAuthAws_put_ServiceName $aws "glacier"
CkAuthAws_put_SignatureVersion $aws 4
set rest [new_CkRest]
CkRest_put_ConnectTimeoutMs $rest 20000
CkRest_put_IdleTimeoutMs $rest 60000
set success [CkRest_SetAuthAws $rest $aws]
if {$success != 1} then {
puts "Could not configure AWS signing."
delete_CkJsonObject $credentials
delete_CkStringBuilder $endpoint
delete_CkAuthAws $aws
delete_CkRest $rest
exit
}
# Temporary IAM/STS credentials require their session token on every signed request.
# Include the token in the signed query. Keep request URLs and diagnostics private.
# Leave session_token absent or empty only for credentials that do not have one.
if {[CkJsonObject_HasMember $credentials "session_token"] == 1} then {
if {[CkJsonObject_JsonTypeOf $credentials "session_token"] != 1} then {
puts "session_token must be a string."
delete_CkJsonObject $credentials
delete_CkStringBuilder $endpoint
delete_CkAuthAws $aws
delete_CkRest $rest
exit
}
if {[CkJsonObject_stringOf $credentials "session_token"] != ""} then {
set success [CkRest_AddQueryParam $rest "X-Amz-Security-Token" [CkJsonObject_stringOf $credentials "session_token"]]
if {$success != 1} then {
puts "Could not set the session-token parameter."
delete_CkJsonObject $credentials
delete_CkStringBuilder $endpoint
delete_CkAuthAws $aws
delete_CkRest $rest
exit
}
}
}
# Supply a Socket to explicitly enable TLS certificate verification.
set connection [new_CkSocket]
CkSocket_put_RequireSslCertVerify $connection 1
CkSocket_put_MaxReadIdleMs $connection 60000
CkSocket_put_MaxSendIdleMs $connection 60000
set success [CkSocket_Connect $connection [CkStringBuilder_getAsString $endpoint] 443 1 20000]
if {$success != 1} then {
puts "TLS connection failed; inspect diagnostics privately."
delete_CkJsonObject $credentials
delete_CkStringBuilder $endpoint
delete_CkAuthAws $aws
delete_CkRest $rest
delete_CkSocket $connection
exit
}
set success [CkRest_UseConnection $rest $connection 1]
if {$success != 1} then {
puts "Could not attach the TLS connection."
delete_CkJsonObject $credentials
delete_CkStringBuilder $endpoint
delete_CkAuthAws $aws
delete_CkRest $rest
delete_CkSocket $connection
exit
}
set success [CkRest_AddHeader $rest "x-amz-glacier-version" "2012-06-01"]
if {$success != 1} then {
puts "Could not set x-amz-glacier-version."
delete_CkJsonObject $credentials
delete_CkStringBuilder $endpoint
delete_CkAuthAws $aws
delete_CkRest $rest
delete_CkSocket $connection
exit
}
# A hyphen selects the account belonging to the signing credentials.
# Use the original, URL-safe vault name and IDs returned by Glacier.
set success [CkRest_AddPathParam $rest "{vault}" "chilkat"]
if {$success != 1} then {
puts "Could not set vault name."
delete_CkJsonObject $credentials
delete_CkStringBuilder $endpoint
delete_CkAuthAws $aws
delete_CkRest $rest
delete_CkSocket $connection
exit
}
set body [new_CkJsonObject]
set result [new_CkJsonObject]
CkJsonObject_put_Strict $result 1
set error [new_CkJsonObject]
CkJsonObject_put_Strict $error 1
set requestBody [new_CkStringBuilder]
set responseBody [new_CkStringBuilder]
set success [CkRest_FullRequestNoBodySb $rest "PUT" "/-/vaults/{vault}" $responseBody]
if {$success != 1} then {
puts "Request did not complete; inspect diagnostics privately. Check state before retrying a change."
delete_CkJsonObject $credentials
delete_CkStringBuilder $endpoint
delete_CkAuthAws $aws
delete_CkRest $rest
delete_CkSocket $connection
delete_CkJsonObject $body
delete_CkJsonObject $result
delete_CkJsonObject $error
delete_CkStringBuilder $requestBody
delete_CkStringBuilder $responseBody
exit
}
if {[CkRest_get_ResponseStatusCode $rest] != 201} then {
puts "Glacier HTTP status: [CkRest_get_ResponseStatusCode $rest]"
set success [CkJsonObject_LoadSb $error $responseBody]
if {$success == 1} then {
if {[CkJsonObject_JsonTypeOf $error "code"] == 1} then {
puts "AWS error code: [CkJsonObject_stringOf $error code]"
}
}
puts "AWS request ID: [CkRest_responseHdrByName $rest x-amzn-RequestId]"
# Inspect full errors privately. An HTTP error is not a successful operation.
delete_CkJsonObject $credentials
delete_CkStringBuilder $endpoint
delete_CkAuthAws $aws
delete_CkRest $rest
delete_CkSocket $connection
delete_CkJsonObject $body
delete_CkJsonObject $result
delete_CkJsonObject $error
delete_CkStringBuilder $requestBody
delete_CkStringBuilder $responseBody
exit
}
puts "Vault location: [CkRest_responseHdrByName $rest Location]"
puts "Operation succeeded."
delete_CkJsonObject $credentials
delete_CkStringBuilder $endpoint
delete_CkAuthAws $aws
delete_CkRest $rest
delete_CkSocket $connection
delete_CkJsonObject $body
delete_CkJsonObject $result
delete_CkJsonObject $error
delete_CkStringBuilder $requestBody
delete_CkStringBuilder $responseBody