Chilkat Online Tools

ModifyReplicationInstance 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;
    const wchar_t *strVal;
    const wchar_t *Name;
    const wchar_t *SubnetIdentifier;
    const wchar_t *SubnetStatus;
    const wchar_t *Status;
    const wchar_t *VpcSecurityGroupId;
    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 *ReplicationInstanceReplicationInstanceClass;
    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 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_UpdateInt(json,L"AllocatedStorage",123);
    CkJsonObjectW_UpdateInt(json,L"AllowMajorVersionUpgrade",123);
    CkJsonObjectW_UpdateInt(json,L"ApplyImmediately",123);
    CkJsonObjectW_UpdateInt(json,L"AutoMinorVersionUpgrade",123);
    CkJsonObjectW_UpdateString(json,L"EngineVersion",L"string");
    CkJsonObjectW_UpdateInt(json,L"MultiAZ",123);
    CkJsonObjectW_UpdateString(json,L"PreferredMaintenanceWindow",L"string");
    CkJsonObjectW_UpdateString(json,L"ReplicationInstanceArn",L"string");
    CkJsonObjectW_UpdateString(json,L"ReplicationInstanceClass",L"string");
    CkJsonObjectW_UpdateString(json,L"ReplicationInstanceIdentifier",L"string");
    CkJsonObjectW_UpdateString(json,L"VpcSecurityGroupIds[0]",L"string");

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

    // {
    //   "AllocatedStorage": number,
    //   "AllowMajorVersionUpgrade": boolean,
    //   "ApplyImmediately": boolean,
    //   "AutoMinorVersionUpgrade": boolean,
    //   "EngineVersion": "string",
    //   "MultiAZ": boolean,
    //   "PreferredMaintenanceWindow": "string",
    //   "ReplicationInstanceArn": "string",
    //   "ReplicationInstanceClass": "string",
    //   "ReplicationInstanceIdentifier": "string",
    //   "VpcSecurityGroupIds": [
    //     "string"
    //   ]
    // }

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

    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.

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

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"ReplicationInstance.ReplicationInstancePublicIpAddresses");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        strVal = CkJsonObjectW_stringOf(jResp,L"ReplicationInstance.ReplicationInstancePublicIpAddresses[i]");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"ReplicationInstance.ReplicationSubnetGroup.Subnets");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        Name = CkJsonObjectW_stringOf(jResp,L"ReplicationInstance.ReplicationSubnetGroup.Subnets[i].SubnetAvailabilityZone.Name");
        SubnetIdentifier = CkJsonObjectW_stringOf(jResp,L"ReplicationInstance.ReplicationSubnetGroup.Subnets[i].SubnetIdentifier");
        SubnetStatus = CkJsonObjectW_stringOf(jResp,L"ReplicationInstance.ReplicationSubnetGroup.Subnets[i].SubnetStatus");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"ReplicationInstance.VpcSecurityGroups");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        Status = CkJsonObjectW_stringOf(jResp,L"ReplicationInstance.VpcSecurityGroups[i].Status");
        VpcSecurityGroupId = CkJsonObjectW_stringOf(jResp,L"ReplicationInstance.VpcSecurityGroups[i].VpcSecurityGroupId");
        i = i + 1;
    }

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

    // {
    //   "ReplicationInstance": {
    //     "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);

    }