Chilkat Online Tools

BatchGetDeploymentTargets Swift3 Example

AWS CodeDeploy

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

    let rest = CkoRest()!
    var success: Bool

    let authAws = CkoAuthAws()!
    authAws.accessKey = "AWS_ACCESS_KEY"
    authAws.secretKey = "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.region = "us-west-2"
    authAws.serviceName = "codedeploy"
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.setAuthAws(authAws)

    // URL: https://codedeploy.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.connect("codedeploy.us-west-2.amazonaws.com", port: 443, tls: true, autoReconnect: true)
    if success != true {
        print("ConnectFailReason: \(rest.connectFailReason.intValue)")
        print("\(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

    let json = CkoJsonObject()!
    json.update("deploymentId", value: "string")
    json.update("targetIds[0]", value: "string")

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

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

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

    let sbRequestBody = CkoStringBuilder()!
    json.emitSb(sbRequestBody)
    let sbResponseBody = CkoStringBuilder()!
    success = rest.fullRequestSb("POST", uriPath: "/", requestBody: sbRequestBody, responseBody: sbResponseBody)
    if success != true {
        print("\(rest.lastErrorText!)")
        return
    }

    var respStatusCode: Int = rest.responseStatusCode.intValue
    print("response status code = \(respStatusCode)")
    if respStatusCode != 200 {
        print("Response Header:")
        print("\(rest.responseHeader!)")
        print("Response Body:")
        print("\(sbResponseBody.getAsString()!)")
        return
    }

    let jResp = CkoJsonObject()!
    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

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

    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "deploymentTargets").intValue
    while i < count_i {
        jResp.i = i
        DeploymentId = jResp.string(of: "deploymentTargets[i].cloudFormationTarget.deploymentId")
        LastUpdatedAt = jResp.int(of: "deploymentTargets[i].cloudFormationTarget.lastUpdatedAt").intValue
        ResourceType = jResp.string(of: "deploymentTargets[i].cloudFormationTarget.resourceType")
        Status = jResp.string(of: "deploymentTargets[i].cloudFormationTarget.status")
        TargetId = jResp.string(of: "deploymentTargets[i].cloudFormationTarget.targetId")
        TargetVersionWeight = jResp.int(of: "deploymentTargets[i].cloudFormationTarget.targetVersionWeight").intValue
        deploymentTargetType = jResp.string(of: "deploymentTargets[i].deploymentTargetType")
        ecsTargetDeploymentId = jResp.string(of: "deploymentTargets[i].ecsTarget.deploymentId")
        ecsTargetLastUpdatedAt = jResp.int(of: "deploymentTargets[i].ecsTarget.lastUpdatedAt").intValue
        ecsTargetStatus = jResp.string(of: "deploymentTargets[i].ecsTarget.status")
        TargetArn = jResp.string(of: "deploymentTargets[i].ecsTarget.targetArn")
        ecsTargetTargetId = jResp.string(of: "deploymentTargets[i].ecsTarget.targetId")
        instanceTargetDeploymentId = jResp.string(of: "deploymentTargets[i].instanceTarget.deploymentId")
        InstanceLabel = jResp.string(of: "deploymentTargets[i].instanceTarget.instanceLabel")
        instanceTargetLastUpdatedAt = jResp.int(of: "deploymentTargets[i].instanceTarget.lastUpdatedAt").intValue
        instanceTargetStatus = jResp.string(of: "deploymentTargets[i].instanceTarget.status")
        instanceTargetTargetArn = jResp.string(of: "deploymentTargets[i].instanceTarget.targetArn")
        instanceTargetTargetId = jResp.string(of: "deploymentTargets[i].instanceTarget.targetId")
        lambdaTargetDeploymentId = jResp.string(of: "deploymentTargets[i].lambdaTarget.deploymentId")
        CurrentVersion = jResp.string(of: "deploymentTargets[i].lambdaTarget.lambdaFunctionInfo.currentVersion")
        FunctionAlias = jResp.string(of: "deploymentTargets[i].lambdaTarget.lambdaFunctionInfo.functionAlias")
        FunctionName = jResp.string(of: "deploymentTargets[i].lambdaTarget.lambdaFunctionInfo.functionName")
        TargetVersion = jResp.string(of: "deploymentTargets[i].lambdaTarget.lambdaFunctionInfo.targetVersion")
        LambdaFunctionInfoTargetVersionWeight = jResp.int(of: "deploymentTargets[i].lambdaTarget.lambdaFunctionInfo.targetVersionWeight").intValue
        lambdaTargetLastUpdatedAt = jResp.int(of: "deploymentTargets[i].lambdaTarget.lastUpdatedAt").intValue
        lambdaTargetStatus = jResp.string(of: "deploymentTargets[i].lambdaTarget.status")
        lambdaTargetTargetArn = jResp.string(of: "deploymentTargets[i].lambdaTarget.targetArn")
        lambdaTargetTargetId = jResp.string(of: "deploymentTargets[i].lambdaTarget.targetId")
        j = 0
        count_j = jResp.size(ofArray: "deploymentTargets[i].cloudFormationTarget.lifecycleEvents").intValue
        while j < count_j {
            jResp.j = j
            ErrorCode = jResp.string(of: "deploymentTargets[i].cloudFormationTarget.lifecycleEvents[j].diagnostics.errorCode")
            LogTail = jResp.string(of: "deploymentTargets[i].cloudFormationTarget.lifecycleEvents[j].diagnostics.logTail")
            Message = jResp.string(of: "deploymentTargets[i].cloudFormationTarget.lifecycleEvents[j].diagnostics.message")
            ScriptName = jResp.string(of: "deploymentTargets[i].cloudFormationTarget.lifecycleEvents[j].diagnostics.scriptName")
            endTime = jResp.int(of: "deploymentTargets[i].cloudFormationTarget.lifecycleEvents[j].endTime").intValue
            lifecycleEventName = jResp.string(of: "deploymentTargets[i].cloudFormationTarget.lifecycleEvents[j].lifecycleEventName")
            startTime = jResp.int(of: "deploymentTargets[i].cloudFormationTarget.lifecycleEvents[j].startTime").intValue
            status = jResp.string(of: "deploymentTargets[i].cloudFormationTarget.lifecycleEvents[j].status")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "deploymentTargets[i].ecsTarget.lifecycleEvents").intValue
        while j < count_j {
            jResp.j = j
            diagnosticsErrorCode = jResp.string(of: "deploymentTargets[i].ecsTarget.lifecycleEvents[j].diagnostics.errorCode")
            diagnosticsLogTail = jResp.string(of: "deploymentTargets[i].ecsTarget.lifecycleEvents[j].diagnostics.logTail")
            diagnosticsMessage = jResp.string(of: "deploymentTargets[i].ecsTarget.lifecycleEvents[j].diagnostics.message")
            diagnosticsScriptName = jResp.string(of: "deploymentTargets[i].ecsTarget.lifecycleEvents[j].diagnostics.scriptName")
            endTime = jResp.int(of: "deploymentTargets[i].ecsTarget.lifecycleEvents[j].endTime").intValue
            lifecycleEventName = jResp.string(of: "deploymentTargets[i].ecsTarget.lifecycleEvents[j].lifecycleEventName")
            startTime = jResp.int(of: "deploymentTargets[i].ecsTarget.lifecycleEvents[j].startTime").intValue
            status = jResp.string(of: "deploymentTargets[i].ecsTarget.lifecycleEvents[j].status")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "deploymentTargets[i].ecsTarget.taskSetsInfo").intValue
        while j < count_j {
            jResp.j = j
            desiredCount = jResp.int(of: "deploymentTargets[i].ecsTarget.taskSetsInfo[j].desiredCount").intValue
            identifer = jResp.string(of: "deploymentTargets[i].ecsTarget.taskSetsInfo[j].identifer")
            pendingCount = jResp.int(of: "deploymentTargets[i].ecsTarget.taskSetsInfo[j].pendingCount").intValue
            runningCount = jResp.int(of: "deploymentTargets[i].ecsTarget.taskSetsInfo[j].runningCount").intValue
            status = jResp.string(of: "deploymentTargets[i].ecsTarget.taskSetsInfo[j].status")
            Name = jResp.string(of: "deploymentTargets[i].ecsTarget.taskSetsInfo[j].targetGroup.name")
            taskSetLabel = jResp.string(of: "deploymentTargets[i].ecsTarget.taskSetsInfo[j].taskSetLabel")
            trafficWeight = jResp.int(of: "deploymentTargets[i].ecsTarget.taskSetsInfo[j].trafficWeight").intValue
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "deploymentTargets[i].instanceTarget.lifecycleEvents").intValue
        while j < count_j {
            jResp.j = j
            diagnosticsErrorCode = jResp.string(of: "deploymentTargets[i].instanceTarget.lifecycleEvents[j].diagnostics.errorCode")
            diagnosticsLogTail = jResp.string(of: "deploymentTargets[i].instanceTarget.lifecycleEvents[j].diagnostics.logTail")
            diagnosticsMessage = jResp.string(of: "deploymentTargets[i].instanceTarget.lifecycleEvents[j].diagnostics.message")
            diagnosticsScriptName = jResp.string(of: "deploymentTargets[i].instanceTarget.lifecycleEvents[j].diagnostics.scriptName")
            endTime = jResp.int(of: "deploymentTargets[i].instanceTarget.lifecycleEvents[j].endTime").intValue
            lifecycleEventName = jResp.string(of: "deploymentTargets[i].instanceTarget.lifecycleEvents[j].lifecycleEventName")
            startTime = jResp.int(of: "deploymentTargets[i].instanceTarget.lifecycleEvents[j].startTime").intValue
            status = jResp.string(of: "deploymentTargets[i].instanceTarget.lifecycleEvents[j].status")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "deploymentTargets[i].lambdaTarget.lifecycleEvents").intValue
        while j < count_j {
            jResp.j = j
            diagnosticsErrorCode = jResp.string(of: "deploymentTargets[i].lambdaTarget.lifecycleEvents[j].diagnostics.errorCode")
            diagnosticsLogTail = jResp.string(of: "deploymentTargets[i].lambdaTarget.lifecycleEvents[j].diagnostics.logTail")
            diagnosticsMessage = jResp.string(of: "deploymentTargets[i].lambdaTarget.lifecycleEvents[j].diagnostics.message")
            diagnosticsScriptName = jResp.string(of: "deploymentTargets[i].lambdaTarget.lifecycleEvents[j].diagnostics.scriptName")
            endTime = jResp.int(of: "deploymentTargets[i].lambdaTarget.lifecycleEvents[j].endTime").intValue
            lifecycleEventName = jResp.string(of: "deploymentTargets[i].lambdaTarget.lifecycleEvents[j].lifecycleEventName")
            startTime = jResp.int(of: "deploymentTargets[i].lambdaTarget.lifecycleEvents[j].startTime").intValue
            status = jResp.string(of: "deploymentTargets[i].lambdaTarget.lifecycleEvents[j].status")
            j = j + 1
        }

        i = i + 1
    }

    // 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"
    //       }
    //     }
    //   ]
    // }

}