DescribeInstances unicodeC Example
#include <C_CkRestW.h>
#include <C_CkAuthAwsW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>
void ChilkatSample(void)
{
HCkRestW rest;
BOOL success;
HCkAuthAwsW authAws;
HCkJsonObjectW json;
HCkStringBuilderW sbRequestBody;
HCkStringBuilderW sbResponseBody;
int respStatusCode;
HCkJsonObjectW jResp;
const wchar_t *AgentVersion;
const wchar_t *AmiId;
const wchar_t *Architecture;
const wchar_t *Arn;
const wchar_t *AutoScalingType;
const wchar_t *AvailabilityZone;
const wchar_t *CreatedAt;
int EbsOptimized;
const wchar_t *Ec2InstanceId;
const wchar_t *EcsClusterArn;
const wchar_t *EcsContainerInstanceArn;
const wchar_t *ElasticIp;
const wchar_t *Hostname;
const wchar_t *InfrastructureClass;
int InstallUpdatesOnBoot;
const wchar_t *InstanceId;
const wchar_t *InstanceProfileArn;
const wchar_t *InstanceType;
const wchar_t *LastServiceErrorId;
const wchar_t *Os;
const wchar_t *Platform;
const wchar_t *PrivateDns;
const wchar_t *PrivateIp;
const wchar_t *PublicDns;
const wchar_t *PublicIp;
const wchar_t *RegisteredBy;
const wchar_t *ReportedAgentVersion;
const wchar_t *Family;
const wchar_t *Name;
const wchar_t *Version;
const wchar_t *RootDeviceType;
const wchar_t *RootDeviceVolumeId;
const wchar_t *SshHostDsaKeyFingerprint;
const wchar_t *SshHostRsaKeyFingerprint;
const wchar_t *SshKeyName;
const wchar_t *StackId;
const wchar_t *Status;
const wchar_t *SubnetId;
const wchar_t *Tenancy;
const wchar_t *VirtualizationType;
int j;
int count_j;
const wchar_t *DeviceName;
int DeleteOnTermination;
int Iops;
const wchar_t *SnapshotId;
int VolumeSize;
const wchar_t *VolumeType;
const wchar_t *NoDevice;
const wchar_t *VirtualName;
const wchar_t *strVal;
int i;
int count_i;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
rest = CkRestW_Create();
authAws = CkAuthAwsW_Create();
CkAuthAwsW_putAccessKey(authAws,L"AWS_ACCESS_KEY");
CkAuthAwsW_putSecretKey(authAws,L"AWS_SECRET_KEY");
// Don't forget to change the region to your particular region. (Also make the same change in the call to Connect below.)
CkAuthAwsW_putRegion(authAws,L"us-west-2");
CkAuthAwsW_putServiceName(authAws,L"opsworks");
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
CkRestW_SetAuthAws(rest,authAws);
// URL: https://opsworks.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = CkRestW_Connect(rest,L"opsworks.us-west-2.amazonaws.com",443,TRUE,TRUE);
if (success != TRUE) {
wprintf(L"ConnectFailReason: %d\n",CkRestW_getConnectFailReason(rest));
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
CkAuthAwsW_Dispose(authAws);
return;
}
// The following code creates the JSON request body.
// The JSON created by this code is shown below.
// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"InstanceIds[0]",L"string");
CkJsonObjectW_UpdateString(json,L"LayerId",L"string");
CkJsonObjectW_UpdateString(json,L"StackId",L"string");
// The JSON request body created by the above code:
// {
// "InstanceIds": [
// "string"
// ],
// "LayerId": "string",
// "StackId": "string"
// }
CkRestW_AddHeader(rest,L"Content-Type",L"application/x-amz-json-1.1");
CkRestW_AddHeader(rest,L"X-Amz-Target",L"OpsWorks_20130218.DescribeInstances");
sbRequestBody = CkStringBuilderW_Create();
CkJsonObjectW_EmitSb(json,sbRequestBody);
sbResponseBody = CkStringBuilderW_Create();
success = CkRestW_FullRequestSb(rest,L"POST",L"/",sbRequestBody,sbResponseBody);
if (success != TRUE) {
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
CkAuthAwsW_Dispose(authAws);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbRequestBody);
CkStringBuilderW_Dispose(sbResponseBody);
return;
}
respStatusCode = CkRestW_getResponseStatusCode(rest);
wprintf(L"response status code = %d\n",respStatusCode);
if (respStatusCode != 200) {
wprintf(L"Response Header:\n");
wprintf(L"%s\n",CkRestW_responseHeader(rest));
wprintf(L"Response Body:\n");
wprintf(L"%s\n",CkStringBuilderW_getAsString(sbResponseBody));
CkRestW_Dispose(rest);
CkAuthAwsW_Dispose(authAws);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbRequestBody);
CkStringBuilderW_Dispose(sbResponseBody);
return;
}
jResp = CkJsonObjectW_Create();
CkJsonObjectW_LoadSb(jResp,sbResponseBody);
// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
// See this example explaining how this memory should be used: const char * functions.
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"Instances");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
AgentVersion = CkJsonObjectW_stringOf(jResp,L"Instances[i].AgentVersion");
AmiId = CkJsonObjectW_stringOf(jResp,L"Instances[i].AmiId");
Architecture = CkJsonObjectW_stringOf(jResp,L"Instances[i].Architecture");
Arn = CkJsonObjectW_stringOf(jResp,L"Instances[i].Arn");
AutoScalingType = CkJsonObjectW_stringOf(jResp,L"Instances[i].AutoScalingType");
AvailabilityZone = CkJsonObjectW_stringOf(jResp,L"Instances[i].AvailabilityZone");
CreatedAt = CkJsonObjectW_stringOf(jResp,L"Instances[i].CreatedAt");
EbsOptimized = CkJsonObjectW_IntOf(jResp,L"Instances[i].EbsOptimized");
Ec2InstanceId = CkJsonObjectW_stringOf(jResp,L"Instances[i].Ec2InstanceId");
EcsClusterArn = CkJsonObjectW_stringOf(jResp,L"Instances[i].EcsClusterArn");
EcsContainerInstanceArn = CkJsonObjectW_stringOf(jResp,L"Instances[i].EcsContainerInstanceArn");
ElasticIp = CkJsonObjectW_stringOf(jResp,L"Instances[i].ElasticIp");
Hostname = CkJsonObjectW_stringOf(jResp,L"Instances[i].Hostname");
InfrastructureClass = CkJsonObjectW_stringOf(jResp,L"Instances[i].InfrastructureClass");
InstallUpdatesOnBoot = CkJsonObjectW_IntOf(jResp,L"Instances[i].InstallUpdatesOnBoot");
InstanceId = CkJsonObjectW_stringOf(jResp,L"Instances[i].InstanceId");
InstanceProfileArn = CkJsonObjectW_stringOf(jResp,L"Instances[i].InstanceProfileArn");
InstanceType = CkJsonObjectW_stringOf(jResp,L"Instances[i].InstanceType");
LastServiceErrorId = CkJsonObjectW_stringOf(jResp,L"Instances[i].LastServiceErrorId");
Os = CkJsonObjectW_stringOf(jResp,L"Instances[i].Os");
Platform = CkJsonObjectW_stringOf(jResp,L"Instances[i].Platform");
PrivateDns = CkJsonObjectW_stringOf(jResp,L"Instances[i].PrivateDns");
PrivateIp = CkJsonObjectW_stringOf(jResp,L"Instances[i].PrivateIp");
PublicDns = CkJsonObjectW_stringOf(jResp,L"Instances[i].PublicDns");
PublicIp = CkJsonObjectW_stringOf(jResp,L"Instances[i].PublicIp");
RegisteredBy = CkJsonObjectW_stringOf(jResp,L"Instances[i].RegisteredBy");
ReportedAgentVersion = CkJsonObjectW_stringOf(jResp,L"Instances[i].ReportedAgentVersion");
Family = CkJsonObjectW_stringOf(jResp,L"Instances[i].ReportedOs.Family");
Name = CkJsonObjectW_stringOf(jResp,L"Instances[i].ReportedOs.Name");
Version = CkJsonObjectW_stringOf(jResp,L"Instances[i].ReportedOs.Version");
RootDeviceType = CkJsonObjectW_stringOf(jResp,L"Instances[i].RootDeviceType");
RootDeviceVolumeId = CkJsonObjectW_stringOf(jResp,L"Instances[i].RootDeviceVolumeId");
SshHostDsaKeyFingerprint = CkJsonObjectW_stringOf(jResp,L"Instances[i].SshHostDsaKeyFingerprint");
SshHostRsaKeyFingerprint = CkJsonObjectW_stringOf(jResp,L"Instances[i].SshHostRsaKeyFingerprint");
SshKeyName = CkJsonObjectW_stringOf(jResp,L"Instances[i].SshKeyName");
StackId = CkJsonObjectW_stringOf(jResp,L"Instances[i].StackId");
Status = CkJsonObjectW_stringOf(jResp,L"Instances[i].Status");
SubnetId = CkJsonObjectW_stringOf(jResp,L"Instances[i].SubnetId");
Tenancy = CkJsonObjectW_stringOf(jResp,L"Instances[i].Tenancy");
VirtualizationType = CkJsonObjectW_stringOf(jResp,L"Instances[i].VirtualizationType");
j = 0;
count_j = CkJsonObjectW_SizeOfArray(jResp,L"Instances[i].BlockDeviceMappings");
while (j < count_j) {
CkJsonObjectW_putJ(jResp,j);
DeviceName = CkJsonObjectW_stringOf(jResp,L"Instances[i].BlockDeviceMappings[j].DeviceName");
DeleteOnTermination = CkJsonObjectW_IntOf(jResp,L"Instances[i].BlockDeviceMappings[j].Ebs.DeleteOnTermination");
Iops = CkJsonObjectW_IntOf(jResp,L"Instances[i].BlockDeviceMappings[j].Ebs.Iops");
SnapshotId = CkJsonObjectW_stringOf(jResp,L"Instances[i].BlockDeviceMappings[j].Ebs.SnapshotId");
VolumeSize = CkJsonObjectW_IntOf(jResp,L"Instances[i].BlockDeviceMappings[j].Ebs.VolumeSize");
VolumeType = CkJsonObjectW_stringOf(jResp,L"Instances[i].BlockDeviceMappings[j].Ebs.VolumeType");
NoDevice = CkJsonObjectW_stringOf(jResp,L"Instances[i].BlockDeviceMappings[j].NoDevice");
VirtualName = CkJsonObjectW_stringOf(jResp,L"Instances[i].BlockDeviceMappings[j].VirtualName");
j = j + 1;
}
j = 0;
count_j = CkJsonObjectW_SizeOfArray(jResp,L"Instances[i].LayerIds");
while (j < count_j) {
CkJsonObjectW_putJ(jResp,j);
strVal = CkJsonObjectW_stringOf(jResp,L"Instances[i].LayerIds[j]");
j = j + 1;
}
j = 0;
count_j = CkJsonObjectW_SizeOfArray(jResp,L"Instances[i].SecurityGroupIds");
while (j < count_j) {
CkJsonObjectW_putJ(jResp,j);
strVal = CkJsonObjectW_stringOf(jResp,L"Instances[i].SecurityGroupIds[j]");
j = j + 1;
}
i = i + 1;
}
// A sample JSON response body parsed by the above code:
// {
// "Instances": [
// {
// "AgentVersion": "string",
// "AmiId": "string",
// "Architecture": "string",
// "Arn": "string",
// "AutoScalingType": "string",
// "AvailabilityZone": "string",
// "BlockDeviceMappings": [
// {
// "DeviceName": "string",
// "Ebs": {
// "DeleteOnTermination": boolean,
// "Iops": number,
// "SnapshotId": "string",
// "VolumeSize": number,
// "VolumeType": "string"
// },
// "NoDevice": "string",
// "VirtualName": "string"
// }
// ],
// "CreatedAt": "string",
// "EbsOptimized": boolean,
// "Ec2InstanceId": "string",
// "EcsClusterArn": "string",
// "EcsContainerInstanceArn": "string",
// "ElasticIp": "string",
// "Hostname": "string",
// "InfrastructureClass": "string",
// "InstallUpdatesOnBoot": boolean,
// "InstanceId": "string",
// "InstanceProfileArn": "string",
// "InstanceType": "string",
// "LastServiceErrorId": "string",
// "LayerIds": [
// "string"
// ],
// "Os": "string",
// "Platform": "string",
// "PrivateDns": "string",
// "PrivateIp": "string",
// "PublicDns": "string",
// "PublicIp": "string",
// "RegisteredBy": "string",
// "ReportedAgentVersion": "string",
// "ReportedOs": {
// "Family": "string",
// "Name": "string",
// "Version": "string"
// },
// "RootDeviceType": "string",
// "RootDeviceVolumeId": "string",
// "SecurityGroupIds": [
// "string"
// ],
// "SshHostDsaKeyFingerprint": "string",
// "SshHostRsaKeyFingerprint": "string",
// "SshKeyName": "string",
// "StackId": "string",
// "Status": "string",
// "SubnetId": "string",
// "Tenancy": "string",
// "VirtualizationType": "string"
// }
// ]
// }
CkRestW_Dispose(rest);
CkAuthAwsW_Dispose(authAws);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbRequestBody);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
}