Chilkat Online Tools

BatchGetDeploymentTargets PureBasic Example

AWS CodeDeploy

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkRest.pb"
IncludeFile "CkAuthAws.pb"

Procedure ChilkatExample()

    ; This example requires the Chilkat API to have been previously unlocked.
    ; See Global Unlock Sample for sample code.

    rest.i = CkRest::ckCreate()
    If rest.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    authAws.i = CkAuthAws::ckCreate()
    If authAws.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkAuthAws::setCkAccessKey(authAws, "AWS_ACCESS_KEY")
    CkAuthAws::setCkSecretKey(authAws, "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.)
    CkAuthAws::setCkRegion(authAws, "us-west-2")
    CkAuthAws::setCkServiceName(authAws, "codedeploy")
    ; SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    CkRest::ckSetAuthAws(rest,authAws)

    ; URL: https://codedeploy.us-west-2.amazonaws.com/
    ; Use the same region as specified above.
    success = CkRest::ckConnect(rest,"codedeploy.us-west-2.amazonaws.com",443,1,1)
    If success <> 1
        Debug "ConnectFailReason: " + Str(CkRest::ckConnectFailReason(rest))
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        CkAuthAws::ckDispose(authAws)
        ProcedureReturn
    EndIf

    ; 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.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(json,"deploymentId","string")
    CkJsonObject::ckUpdateString(json,"targetIds[0]","string")

    ; The JSON request body created by the above code:

    ; {
    ;   "deploymentId": "string",
    ;   "targetIds": [
    ;     "string"
    ;   ]
    ; }

    CkRest::ckAddHeader(rest,"Content-Type","application/x-amz-json-1.1")
    CkRest::ckAddHeader(rest,"X-Amz-Target","CodeDeploy_20141006.BatchGetDeploymentTargets")

    sbRequestBody.i = CkStringBuilder::ckCreate()
    If sbRequestBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckEmitSb(json,sbRequestBody)
    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkRest::ckFullRequestSb(rest,"POST","/",sbRequestBody,sbResponseBody)
    If success <> 1
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        CkAuthAws::ckDispose(authAws)
        CkJsonObject::ckDispose(json)
        CkStringBuilder::ckDispose(sbRequestBody)
        CkStringBuilder::ckDispose(sbResponseBody)
        ProcedureReturn
    EndIf

    respStatusCode.i = CkRest::ckResponseStatusCode(rest)
    Debug "response status code = " + Str(respStatusCode)
    If respStatusCode <> 200
        Debug "Response Header:"
        Debug CkRest::ckResponseHeader(rest)
        Debug "Response Body:"
        Debug CkStringBuilder::ckGetAsString(sbResponseBody)
        CkRest::ckDispose(rest)
        CkAuthAws::ckDispose(authAws)
        CkJsonObject::ckDispose(json)
        CkStringBuilder::ckDispose(sbRequestBody)
        CkStringBuilder::ckDispose(sbResponseBody)
        ProcedureReturn
    EndIf

    jResp.i = CkJsonObject::ckCreate()
    If jResp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(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

    DeploymentId.s
    LastUpdatedAt.i
    ResourceType.s
    Status.s
    TargetId.s
    TargetVersionWeight.i
    deploymentTargetType.s
    ecsTargetDeploymentId.s
    ecsTargetLastUpdatedAt.i
    ecsTargetStatus.s
    TargetArn.s
    ecsTargetTargetId.s
    instanceTargetDeploymentId.s
    InstanceLabel.s
    instanceTargetLastUpdatedAt.i
    instanceTargetStatus.s
    instanceTargetTargetArn.s
    instanceTargetTargetId.s
    lambdaTargetDeploymentId.s
    CurrentVersion.s
    FunctionAlias.s
    FunctionName.s
    TargetVersion.s
    LambdaFunctionInfoTargetVersionWeight.i
    lambdaTargetLastUpdatedAt.i
    lambdaTargetStatus.s
    lambdaTargetTargetArn.s
    lambdaTargetTargetId.s
    j.i
    count_j.i
    ErrorCode.s
    LogTail.s
    Message.s
    ScriptName.s
    endTime.i
    lifecycleEventName.s
    startTime.i
    status.s
    diagnosticsErrorCode.s
    diagnosticsLogTail.s
    diagnosticsMessage.s
    diagnosticsScriptName.s
    desiredCount.i
    identifer.s
    pendingCount.i
    runningCount.i
    Name.s
    taskSetLabel.s
    trafficWeight.i

    i.i = 0
    count_i.i = CkJsonObject::ckSizeOfArray(jResp,"deploymentTargets")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        DeploymentId = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].cloudFormationTarget.deploymentId")
        LastUpdatedAt = CkJsonObject::ckIntOf(jResp,"deploymentTargets[i].cloudFormationTarget.lastUpdatedAt")
        ResourceType = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].cloudFormationTarget.resourceType")
        Status = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].cloudFormationTarget.status")
        TargetId = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].cloudFormationTarget.targetId")
        TargetVersionWeight = CkJsonObject::ckIntOf(jResp,"deploymentTargets[i].cloudFormationTarget.targetVersionWeight")
        deploymentTargetType = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].deploymentTargetType")
        ecsTargetDeploymentId = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].ecsTarget.deploymentId")
        ecsTargetLastUpdatedAt = CkJsonObject::ckIntOf(jResp,"deploymentTargets[i].ecsTarget.lastUpdatedAt")
        ecsTargetStatus = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].ecsTarget.status")
        TargetArn = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].ecsTarget.targetArn")
        ecsTargetTargetId = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].ecsTarget.targetId")
        instanceTargetDeploymentId = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].instanceTarget.deploymentId")
        InstanceLabel = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].instanceTarget.instanceLabel")
        instanceTargetLastUpdatedAt = CkJsonObject::ckIntOf(jResp,"deploymentTargets[i].instanceTarget.lastUpdatedAt")
        instanceTargetStatus = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].instanceTarget.status")
        instanceTargetTargetArn = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].instanceTarget.targetArn")
        instanceTargetTargetId = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].instanceTarget.targetId")
        lambdaTargetDeploymentId = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].lambdaTarget.deploymentId")
        CurrentVersion = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].lambdaTarget.lambdaFunctionInfo.currentVersion")
        FunctionAlias = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].lambdaTarget.lambdaFunctionInfo.functionAlias")
        FunctionName = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].lambdaTarget.lambdaFunctionInfo.functionName")
        TargetVersion = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].lambdaTarget.lambdaFunctionInfo.targetVersion")
        LambdaFunctionInfoTargetVersionWeight = CkJsonObject::ckIntOf(jResp,"deploymentTargets[i].lambdaTarget.lambdaFunctionInfo.targetVersionWeight")
        lambdaTargetLastUpdatedAt = CkJsonObject::ckIntOf(jResp,"deploymentTargets[i].lambdaTarget.lastUpdatedAt")
        lambdaTargetStatus = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].lambdaTarget.status")
        lambdaTargetTargetArn = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].lambdaTarget.targetArn")
        lambdaTargetTargetId = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].lambdaTarget.targetId")
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"deploymentTargets[i].cloudFormationTarget.lifecycleEvents")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            ErrorCode = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].cloudFormationTarget.lifecycleEvents[j].diagnostics.errorCode")
            LogTail = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].cloudFormationTarget.lifecycleEvents[j].diagnostics.logTail")
            Message = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].cloudFormationTarget.lifecycleEvents[j].diagnostics.message")
            ScriptName = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].cloudFormationTarget.lifecycleEvents[j].diagnostics.scriptName")
            endTime = CkJsonObject::ckIntOf(jResp,"deploymentTargets[i].cloudFormationTarget.lifecycleEvents[j].endTime")
            lifecycleEventName = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].cloudFormationTarget.lifecycleEvents[j].lifecycleEventName")
            startTime = CkJsonObject::ckIntOf(jResp,"deploymentTargets[i].cloudFormationTarget.lifecycleEvents[j].startTime")
            status = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].cloudFormationTarget.lifecycleEvents[j].status")
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"deploymentTargets[i].ecsTarget.lifecycleEvents")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            diagnosticsErrorCode = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].ecsTarget.lifecycleEvents[j].diagnostics.errorCode")
            diagnosticsLogTail = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].ecsTarget.lifecycleEvents[j].diagnostics.logTail")
            diagnosticsMessage = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].ecsTarget.lifecycleEvents[j].diagnostics.message")
            diagnosticsScriptName = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].ecsTarget.lifecycleEvents[j].diagnostics.scriptName")
            endTime = CkJsonObject::ckIntOf(jResp,"deploymentTargets[i].ecsTarget.lifecycleEvents[j].endTime")
            lifecycleEventName = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].ecsTarget.lifecycleEvents[j].lifecycleEventName")
            startTime = CkJsonObject::ckIntOf(jResp,"deploymentTargets[i].ecsTarget.lifecycleEvents[j].startTime")
            status = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].ecsTarget.lifecycleEvents[j].status")
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"deploymentTargets[i].ecsTarget.taskSetsInfo")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            desiredCount = CkJsonObject::ckIntOf(jResp,"deploymentTargets[i].ecsTarget.taskSetsInfo[j].desiredCount")
            identifer = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].ecsTarget.taskSetsInfo[j].identifer")
            pendingCount = CkJsonObject::ckIntOf(jResp,"deploymentTargets[i].ecsTarget.taskSetsInfo[j].pendingCount")
            runningCount = CkJsonObject::ckIntOf(jResp,"deploymentTargets[i].ecsTarget.taskSetsInfo[j].runningCount")
            status = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].ecsTarget.taskSetsInfo[j].status")
            Name = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].ecsTarget.taskSetsInfo[j].targetGroup.name")
            taskSetLabel = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].ecsTarget.taskSetsInfo[j].taskSetLabel")
            trafficWeight = CkJsonObject::ckIntOf(jResp,"deploymentTargets[i].ecsTarget.taskSetsInfo[j].trafficWeight")
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"deploymentTargets[i].instanceTarget.lifecycleEvents")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            diagnosticsErrorCode = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].instanceTarget.lifecycleEvents[j].diagnostics.errorCode")
            diagnosticsLogTail = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].instanceTarget.lifecycleEvents[j].diagnostics.logTail")
            diagnosticsMessage = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].instanceTarget.lifecycleEvents[j].diagnostics.message")
            diagnosticsScriptName = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].instanceTarget.lifecycleEvents[j].diagnostics.scriptName")
            endTime = CkJsonObject::ckIntOf(jResp,"deploymentTargets[i].instanceTarget.lifecycleEvents[j].endTime")
            lifecycleEventName = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].instanceTarget.lifecycleEvents[j].lifecycleEventName")
            startTime = CkJsonObject::ckIntOf(jResp,"deploymentTargets[i].instanceTarget.lifecycleEvents[j].startTime")
            status = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].instanceTarget.lifecycleEvents[j].status")
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"deploymentTargets[i].lambdaTarget.lifecycleEvents")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            diagnosticsErrorCode = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].lambdaTarget.lifecycleEvents[j].diagnostics.errorCode")
            diagnosticsLogTail = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].lambdaTarget.lifecycleEvents[j].diagnostics.logTail")
            diagnosticsMessage = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].lambdaTarget.lifecycleEvents[j].diagnostics.message")
            diagnosticsScriptName = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].lambdaTarget.lifecycleEvents[j].diagnostics.scriptName")
            endTime = CkJsonObject::ckIntOf(jResp,"deploymentTargets[i].lambdaTarget.lifecycleEvents[j].endTime")
            lifecycleEventName = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].lambdaTarget.lifecycleEvents[j].lifecycleEventName")
            startTime = CkJsonObject::ckIntOf(jResp,"deploymentTargets[i].lambdaTarget.lifecycleEvents[j].startTime")
            status = CkJsonObject::ckStringOf(jResp,"deploymentTargets[i].lambdaTarget.lifecycleEvents[j].status")
            j = j + 1
        Wend
        i = i + 1
    Wend

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

    ; {
    ;   "deploymentTargets": [
    ;     {
    ;       "cloudFormationTarget": {
    ;         "deploymentId": "string",
    ;         "lastUpdatedAt": number,
    ;         "lifecycleEvents": [
    ;           {
    ;             "diagnostics": {
    ;               "errorCode": "string",
    ;               "logTail": "string",
    ;               "message": "string",
    ;               "scriptName": "string"
    ;             },
    ;             "endTime": number,
    ;             "lifecycleEventName": "string",
    ;             "startTime": number,
    ;             "status": "string"
    ;           }
    ;         ],
    ;         "resourceType": "string",
    ;         "status": "string",
    ;         "targetId": "string",
    ;         "targetVersionWeight": number
    ;       },
    ;       "deploymentTargetType": "string",
    ;       "ecsTarget": {
    ;         "deploymentId": "string",
    ;         "lastUpdatedAt": number,
    ;         "lifecycleEvents": [
    ;           {
    ;             "diagnostics": {
    ;               "errorCode": "string",
    ;               "logTail": "string",
    ;               "message": "string",
    ;               "scriptName": "string"
    ;             },
    ;             "endTime": number,
    ;             "lifecycleEventName": "string",
    ;             "startTime": number,
    ;             "status": "string"
    ;           }
    ;         ],
    ;         "status": "string",
    ;         "targetArn": "string",
    ;         "targetId": "string",
    ;         "taskSetsInfo": [
    ;           {
    ;             "desiredCount": number,
    ;             "identifer": "string",
    ;             "pendingCount": number,
    ;             "runningCount": number,
    ;             "status": "string",
    ;             "targetGroup": {
    ;               "name": "string"
    ;             },
    ;             "taskSetLabel": "string",
    ;             "trafficWeight": number
    ;           }
    ;         ]
    ;       },
    ;       "instanceTarget": {
    ;         "deploymentId": "string",
    ;         "instanceLabel": "string",
    ;         "lastUpdatedAt": number,
    ;         "lifecycleEvents": [
    ;           {
    ;             "diagnostics": {
    ;               "errorCode": "string",
    ;               "logTail": "string",
    ;               "message": "string",
    ;               "scriptName": "string"
    ;             },
    ;             "endTime": number,
    ;             "lifecycleEventName": "string",
    ;             "startTime": number,
    ;             "status": "string"
    ;           }
    ;         ],
    ;         "status": "string",
    ;         "targetArn": "string",
    ;         "targetId": "string"
    ;       },
    ;       "lambdaTarget": {
    ;         "deploymentId": "string",
    ;         "lambdaFunctionInfo": {
    ;           "currentVersion": "string",
    ;           "functionAlias": "string",
    ;           "functionName": "string",
    ;           "targetVersion": "string",
    ;           "targetVersionWeight": number
    ;         },
    ;         "lastUpdatedAt": number,
    ;         "lifecycleEvents": [
    ;           {
    ;             "diagnostics": {
    ;               "errorCode": "string",
    ;               "logTail": "string",
    ;               "message": "string",
    ;               "scriptName": "string"
    ;             },
    ;             "endTime": number,
    ;             "lifecycleEventName": "string",
    ;             "startTime": number,
    ;             "status": "string"
    ;           }
    ;         ],
    ;         "status": "string",
    ;         "targetArn": "string",
    ;         "targetId": "string"
    ;       }
    ;     }
    ;   ]
    ; }


    CkRest::ckDispose(rest)
    CkAuthAws::ckDispose(authAws)
    CkJsonObject::ckDispose(json)
    CkStringBuilder::ckDispose(sbRequestBody)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jResp)


    ProcedureReturn
EndProcedure