Chilkat Online Tools

CreateNodegroup unicodeCpp Example

Amazon Elastic Kubernetes Service

#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"eks");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.SetAuthAws(authAws);

    // URL: https://eks.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.Connect(L"eks.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"amiType",L"string");
    json.UpdateString(L"capacityType",L"string");
    json.UpdateString(L"clientRequestToken",L"string");
    json.UpdateInt(L"diskSize",123);
    json.UpdateString(L"instanceTypes[0]",L"string");
    json.UpdateString(L"labels.string",L"string");
    json.UpdateString(L"launchTemplate.id",L"string");
    json.UpdateString(L"launchTemplate.name",L"string");
    json.UpdateString(L"launchTemplate.version",L"string");
    json.UpdateString(L"nodegroupName",L"string");
    json.UpdateString(L"nodeRole",L"string");
    json.UpdateString(L"releaseVersion",L"string");
    json.UpdateString(L"remoteAccess.ec2SshKey",L"string");
    json.UpdateString(L"remoteAccess.sourceSecurityGroups[0]",L"string");
    json.UpdateInt(L"scalingConfig.desiredSize",123);
    json.UpdateInt(L"scalingConfig.maxSize",123);
    json.UpdateInt(L"scalingConfig.minSize",123);
    json.UpdateString(L"subnets[0]",L"string");
    json.UpdateString(L"tags.string",L"string");
    json.UpdateString(L"taints[0].effect",L"string");
    json.UpdateString(L"taints[0].key",L"string");
    json.UpdateString(L"taints[0].value",L"string");
    json.UpdateInt(L"updateConfig.maxUnavailable",123);
    json.UpdateInt(L"updateConfig.maxUnavailablePercentage",123);
    json.UpdateString(L"version",L"string");

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

    // {
    //   "amiType": "string",
    //   "capacityType": "string",
    //   "clientRequestToken": "string",
    //   "diskSize": number,
    //   "instanceTypes": [
    //     "string"
    //   ],
    //   "labels": {
    //     "string": "string"
    //   },
    //   "launchTemplate": {
    //     "id": "string",
    //     "name": "string",
    //     "version": "string"
    //   },
    //   "nodegroupName": "string",
    //   "nodeRole": "string",
    //   "releaseVersion": "string",
    //   "remoteAccess": {
    //     "ec2SshKey": "string",
    //     "sourceSecurityGroups": [
    //       "string"
    //     ]
    //   },
    //   "scalingConfig": {
    //     "desiredSize": number,
    //     "maxSize": number,
    //     "minSize": number
    //   },
    //   "subnets": [
    //     "string"
    //   ],
    //   "tags": {
    //     "string": "string"
    //   },
    //   "taints": [
    //     {
    //       "effect": "string",
    //       "key": "string",
    //       "value": "string"
    //     }
    //   ],
    //   "updateConfig": {
    //     "maxUnavailable": number,
    //     "maxUnavailablePercentage": number
    //   },
    //   "version": "string"
    // }

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

    CkStringBuilderW sbRequestBody;
    json.EmitSb(sbRequestBody);
    CkStringBuilderW sbResponseBody;
    success = rest.FullRequestSb(L"POST",L"/clusters/{name}/node-groups",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 *code = 0;
    const wchar_t *message = 0;
    int j;
    int count_j;
    const wchar_t *strVal = 0;
    const wchar_t *name = 0;
    const wchar_t *effect = 0;
    const wchar_t *key = 0;
    const wchar_t *value = 0;

    const wchar_t *AmiType = jResp.stringOf(L"nodegroup.amiType");
    const wchar_t *CapacityType = jResp.stringOf(L"nodegroup.capacityType");
    const wchar_t *ClusterName = jResp.stringOf(L"nodegroup.clusterName");
    int CreatedAt = jResp.IntOf(L"nodegroup.createdAt");
    int DiskSize = jResp.IntOf(L"nodegroup.diskSize");
    const wchar_t *v_String = jResp.stringOf(L"nodegroup.labels.string");
    const wchar_t *Id = jResp.stringOf(L"nodegroup.launchTemplate.id");
    const wchar_t *Name = jResp.stringOf(L"nodegroup.launchTemplate.name");
    const wchar_t *Version = jResp.stringOf(L"nodegroup.launchTemplate.version");
    int ModifiedAt = jResp.IntOf(L"nodegroup.modifiedAt");
    const wchar_t *NodegroupArn = jResp.stringOf(L"nodegroup.nodegroupArn");
    const wchar_t *NodegroupName = jResp.stringOf(L"nodegroup.nodegroupName");
    const wchar_t *NodeRole = jResp.stringOf(L"nodegroup.nodeRole");
    const wchar_t *ReleaseVersion = jResp.stringOf(L"nodegroup.releaseVersion");
    const wchar_t *Ec2SshKey = jResp.stringOf(L"nodegroup.remoteAccess.ec2SshKey");
    const wchar_t *RemoteAccessSecurityGroup = jResp.stringOf(L"nodegroup.resources.remoteAccessSecurityGroup");
    int DesiredSize = jResp.IntOf(L"nodegroup.scalingConfig.desiredSize");
    int MaxSize = jResp.IntOf(L"nodegroup.scalingConfig.maxSize");
    int MinSize = jResp.IntOf(L"nodegroup.scalingConfig.minSize");
    const wchar_t *Status = jResp.stringOf(L"nodegroup.status");
    const wchar_t *TagsString = jResp.stringOf(L"nodegroup.tags.string");
    int MaxUnavailable = jResp.IntOf(L"nodegroup.updateConfig.maxUnavailable");
    int MaxUnavailablePercentage = jResp.IntOf(L"nodegroup.updateConfig.maxUnavailablePercentage");
    const wchar_t *nodegroupVersion = jResp.stringOf(L"nodegroup.version");
    int i = 0;
    int count_i = jResp.SizeOfArray(L"nodegroup.health.issues");
    while (i < count_i) {
        jResp.put_I(i);
        code = jResp.stringOf(L"nodegroup.health.issues[i].code");
        message = jResp.stringOf(L"nodegroup.health.issues[i].message");
        j = 0;
        count_j = jResp.SizeOfArray(L"nodegroup.health.issues[i].resourceIds");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf(L"nodegroup.health.issues[i].resourceIds[j]");
            j = j + 1;
        }

        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"nodegroup.instanceTypes");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf(L"nodegroup.instanceTypes[i]");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"nodegroup.remoteAccess.sourceSecurityGroups");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf(L"nodegroup.remoteAccess.sourceSecurityGroups[i]");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"nodegroup.resources.autoScalingGroups");
    while (i < count_i) {
        jResp.put_I(i);
        name = jResp.stringOf(L"nodegroup.resources.autoScalingGroups[i].name");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"nodegroup.subnets");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf(L"nodegroup.subnets[i]");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"nodegroup.taints");
    while (i < count_i) {
        jResp.put_I(i);
        effect = jResp.stringOf(L"nodegroup.taints[i].effect");
        key = jResp.stringOf(L"nodegroup.taints[i].key");
        value = jResp.stringOf(L"nodegroup.taints[i].value");
        i = i + 1;
    }

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

    // {
    //   "nodegroup": {
    //     "amiType": "string",
    //     "capacityType": "string",
    //     "clusterName": "string",
    //     "createdAt": number,
    //     "diskSize": number,
    //     "health": {
    //       "issues": [
    //         {
    //           "code": "string",
    //           "message": "string",
    //           "resourceIds": [
    //             "string"
    //           ]
    //         }
    //       ]
    //     },
    //     "instanceTypes": [
    //       "string"
    //     ],
    //     "labels": {
    //       "string": "string"
    //     },
    //     "launchTemplate": {
    //       "id": "string",
    //       "name": "string",
    //       "version": "string"
    //     },
    //     "modifiedAt": number,
    //     "nodegroupArn": "string",
    //     "nodegroupName": "string",
    //     "nodeRole": "string",
    //     "releaseVersion": "string",
    //     "remoteAccess": {
    //       "ec2SshKey": "string",
    //       "sourceSecurityGroups": [
    //         "string"
    //       ]
    //     },
    //     "resources": {
    //       "autoScalingGroups": [
    //         {
    //           "name": "string"
    //         }
    //       ],
    //       "remoteAccessSecurityGroup": "string"
    //     },
    //     "scalingConfig": {
    //       "desiredSize": number,
    //       "maxSize": number,
    //       "minSize": number
    //     },
    //     "status": "string",
    //     "subnets": [
    //       "string"
    //     ],
    //     "tags": {
    //       "string": "string"
    //     },
    //     "taints": [
    //       {
    //         "effect": "string",
    //         "key": "string",
    //         "value": "string"
    //       }
    //     ],
    //     "updateConfig": {
    //       "maxUnavailable": number,
    //       "maxUnavailablePercentage": number
    //     },
    //     "version": "string"
    //   }
    // }
    }