Chilkat Online Tools

DescribeReplicationInstances unicodeC Example

AWS Database Migration Service

#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;
    int AllocatedStorage;
    int AutoMinorVersionUpgrade;
    const wchar_t *AvailabilityZone;
    const wchar_t *DnsNameServers;
    const wchar_t *EngineVersion;
    int FreeUntil;
    int InstanceCreateTime;
    const wchar_t *KmsKeyId;
    int MultiAZ;
    int PendingModifiedValuesAllocatedStorage;
    const wchar_t *PendingModifiedValuesEngineVersion;
    int PendingModifiedValuesMultiAZ;
    const wchar_t *ReplicationInstanceClass;
    const wchar_t *PreferredMaintenanceWindow;
    int PubliclyAccessible;
    const wchar_t *ReplicationInstanceArn;
    const wchar_t *ReplicationInstanceIdentifier;
    const wchar_t *ReplicationInstancePrivateIpAddress;
    const wchar_t *ReplicationInstancePublicIpAddress;
    const wchar_t *ReplicationInstanceStatus;
    const wchar_t *ReplicationSubnetGroupDescription;
    const wchar_t *ReplicationSubnetGroupIdentifier;
    const wchar_t *SubnetGroupStatus;
    const wchar_t *VpcId;
    const wchar_t *SecondaryAvailabilityZone;
    int j;
    int count_j;
    const wchar_t *strVal;
    const wchar_t *Name;
    const wchar_t *SubnetIdentifier;
    const wchar_t *SubnetStatus;
    const wchar_t *Status;
    const wchar_t *VpcSecurityGroupId;
    const wchar_t *Marker;
    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"dms");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    CkRestW_SetAuthAws(rest,authAws);

    // URL: https://dms.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = CkRestW_Connect(rest,L"dms.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"Filters[0].Name",L"string");
    CkJsonObjectW_UpdateString(json,L"Filters[0].Values[0]",L"string");
    CkJsonObjectW_UpdateString(json,L"Marker",L"string");
    CkJsonObjectW_UpdateInt(json,L"MaxRecords",123);

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

    // {
    //   "Filters": [
    //     {
    //       "Name": "string",
    //       "Values": [
    //         "string"
    //       ]
    //     }
    //   ],
    //   "Marker": "string",
    //   "MaxRecords": number
    // }

    CkRestW_AddHeader(rest,L"Content-Type",L"application/x-amz-json-1.1");
    CkRestW_AddHeader(rest,L"X-Amz-Target",L"AmazonDMSv20160101.DescribeReplicationInstances");

    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.

    Marker = CkJsonObjectW_stringOf(jResp,L"Marker");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"ReplicationInstances");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        AllocatedStorage = CkJsonObjectW_IntOf(jResp,L"ReplicationInstances[i].AllocatedStorage");
        AutoMinorVersionUpgrade = CkJsonObjectW_IntOf(jResp,L"ReplicationInstances[i].AutoMinorVersionUpgrade");
        AvailabilityZone = CkJsonObjectW_stringOf(jResp,L"ReplicationInstances[i].AvailabilityZone");
        DnsNameServers = CkJsonObjectW_stringOf(jResp,L"ReplicationInstances[i].DnsNameServers");
        EngineVersion = CkJsonObjectW_stringOf(jResp,L"ReplicationInstances[i].EngineVersion");
        FreeUntil = CkJsonObjectW_IntOf(jResp,L"ReplicationInstances[i].FreeUntil");
        InstanceCreateTime = CkJsonObjectW_IntOf(jResp,L"ReplicationInstances[i].InstanceCreateTime");
        KmsKeyId = CkJsonObjectW_stringOf(jResp,L"ReplicationInstances[i].KmsKeyId");
        MultiAZ = CkJsonObjectW_IntOf(jResp,L"ReplicationInstances[i].MultiAZ");
        PendingModifiedValuesAllocatedStorage = CkJsonObjectW_IntOf(jResp,L"ReplicationInstances[i].PendingModifiedValues.AllocatedStorage");
        PendingModifiedValuesEngineVersion = CkJsonObjectW_stringOf(jResp,L"ReplicationInstances[i].PendingModifiedValues.EngineVersion");
        PendingModifiedValuesMultiAZ = CkJsonObjectW_IntOf(jResp,L"ReplicationInstances[i].PendingModifiedValues.MultiAZ");
        ReplicationInstanceClass = CkJsonObjectW_stringOf(jResp,L"ReplicationInstances[i].PendingModifiedValues.ReplicationInstanceClass");
        PreferredMaintenanceWindow = CkJsonObjectW_stringOf(jResp,L"ReplicationInstances[i].PreferredMaintenanceWindow");
        PubliclyAccessible = CkJsonObjectW_IntOf(jResp,L"ReplicationInstances[i].PubliclyAccessible");
        ReplicationInstanceArn = CkJsonObjectW_stringOf(jResp,L"ReplicationInstances[i].ReplicationInstanceArn");
        ReplicationInstanceClass = CkJsonObjectW_stringOf(jResp,L"ReplicationInstances[i].ReplicationInstanceClass");
        ReplicationInstanceIdentifier = CkJsonObjectW_stringOf(jResp,L"ReplicationInstances[i].ReplicationInstanceIdentifier");
        ReplicationInstancePrivateIpAddress = CkJsonObjectW_stringOf(jResp,L"ReplicationInstances[i].ReplicationInstancePrivateIpAddress");
        ReplicationInstancePublicIpAddress = CkJsonObjectW_stringOf(jResp,L"ReplicationInstances[i].ReplicationInstancePublicIpAddress");
        ReplicationInstanceStatus = CkJsonObjectW_stringOf(jResp,L"ReplicationInstances[i].ReplicationInstanceStatus");
        ReplicationSubnetGroupDescription = CkJsonObjectW_stringOf(jResp,L"ReplicationInstances[i].ReplicationSubnetGroup.ReplicationSubnetGroupDescription");
        ReplicationSubnetGroupIdentifier = CkJsonObjectW_stringOf(jResp,L"ReplicationInstances[i].ReplicationSubnetGroup.ReplicationSubnetGroupIdentifier");
        SubnetGroupStatus = CkJsonObjectW_stringOf(jResp,L"ReplicationInstances[i].ReplicationSubnetGroup.SubnetGroupStatus");
        VpcId = CkJsonObjectW_stringOf(jResp,L"ReplicationInstances[i].ReplicationSubnetGroup.VpcId");
        SecondaryAvailabilityZone = CkJsonObjectW_stringOf(jResp,L"ReplicationInstances[i].SecondaryAvailabilityZone");
        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"ReplicationInstances[i].ReplicationInstancePrivateIpAddresses");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            strVal = CkJsonObjectW_stringOf(jResp,L"ReplicationInstances[i].ReplicationInstancePrivateIpAddresses[j]");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"ReplicationInstances[i].ReplicationInstancePublicIpAddresses");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            strVal = CkJsonObjectW_stringOf(jResp,L"ReplicationInstances[i].ReplicationInstancePublicIpAddresses[j]");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"ReplicationInstances[i].ReplicationSubnetGroup.Subnets");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            Name = CkJsonObjectW_stringOf(jResp,L"ReplicationInstances[i].ReplicationSubnetGroup.Subnets[j].SubnetAvailabilityZone.Name");
            SubnetIdentifier = CkJsonObjectW_stringOf(jResp,L"ReplicationInstances[i].ReplicationSubnetGroup.Subnets[j].SubnetIdentifier");
            SubnetStatus = CkJsonObjectW_stringOf(jResp,L"ReplicationInstances[i].ReplicationSubnetGroup.Subnets[j].SubnetStatus");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"ReplicationInstances[i].VpcSecurityGroups");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            Status = CkJsonObjectW_stringOf(jResp,L"ReplicationInstances[i].VpcSecurityGroups[j].Status");
            VpcSecurityGroupId = CkJsonObjectW_stringOf(jResp,L"ReplicationInstances[i].VpcSecurityGroups[j].VpcSecurityGroupId");
            j = j + 1;
        }

        i = i + 1;
    }

    // A sample JSON response body parsed by the above code:

    // {
    //   "Marker": "string",
    //   "ReplicationInstances": [
    //     {
    //       "AllocatedStorage": number,
    //       "AutoMinorVersionUpgrade": boolean,
    //       "AvailabilityZone": "string",
    //       "DnsNameServers": "string",
    //       "EngineVersion": "string",
    //       "FreeUntil": number,
    //       "InstanceCreateTime": number,
    //       "KmsKeyId": "string",
    //       "MultiAZ": boolean,
    //       "PendingModifiedValues": {
    //         "AllocatedStorage": number,
    //         "EngineVersion": "string",
    //         "MultiAZ": boolean,
    //         "ReplicationInstanceClass": "string"
    //       },
    //       "PreferredMaintenanceWindow": "string",
    //       "PubliclyAccessible": boolean,
    //       "ReplicationInstanceArn": "string",
    //       "ReplicationInstanceClass": "string",
    //       "ReplicationInstanceIdentifier": "string",
    //       "ReplicationInstancePrivateIpAddress": "string",
    //       "ReplicationInstancePrivateIpAddresses": [
    //         "string"
    //       ],
    //       "ReplicationInstancePublicIpAddress": "string",
    //       "ReplicationInstancePublicIpAddresses": [
    //         "string"
    //       ],
    //       "ReplicationInstanceStatus": "string",
    //       "ReplicationSubnetGroup": {
    //         "ReplicationSubnetGroupDescription": "string",
    //         "ReplicationSubnetGroupIdentifier": "string",
    //         "SubnetGroupStatus": "string",
    //         "Subnets": [
    //           {
    //             "SubnetAvailabilityZone": {
    //               "Name": "string"
    //             },
    //             "SubnetIdentifier": "string",
    //             "SubnetStatus": "string"
    //           }
    //         ],
    //         "VpcId": "string"
    //       },
    //       "SecondaryAvailabilityZone": "string",
    //       "VpcSecurityGroups": [
    //         {
    //           "Status": "string",
    //           "VpcSecurityGroupId": "string"
    //         }
    //       ]
    //     }
    //   ]
    // }


    CkRestW_Dispose(rest);
    CkAuthAwsW_Dispose(authAws);
    CkJsonObjectW_Dispose(json);
    CkStringBuilderW_Dispose(sbRequestBody);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }