Chilkat Online Tools

BatchGetDeployments TCL Example

AWS CodeDeploy

load ./chilkat.dll

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

set rest [new_CkRest]

set authAws [new_CkAuthAws]

CkAuthAws_put_AccessKey $authAws "AWS_ACCESS_KEY"
CkAuthAws_put_SecretKey $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_put_Region $authAws "us-west-2"
CkAuthAws_put_ServiceName $authAws "codedeploy"
# SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
CkRest_SetAuthAws $rest $authAws

# URL: https://codedeploy.us-west-2.amazonaws.com/
# Use the same region as specified above.
set success [CkRest_Connect $rest "codedeploy.us-west-2.amazonaws.com" 443 1 1]
if {$success != 1} then {
    puts "ConnectFailReason: [CkRest_get_ConnectFailReason $rest]"
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkAuthAws $authAws
    exit
}

# 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

set json [new_CkJsonObject]

CkJsonObject_UpdateString $json "deploymentIds[0]" "string"

# The JSON request body created by the above code:

# {
#   "deploymentIds": [
#     "string"
#   ]
# }

CkRest_AddHeader $rest "Content-Type" "application/x-amz-json-1.1"
CkRest_AddHeader $rest "X-Amz-Target" "CodeDeploy_20141006.BatchGetDeployments"

set sbRequestBody [new_CkStringBuilder]

CkJsonObject_EmitSb $json $sbRequestBody
set sbResponseBody [new_CkStringBuilder]

set success [CkRest_FullRequestSb $rest "POST" "/" $sbRequestBody $sbResponseBody]
if {$success != 1} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkAuthAws $authAws
    delete_CkJsonObject $json
    delete_CkStringBuilder $sbRequestBody
    delete_CkStringBuilder $sbResponseBody
    exit
}

set respStatusCode [CkRest_get_ResponseStatusCode $rest]
puts "response status code = $respStatusCode"
if {$respStatusCode != 200} then {
    puts "Response Header:"
    puts [CkRest_responseHeader $rest]
    puts "Response Body:"
    puts [CkStringBuilder_getAsString $sbResponseBody]
    delete_CkRest $rest
    delete_CkAuthAws $authAws
    delete_CkJsonObject $json
    delete_CkStringBuilder $sbRequestBody
    delete_CkStringBuilder $sbResponseBody
    exit
}

set jResp [new_CkJsonObject]

CkJsonObject_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

set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "deploymentsInfo"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set additionalDeploymentStatusInfo [CkJsonObject_stringOf $jResp "deploymentsInfo[i].additionalDeploymentStatusInfo"]
    set applicationName [CkJsonObject_stringOf $jResp "deploymentsInfo[i].applicationName"]
    set Enabled [CkJsonObject_IntOf $jResp "deploymentsInfo[i].autoRollbackConfiguration.enabled"]
    set ActionOnTimeout [CkJsonObject_stringOf $jResp "deploymentsInfo[i].blueGreenDeploymentConfiguration.deploymentReadyOption.actionOnTimeout"]
    set WaitTimeInMinutes [CkJsonObject_IntOf $jResp "deploymentsInfo[i].blueGreenDeploymentConfiguration.deploymentReadyOption.waitTimeInMinutes"]
    set Action [CkJsonObject_stringOf $jResp "deploymentsInfo[i].blueGreenDeploymentConfiguration.greenFleetProvisioningOption.action"]
    set TerminateBlueInstancesOnDeploymentSuccessAction [CkJsonObject_stringOf $jResp "deploymentsInfo[i].blueGreenDeploymentConfiguration.terminateBlueInstancesOnDeploymentSuccess.action"]
    set TerminationWaitTimeInMinutes [CkJsonObject_IntOf $jResp "deploymentsInfo[i].blueGreenDeploymentConfiguration.terminateBlueInstancesOnDeploymentSuccess.terminationWaitTimeInMinutes"]
    set completeTime [CkJsonObject_IntOf $jResp "deploymentsInfo[i].completeTime"]
    set computePlatform [CkJsonObject_stringOf $jResp "deploymentsInfo[i].computePlatform"]
    set createTime [CkJsonObject_IntOf $jResp "deploymentsInfo[i].createTime"]
    set creator [CkJsonObject_stringOf $jResp "deploymentsInfo[i].creator"]
    set deploymentConfigName [CkJsonObject_stringOf $jResp "deploymentsInfo[i].deploymentConfigName"]
    set deploymentGroupName [CkJsonObject_stringOf $jResp "deploymentsInfo[i].deploymentGroupName"]
    set deploymentId [CkJsonObject_stringOf $jResp "deploymentsInfo[i].deploymentId"]
    set Failed [CkJsonObject_IntOf $jResp "deploymentsInfo[i].deploymentOverview.Failed"]
    set InProgress [CkJsonObject_IntOf $jResp "deploymentsInfo[i].deploymentOverview.InProgress"]
    set Pending [CkJsonObject_IntOf $jResp "deploymentsInfo[i].deploymentOverview.Pending"]
    set Ready [CkJsonObject_IntOf $jResp "deploymentsInfo[i].deploymentOverview.Ready"]
    set Skipped [CkJsonObject_IntOf $jResp "deploymentsInfo[i].deploymentOverview.Skipped"]
    set Succeeded [CkJsonObject_IntOf $jResp "deploymentsInfo[i].deploymentOverview.Succeeded"]
    set DeploymentOption [CkJsonObject_stringOf $jResp "deploymentsInfo[i].deploymentStyle.deploymentOption"]
    set DeploymentType [CkJsonObject_stringOf $jResp "deploymentsInfo[i].deploymentStyle.deploymentType"]
    set description [CkJsonObject_stringOf $jResp "deploymentsInfo[i].description"]
    set Code [CkJsonObject_stringOf $jResp "deploymentsInfo[i].errorInformation.code"]
    set Message [CkJsonObject_stringOf $jResp "deploymentsInfo[i].errorInformation.message"]
    set externalId [CkJsonObject_stringOf $jResp "deploymentsInfo[i].externalId"]
    set fileExistsBehavior [CkJsonObject_stringOf $jResp "deploymentsInfo[i].fileExistsBehavior"]
    set ignoreApplicationStopFailures [CkJsonObject_IntOf $jResp "deploymentsInfo[i].ignoreApplicationStopFailures"]
    set instanceTerminationWaitTimeStarted [CkJsonObject_IntOf $jResp "deploymentsInfo[i].instanceTerminationWaitTimeStarted"]
    set Content [CkJsonObject_stringOf $jResp "deploymentsInfo[i].previousRevision.appSpecContent.content"]
    set Sha256 [CkJsonObject_stringOf $jResp "deploymentsInfo[i].previousRevision.appSpecContent.sha256"]
    set CommitId [CkJsonObject_stringOf $jResp "deploymentsInfo[i].previousRevision.gitHubLocation.commitId"]
    set Repository [CkJsonObject_stringOf $jResp "deploymentsInfo[i].previousRevision.gitHubLocation.repository"]
    set RevisionType [CkJsonObject_stringOf $jResp "deploymentsInfo[i].previousRevision.revisionType"]
    set Bucket [CkJsonObject_stringOf $jResp "deploymentsInfo[i].previousRevision.s3Location.bucket"]
    set BundleType [CkJsonObject_stringOf $jResp "deploymentsInfo[i].previousRevision.s3Location.bundleType"]
    set ETag [CkJsonObject_stringOf $jResp "deploymentsInfo[i].previousRevision.s3Location.eTag"]
    set Key [CkJsonObject_stringOf $jResp "deploymentsInfo[i].previousRevision.s3Location.key"]
    set Version [CkJsonObject_stringOf $jResp "deploymentsInfo[i].previousRevision.s3Location.version"]
    set StringContent [CkJsonObject_stringOf $jResp "deploymentsInfo[i].previousRevision.string.content"]
    set StringSha256 [CkJsonObject_stringOf $jResp "deploymentsInfo[i].previousRevision.string.sha256"]
    set AutoUpdateOutdatedInstancesRootDeploymentId [CkJsonObject_stringOf $jResp "deploymentsInfo[i].relatedDeployments.autoUpdateOutdatedInstancesRootDeploymentId"]
    set AppSpecContentContent [CkJsonObject_stringOf $jResp "deploymentsInfo[i].revision.appSpecContent.content"]
    set AppSpecContentSha256 [CkJsonObject_stringOf $jResp "deploymentsInfo[i].revision.appSpecContent.sha256"]
    set GitHubLocationCommitId [CkJsonObject_stringOf $jResp "deploymentsInfo[i].revision.gitHubLocation.commitId"]
    set GitHubLocationRepository [CkJsonObject_stringOf $jResp "deploymentsInfo[i].revision.gitHubLocation.repository"]
    set revisionRevisionType [CkJsonObject_stringOf $jResp "deploymentsInfo[i].revision.revisionType"]
    set S3LocationBucket [CkJsonObject_stringOf $jResp "deploymentsInfo[i].revision.s3Location.bucket"]
    set S3LocationBundleType [CkJsonObject_stringOf $jResp "deploymentsInfo[i].revision.s3Location.bundleType"]
    set S3LocationETag [CkJsonObject_stringOf $jResp "deploymentsInfo[i].revision.s3Location.eTag"]
    set S3LocationKey [CkJsonObject_stringOf $jResp "deploymentsInfo[i].revision.s3Location.key"]
    set S3LocationVersion [CkJsonObject_stringOf $jResp "deploymentsInfo[i].revision.s3Location.version"]
    set StringContent [CkJsonObject_stringOf $jResp "deploymentsInfo[i].revision.string.content"]
    set StringSha256 [CkJsonObject_stringOf $jResp "deploymentsInfo[i].revision.string.sha256"]
    set RollbackDeploymentId [CkJsonObject_stringOf $jResp "deploymentsInfo[i].rollbackInfo.rollbackDeploymentId"]
    set RollbackMessage [CkJsonObject_stringOf $jResp "deploymentsInfo[i].rollbackInfo.rollbackMessage"]
    set RollbackTriggeringDeploymentId [CkJsonObject_stringOf $jResp "deploymentsInfo[i].rollbackInfo.rollbackTriggeringDeploymentId"]
    set startTime [CkJsonObject_IntOf $jResp "deploymentsInfo[i].startTime"]
    set status [CkJsonObject_stringOf $jResp "deploymentsInfo[i].status"]
    set updateOutdatedInstancesOnly [CkJsonObject_IntOf $jResp "deploymentsInfo[i].updateOutdatedInstancesOnly"]
    set j 0
    set count_j [CkJsonObject_SizeOfArray $jResp "deploymentsInfo[i].autoRollbackConfiguration.events"]
    while {$j < $count_j} {
        CkJsonObject_put_J $jResp $j
        set strVal [CkJsonObject_stringOf $jResp "deploymentsInfo[i].autoRollbackConfiguration.events[j]"]
        set j [expr $j + 1]
    }
    set j 0
    set count_j [CkJsonObject_SizeOfArray $jResp "deploymentsInfo[i].deploymentStatusMessages"]
    while {$j < $count_j} {
        CkJsonObject_put_J $jResp $j
        set strVal [CkJsonObject_stringOf $jResp "deploymentsInfo[i].deploymentStatusMessages[j]"]
        set j [expr $j + 1]
    }
    set j 0
    set count_j [CkJsonObject_SizeOfArray $jResp "deploymentsInfo[i].loadBalancerInfo.elbInfoList"]
    while {$j < $count_j} {
        CkJsonObject_put_J $jResp $j
        set name [CkJsonObject_stringOf $jResp "deploymentsInfo[i].loadBalancerInfo.elbInfoList[j].name"]
        set j [expr $j + 1]
    }
    set j 0
    set count_j [CkJsonObject_SizeOfArray $jResp "deploymentsInfo[i].loadBalancerInfo.targetGroupInfoList"]
    while {$j < $count_j} {
        CkJsonObject_put_J $jResp $j
        set name [CkJsonObject_stringOf $jResp "deploymentsInfo[i].loadBalancerInfo.targetGroupInfoList[j].name"]
        set j [expr $j + 1]
    }
    set j 0
    set count_j [CkJsonObject_SizeOfArray $jResp "deploymentsInfo[i].loadBalancerInfo.targetGroupPairInfoList"]
    while {$j < $count_j} {
        CkJsonObject_put_J $jResp $j
        set k 0
        set count_k [CkJsonObject_SizeOfArray $jResp "deploymentsInfo[i].loadBalancerInfo.targetGroupPairInfoList[j].prodTrafficRoute.listenerArns"]
        while {$k < $count_k} {
            CkJsonObject_put_K $jResp $k
            set strVal [CkJsonObject_stringOf $jResp "deploymentsInfo[i].loadBalancerInfo.targetGroupPairInfoList[j].prodTrafficRoute.listenerArns[k]"]
            set k [expr $k + 1]
        }
        set k 0
        set count_k [CkJsonObject_SizeOfArray $jResp "deploymentsInfo[i].loadBalancerInfo.targetGroupPairInfoList[j].targetGroups"]
        while {$k < $count_k} {
            CkJsonObject_put_K $jResp $k
            set name [CkJsonObject_stringOf $jResp "deploymentsInfo[i].loadBalancerInfo.targetGroupPairInfoList[j].targetGroups[k].name"]
            set k [expr $k + 1]
        }
        set k 0
        set count_k [CkJsonObject_SizeOfArray $jResp "deploymentsInfo[i].loadBalancerInfo.targetGroupPairInfoList[j].testTrafficRoute.listenerArns"]
        while {$k < $count_k} {
            CkJsonObject_put_K $jResp $k
            set strVal [CkJsonObject_stringOf $jResp "deploymentsInfo[i].loadBalancerInfo.targetGroupPairInfoList[j].testTrafficRoute.listenerArns[k]"]
            set k [expr $k + 1]
        }
        set j [expr $j + 1]
    }
    set j 0
    set count_j [CkJsonObject_SizeOfArray $jResp "deploymentsInfo[i].relatedDeployments.autoUpdateOutdatedInstancesDeploymentIds"]
    while {$j < $count_j} {
        CkJsonObject_put_J $jResp $j
        set strVal [CkJsonObject_stringOf $jResp "deploymentsInfo[i].relatedDeployments.autoUpdateOutdatedInstancesDeploymentIds[j]"]
        set j [expr $j + 1]
    }
    set j 0
    set count_j [CkJsonObject_SizeOfArray $jResp "deploymentsInfo[i].targetInstances.autoScalingGroups"]
    while {$j < $count_j} {
        CkJsonObject_put_J $jResp $j
        set strVal [CkJsonObject_stringOf $jResp "deploymentsInfo[i].targetInstances.autoScalingGroups[j]"]
        set j [expr $j + 1]
    }
    set j 0
    set count_j [CkJsonObject_SizeOfArray $jResp "deploymentsInfo[i].targetInstances.ec2TagSet.ec2TagSetList"]
    while {$j < $count_j} {
        CkJsonObject_put_J $jResp $j
        set k 0
        set count_k [CkJsonObject_SizeOfArray $jResp "deploymentsInfo[i].targetInstances.ec2TagSet.ec2TagSetList[j]"]
        while {$k < $count_k} {
            CkJsonObject_put_K $jResp $k
            set Key [CkJsonObject_stringOf $jResp "deploymentsInfo[i].targetInstances.ec2TagSet.ec2TagSetList[j][k].Key"]
            set v_Type [CkJsonObject_stringOf $jResp "deploymentsInfo[i].targetInstances.ec2TagSet.ec2TagSetList[j][k].Type"]
            set Value [CkJsonObject_stringOf $jResp "deploymentsInfo[i].targetInstances.ec2TagSet.ec2TagSetList[j][k].Value"]
            set k [expr $k + 1]
        }
        set j [expr $j + 1]
    }
    set j 0
    set count_j [CkJsonObject_SizeOfArray $jResp "deploymentsInfo[i].targetInstances.tagFilters"]
    while {$j < $count_j} {
        CkJsonObject_put_J $jResp $j
        set Key [CkJsonObject_stringOf $jResp "deploymentsInfo[i].targetInstances.tagFilters[j].Key"]
        set v_Type [CkJsonObject_stringOf $jResp "deploymentsInfo[i].targetInstances.tagFilters[j].Type"]
        set Value [CkJsonObject_stringOf $jResp "deploymentsInfo[i].targetInstances.tagFilters[j].Value"]
        set j [expr $j + 1]
    }
    set i [expr $i + 1]
}

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

# {
#   "deploymentsInfo": [
#     {
#       "additionalDeploymentStatusInfo": "string",
#       "applicationName": "string",
#       "autoRollbackConfiguration": {
#         "enabled": boolean,
#         "events": [
#           "string"
#         ]
#       },
#       "blueGreenDeploymentConfiguration": {
#         "deploymentReadyOption": {
#           "actionOnTimeout": "string",
#           "waitTimeInMinutes": number
#         },
#         "greenFleetProvisioningOption": {
#           "action": "string"
#         },
#         "terminateBlueInstancesOnDeploymentSuccess": {
#           "action": "string",
#           "terminationWaitTimeInMinutes": number
#         }
#       },
#       "completeTime": number,
#       "computePlatform": "string",
#       "createTime": number,
#       "creator": "string",
#       "deploymentConfigName": "string",
#       "deploymentGroupName": "string",
#       "deploymentId": "string",
#       "deploymentOverview": {
#         "Failed": number,
#         "InProgress": number,
#         "Pending": number,
#         "Ready": number,
#         "Skipped": number,
#         "Succeeded": number
#       },
#       "deploymentStatusMessages": [
#         "string"
#       ],
#       "deploymentStyle": {
#         "deploymentOption": "string",
#         "deploymentType": "string"
#       },
#       "description": "string",
#       "errorInformation": {
#         "code": "string",
#         "message": "string"
#       },
#       "externalId": "string",
#       "fileExistsBehavior": "string",
#       "ignoreApplicationStopFailures": boolean,
#       "instanceTerminationWaitTimeStarted": boolean,
#       "loadBalancerInfo": {
#         "elbInfoList": [
#           {
#             "name": "string"
#           }
#         ],
#         "targetGroupInfoList": [
#           {
#             "name": "string"
#           }
#         ],
#         "targetGroupPairInfoList": [
#           {
#             "prodTrafficRoute": {
#               "listenerArns": [
#                 "string"
#               ]
#             },
#             "targetGroups": [
#               {
#                 "name": "string"
#               }
#             ],
#             "testTrafficRoute": {
#               "listenerArns": [
#                 "string"
#               ]
#             }
#           }
#         ]
#       },
#       "previousRevision": {
#         "appSpecContent": {
#           "content": "string",
#           "sha256": "string"
#         },
#         "gitHubLocation": {
#           "commitId": "string",
#           "repository": "string"
#         },
#         "revisionType": "string",
#         "s3Location": {
#           "bucket": "string",
#           "bundleType": "string",
#           "eTag": "string",
#           "key": "string",
#           "version": "string"
#         },
#         "string": {
#           "content": "string",
#           "sha256": "string"
#         }
#       },
#       "relatedDeployments": {
#         "autoUpdateOutdatedInstancesDeploymentIds": [
#           "string"
#         ],
#         "autoUpdateOutdatedInstancesRootDeploymentId": "string"
#       },
#       "revision": {
#         "appSpecContent": {
#           "content": "string",
#           "sha256": "string"
#         },
#         "gitHubLocation": {
#           "commitId": "string",
#           "repository": "string"
#         },
#         "revisionType": "string",
#         "s3Location": {
#           "bucket": "string",
#           "bundleType": "string",
#           "eTag": "string",
#           "key": "string",
#           "version": "string"
#         },
#         "string": {
#           "content": "string",
#           "sha256": "string"
#         }
#       },
#       "rollbackInfo": {
#         "rollbackDeploymentId": "string",
#         "rollbackMessage": "string",
#         "rollbackTriggeringDeploymentId": "string"
#       },
#       "startTime": number,
#       "status": "string",
#       "targetInstances": {
#         "autoScalingGroups": [
#           "string"
#         ],
#         "ec2TagSet": {
#           "ec2TagSetList": [
#             [
#               {
#                 "Key": "string",
#                 "Type": "string",
#                 "Value": "string"
#               }
#             ]
#           ]
#         },
#         "tagFilters": [
#           {
#             "Key": "string",
#             "Type": "string",
#             "Value": "string"
#           }
#         ]
#       },
#       "updateOutdatedInstancesOnly": boolean
#     }
#   ]
# }

delete_CkRest $rest
delete_CkAuthAws $authAws
delete_CkJsonObject $json
delete_CkStringBuilder $sbRequestBody
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp