Chilkat Online Tools

DescribeInstances unicodeCpp Example

AWS OpsWorks

#include <CkRestW.h>
#include <CkAuthAwsW.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>

void ChilkatSample(void)
    {
    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkRestW rest;
    bool success;

    CkAuthAwsW authAws;
    authAws.put_AccessKey(L"AWS_ACCESS_KEY");
    authAws.put_SecretKey(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.)
    authAws.put_Region(L"us-west-2");
    authAws.put_ServiceName(L"opsworks");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.SetAuthAws(authAws);

    // URL: https://opsworks.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.Connect(L"opsworks.us-west-2.amazonaws.com",443,true,true);
    if (success != true) {
        wprintf(L"ConnectFailReason: %d\n",rest.get_ConnectFailReason());
        wprintf(L"%s\n",rest.lastErrorText());
        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

    CkJsonObjectW json;
    json.UpdateString(L"InstanceIds[0]",L"string");
    json.UpdateString(L"LayerId",L"string");
    json.UpdateString(L"StackId",L"string");

    // The JSON request body created by the above code:

    // {
    //   "InstanceIds": [
    //     "string"
    //   ],
    //   "LayerId": "string",
    //   "StackId": "string"
    // }

    rest.AddHeader(L"Content-Type",L"application/x-amz-json-1.1");
    rest.AddHeader(L"X-Amz-Target",L"OpsWorks_20130218.DescribeInstances");

    CkStringBuilderW sbRequestBody;
    json.EmitSb(sbRequestBody);
    CkStringBuilderW sbResponseBody;
    success = rest.FullRequestSb(L"POST",L"/",sbRequestBody,sbResponseBody);
    if (success != true) {
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    int respStatusCode = rest.get_ResponseStatusCode();
    wprintf(L"response status code = %d\n",respStatusCode);
    if (respStatusCode != 200) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",rest.responseHeader());
        wprintf(L"Response Body:\n");
        wprintf(L"%s\n",sbResponseBody.getAsString());
        return;
    }

    CkJsonObjectW jResp;
    jResp.LoadSb(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.

    const wchar_t *AgentVersion = 0;
    const wchar_t *AmiId = 0;
    const wchar_t *Architecture = 0;
    const wchar_t *Arn = 0;
    const wchar_t *AutoScalingType = 0;
    const wchar_t *AvailabilityZone = 0;
    const wchar_t *CreatedAt = 0;
    int EbsOptimized;
    const wchar_t *Ec2InstanceId = 0;
    const wchar_t *EcsClusterArn = 0;
    const wchar_t *EcsContainerInstanceArn = 0;
    const wchar_t *ElasticIp = 0;
    const wchar_t *Hostname = 0;
    const wchar_t *InfrastructureClass = 0;
    int InstallUpdatesOnBoot;
    const wchar_t *InstanceId = 0;
    const wchar_t *InstanceProfileArn = 0;
    const wchar_t *InstanceType = 0;
    const wchar_t *LastServiceErrorId = 0;
    const wchar_t *Os = 0;
    const wchar_t *Platform = 0;
    const wchar_t *PrivateDns = 0;
    const wchar_t *PrivateIp = 0;
    const wchar_t *PublicDns = 0;
    const wchar_t *PublicIp = 0;
    const wchar_t *RegisteredBy = 0;
    const wchar_t *ReportedAgentVersion = 0;
    const wchar_t *Family = 0;
    const wchar_t *Name = 0;
    const wchar_t *Version = 0;
    const wchar_t *RootDeviceType = 0;
    const wchar_t *RootDeviceVolumeId = 0;
    const wchar_t *SshHostDsaKeyFingerprint = 0;
    const wchar_t *SshHostRsaKeyFingerprint = 0;
    const wchar_t *SshKeyName = 0;
    const wchar_t *StackId = 0;
    const wchar_t *Status = 0;
    const wchar_t *SubnetId = 0;
    const wchar_t *Tenancy = 0;
    const wchar_t *VirtualizationType = 0;
    int j;
    int count_j;
    const wchar_t *DeviceName = 0;
    int DeleteOnTermination;
    int Iops;
    const wchar_t *SnapshotId = 0;
    int VolumeSize;
    const wchar_t *VolumeType = 0;
    const wchar_t *NoDevice = 0;
    const wchar_t *VirtualName = 0;
    const wchar_t *strVal = 0;

    int i = 0;
    int count_i = jResp.SizeOfArray(L"Instances");
    while (i < count_i) {
        jResp.put_I(i);
        AgentVersion = jResp.stringOf(L"Instances[i].AgentVersion");
        AmiId = jResp.stringOf(L"Instances[i].AmiId");
        Architecture = jResp.stringOf(L"Instances[i].Architecture");
        Arn = jResp.stringOf(L"Instances[i].Arn");
        AutoScalingType = jResp.stringOf(L"Instances[i].AutoScalingType");
        AvailabilityZone = jResp.stringOf(L"Instances[i].AvailabilityZone");
        CreatedAt = jResp.stringOf(L"Instances[i].CreatedAt");
        EbsOptimized = jResp.IntOf(L"Instances[i].EbsOptimized");
        Ec2InstanceId = jResp.stringOf(L"Instances[i].Ec2InstanceId");
        EcsClusterArn = jResp.stringOf(L"Instances[i].EcsClusterArn");
        EcsContainerInstanceArn = jResp.stringOf(L"Instances[i].EcsContainerInstanceArn");
        ElasticIp = jResp.stringOf(L"Instances[i].ElasticIp");
        Hostname = jResp.stringOf(L"Instances[i].Hostname");
        InfrastructureClass = jResp.stringOf(L"Instances[i].InfrastructureClass");
        InstallUpdatesOnBoot = jResp.IntOf(L"Instances[i].InstallUpdatesOnBoot");
        InstanceId = jResp.stringOf(L"Instances[i].InstanceId");
        InstanceProfileArn = jResp.stringOf(L"Instances[i].InstanceProfileArn");
        InstanceType = jResp.stringOf(L"Instances[i].InstanceType");
        LastServiceErrorId = jResp.stringOf(L"Instances[i].LastServiceErrorId");
        Os = jResp.stringOf(L"Instances[i].Os");
        Platform = jResp.stringOf(L"Instances[i].Platform");
        PrivateDns = jResp.stringOf(L"Instances[i].PrivateDns");
        PrivateIp = jResp.stringOf(L"Instances[i].PrivateIp");
        PublicDns = jResp.stringOf(L"Instances[i].PublicDns");
        PublicIp = jResp.stringOf(L"Instances[i].PublicIp");
        RegisteredBy = jResp.stringOf(L"Instances[i].RegisteredBy");
        ReportedAgentVersion = jResp.stringOf(L"Instances[i].ReportedAgentVersion");
        Family = jResp.stringOf(L"Instances[i].ReportedOs.Family");
        Name = jResp.stringOf(L"Instances[i].ReportedOs.Name");
        Version = jResp.stringOf(L"Instances[i].ReportedOs.Version");
        RootDeviceType = jResp.stringOf(L"Instances[i].RootDeviceType");
        RootDeviceVolumeId = jResp.stringOf(L"Instances[i].RootDeviceVolumeId");
        SshHostDsaKeyFingerprint = jResp.stringOf(L"Instances[i].SshHostDsaKeyFingerprint");
        SshHostRsaKeyFingerprint = jResp.stringOf(L"Instances[i].SshHostRsaKeyFingerprint");
        SshKeyName = jResp.stringOf(L"Instances[i].SshKeyName");
        StackId = jResp.stringOf(L"Instances[i].StackId");
        Status = jResp.stringOf(L"Instances[i].Status");
        SubnetId = jResp.stringOf(L"Instances[i].SubnetId");
        Tenancy = jResp.stringOf(L"Instances[i].Tenancy");
        VirtualizationType = jResp.stringOf(L"Instances[i].VirtualizationType");
        j = 0;
        count_j = jResp.SizeOfArray(L"Instances[i].BlockDeviceMappings");
        while (j < count_j) {
            jResp.put_J(j);
            DeviceName = jResp.stringOf(L"Instances[i].BlockDeviceMappings[j].DeviceName");
            DeleteOnTermination = jResp.IntOf(L"Instances[i].BlockDeviceMappings[j].Ebs.DeleteOnTermination");
            Iops = jResp.IntOf(L"Instances[i].BlockDeviceMappings[j].Ebs.Iops");
            SnapshotId = jResp.stringOf(L"Instances[i].BlockDeviceMappings[j].Ebs.SnapshotId");
            VolumeSize = jResp.IntOf(L"Instances[i].BlockDeviceMappings[j].Ebs.VolumeSize");
            VolumeType = jResp.stringOf(L"Instances[i].BlockDeviceMappings[j].Ebs.VolumeType");
            NoDevice = jResp.stringOf(L"Instances[i].BlockDeviceMappings[j].NoDevice");
            VirtualName = jResp.stringOf(L"Instances[i].BlockDeviceMappings[j].VirtualName");
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray(L"Instances[i].LayerIds");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf(L"Instances[i].LayerIds[j]");
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray(L"Instances[i].SecurityGroupIds");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf(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"
    //     }
    //   ]
    // }
    }