Chilkat Online Tools

GetContainerRecipe TCL Example

EC2 Image Builder

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 "imagebuilder"
# SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
CkRest_SetAuthAws $rest $authAws

# URL: https://imagebuilder.us-west-2.amazonaws.com/
# Use the same region as specified above.
set success [CkRest_Connect $rest "imagebuilder.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
}

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

set sbResponseBody [new_CkStringBuilder]

set success [CkRest_FullRequestNoBodySb $rest "GET" "/GetContainerRecipe" $sbResponseBody]
if {$success != 1} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkAuthAws $authAws
    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_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 Arn [CkJsonObject_stringOf $jResp "containerRecipe.arn"]
set ContainerType [CkJsonObject_stringOf $jResp "containerRecipe.containerType"]
set DateCreated [CkJsonObject_stringOf $jResp "containerRecipe.dateCreated"]
set Description [CkJsonObject_stringOf $jResp "containerRecipe.description"]
set DockerfileTemplateData [CkJsonObject_stringOf $jResp "containerRecipe.dockerfileTemplateData"]
set Encrypted [CkJsonObject_IntOf $jResp "containerRecipe.encrypted"]
set Image [CkJsonObject_stringOf $jResp "containerRecipe.instanceConfiguration.image"]
set KmsKeyId [CkJsonObject_stringOf $jResp "containerRecipe.kmsKeyId"]
set Name [CkJsonObject_stringOf $jResp "containerRecipe.name"]
set Owner [CkJsonObject_stringOf $jResp "containerRecipe.owner"]
set ParentImage [CkJsonObject_stringOf $jResp "containerRecipe.parentImage"]
set Platform [CkJsonObject_stringOf $jResp "containerRecipe.platform"]
set v_String [CkJsonObject_stringOf $jResp "containerRecipe.tags.string"]
set RepositoryName [CkJsonObject_stringOf $jResp "containerRecipe.targetRepository.repositoryName"]
set Service [CkJsonObject_stringOf $jResp "containerRecipe.targetRepository.service"]
set Version [CkJsonObject_stringOf $jResp "containerRecipe.version"]
set WorkingDirectory [CkJsonObject_stringOf $jResp "containerRecipe.workingDirectory"]
set requestId [CkJsonObject_stringOf $jResp "requestId"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "containerRecipe.components"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set componentArn [CkJsonObject_stringOf $jResp "containerRecipe.components[i].componentArn"]
    set j 0
    set count_j [CkJsonObject_SizeOfArray $jResp "containerRecipe.components[i].parameters"]
    while {$j < $count_j} {
        CkJsonObject_put_J $jResp $j
        set name [CkJsonObject_stringOf $jResp "containerRecipe.components[i].parameters[j].name"]
        set k 0
        set count_k [CkJsonObject_SizeOfArray $jResp "containerRecipe.components[i].parameters[j].value"]
        while {$k < $count_k} {
            CkJsonObject_put_K $jResp $k
            set strVal [CkJsonObject_stringOf $jResp "containerRecipe.components[i].parameters[j].value[k]"]
            set k [expr $k + 1]
        }
        set j [expr $j + 1]
    }
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "containerRecipe.instanceConfiguration.blockDeviceMappings"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set deviceName [CkJsonObject_stringOf $jResp "containerRecipe.instanceConfiguration.blockDeviceMappings[i].deviceName"]
    set DeleteOnTermination [CkJsonObject_IntOf $jResp "containerRecipe.instanceConfiguration.blockDeviceMappings[i].ebs.deleteOnTermination"]
    set ebsEncrypted [CkJsonObject_IntOf $jResp "containerRecipe.instanceConfiguration.blockDeviceMappings[i].ebs.encrypted"]
    set Iops [CkJsonObject_IntOf $jResp "containerRecipe.instanceConfiguration.blockDeviceMappings[i].ebs.iops"]
    set ebsKmsKeyId [CkJsonObject_stringOf $jResp "containerRecipe.instanceConfiguration.blockDeviceMappings[i].ebs.kmsKeyId"]
    set SnapshotId [CkJsonObject_stringOf $jResp "containerRecipe.instanceConfiguration.blockDeviceMappings[i].ebs.snapshotId"]
    set Throughput [CkJsonObject_IntOf $jResp "containerRecipe.instanceConfiguration.blockDeviceMappings[i].ebs.throughput"]
    set VolumeSize [CkJsonObject_IntOf $jResp "containerRecipe.instanceConfiguration.blockDeviceMappings[i].ebs.volumeSize"]
    set VolumeType [CkJsonObject_stringOf $jResp "containerRecipe.instanceConfiguration.blockDeviceMappings[i].ebs.volumeType"]
    set noDevice [CkJsonObject_stringOf $jResp "containerRecipe.instanceConfiguration.blockDeviceMappings[i].noDevice"]
    set virtualName [CkJsonObject_stringOf $jResp "containerRecipe.instanceConfiguration.blockDeviceMappings[i].virtualName"]
    set i [expr $i + 1]
}

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

# {
#   "containerRecipe": {
#     "arn": "string",
#     "components": [
#       {
#         "componentArn": "string",
#         "parameters": [
#           {
#             "name": "string",
#             "value": [
#               "string"
#             ]
#           }
#         ]
#       }
#     ],
#     "containerType": "string",
#     "dateCreated": "string",
#     "description": "string",
#     "dockerfileTemplateData": "string",
#     "encrypted": boolean,
#     "instanceConfiguration": {
#       "blockDeviceMappings": [
#         {
#           "deviceName": "string",
#           "ebs": {
#             "deleteOnTermination": boolean,
#             "encrypted": boolean,
#             "iops": number,
#             "kmsKeyId": "string",
#             "snapshotId": "string",
#             "throughput": number,
#             "volumeSize": number,
#             "volumeType": "string"
#           },
#           "noDevice": "string",
#           "virtualName": "string"
#         }
#       ],
#       "image": "string"
#     },
#     "kmsKeyId": "string",
#     "name": "string",
#     "owner": "string",
#     "parentImage": "string",
#     "platform": "string",
#     "tags": {
#       "string": "string"
#     },
#     "targetRepository": {
#       "repositoryName": "string",
#       "service": "string"
#     },
#     "version": "string",
#     "workingDirectory": "string"
#   },
#   "requestId": "string"
# }

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