C
C
Amazon Glacier Create Vault
See more Amazon Glacier Examples
Demonstrates how to create a new vault with a specified name. The name of the vault must be unique within a region for an AWS account.Chilkat C Downloads
#include <C_CkRest.h>
#include <C_CkAuthAws.h>
#include <C_CkStringBuilder.h>
void ChilkatSample(void)
{
BOOL success;
HCkRest rest;
BOOL bTls;
int port;
BOOL bAutoReconnect;
HCkAuthAws authAws;
HCkStringBuilder sbResponseBody;
int respStatusCode;
success = FALSE;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
rest = CkRest_Create();
// Connect to the Amazon AWS REST server in the desired region.
bTls = TRUE;
port = 443;
bAutoReconnect = TRUE;
success = CkRest_Connect(rest,"glacier.us-west-2.amazonaws.com",port,bTls,bAutoReconnect);
// Provide AWS credentials.
authAws = CkAuthAws_Create();
CkAuthAws_putAccessKey(authAws,"AWS_ACCESS_KEY");
CkAuthAws_putSecretKey(authAws,"AWS_SECRET_KEY");
CkAuthAws_putServiceName(authAws,"glacier");
// The vault we're creating will be in the us-west-2 region.
CkAuthAws_putRegion(authAws,"us-west-2");
success = CkRest_SetAuthAws(rest,authAws);
// --------------------------------------------------------------------------
// Note: The above REST connection and setup of the AWS credentials
// can be done once. After connecting, any number of REST calls can be made.
// The "auto reconnect" property passed to rest.Connect indicates that if
// the connection is lost, a REST method call will automatically reconnect
// if needed.
// --------------------------------------------------------------------------
//
// For more information, see Glacier Create Vault Reference Documentation
//
CkRest_AddHeader(rest,"x-amz-glacier-version","2012-06-01");
// Create a vault named "chilkat" in my account's us-west-2 region.
sbResponseBody = CkStringBuilder_Create();
success = CkRest_FullRequestNoBodySb(rest,"PUT","/AWS_ACCOUNT_ID/vaults/chilkat",sbResponseBody);
if (success != TRUE) {
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
CkAuthAws_Dispose(authAws);
CkStringBuilder_Dispose(sbResponseBody);
return;
}
respStatusCode = CkRest_getResponseStatusCode(rest);
if (respStatusCode >= 400) {
printf("Response Status Code = %d\n",respStatusCode);
printf("Response Header:\n");
printf("%s\n",CkRest_responseHeader(rest));
printf("Response Body:\n");
printf("%s\n",CkStringBuilder_getAsString(sbResponseBody));
CkRest_Dispose(rest);
CkAuthAws_Dispose(authAws);
CkStringBuilder_Dispose(sbResponseBody);
return;
}
// Success is indicated by a 201 response status with an empty response body.
printf("response status code = %d\n",respStatusCode);
CkRest_Dispose(rest);
CkAuthAws_Dispose(authAws);
CkStringBuilder_Dispose(sbResponseBody);
}