GetImageRecipe Swift Example
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 = "imagebuilder"
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
rest.SetAuthAws(authAws)
// URL: https://imagebuilder.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = rest.Connect("imagebuilder.us-west-2.amazonaws.com", port: 443, tls: true, autoReconnect: true)
if success != true {
print("ConnectFailReason: \(rest.ConnectFailReason.intValue)")
print("\(rest.LastErrorText)")
return
}
rest.AddHeader("Content-Type", value: "application/x-amz-json-1.1")
rest.AddHeader("X-Amz-Target", value: "GetImageRecipe")
let sbResponseBody = CkoStringBuilder()
success = rest.FullRequestNoBodySb("GET", uriPath: "/GetImageRecipe", sb: 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 deviceName: String?
var DeleteOnTermination: Int
var Encrypted: Int
var Iops: Int
var KmsKeyId: String?
var SnapshotId: String?
var Throughput: Int
var VolumeSize: Int
var VolumeType: String?
var noDevice: String?
var virtualName: String?
var componentArn: String?
var j: Int
var count_j: Int
var name: String?
var k: Int
var count_k: Int
var strVal: String?
var UninstallAfterBuild: Int = jResp.IntOf("imageRecipe.additionalInstanceConfiguration.systemsManagerAgent.uninstallAfterBuild").intValue
var UserDataOverride: String? = jResp.StringOf("imageRecipe.additionalInstanceConfiguration.userDataOverride")
var Arn: String? = jResp.StringOf("imageRecipe.arn")
var DateCreated: String? = jResp.StringOf("imageRecipe.dateCreated")
var Description: String? = jResp.StringOf("imageRecipe.description")
var Name: String? = jResp.StringOf("imageRecipe.name")
var Owner: String? = jResp.StringOf("imageRecipe.owner")
var ParentImage: String? = jResp.StringOf("imageRecipe.parentImage")
var Platform: String? = jResp.StringOf("imageRecipe.platform")
var v_String: String? = jResp.StringOf("imageRecipe.tags.string")
var v_Type: String? = jResp.StringOf("imageRecipe.type")
var Version: String? = jResp.StringOf("imageRecipe.version")
var WorkingDirectory: String? = jResp.StringOf("imageRecipe.workingDirectory")
var requestId: String? = jResp.StringOf("requestId")
var i: Int = 0
var count_i: Int = jResp.SizeOfArray("imageRecipe.blockDeviceMappings").intValue
while i < count_i {
jResp.I = i
deviceName = jResp.StringOf("imageRecipe.blockDeviceMappings[i].deviceName")
DeleteOnTermination = jResp.IntOf("imageRecipe.blockDeviceMappings[i].ebs.deleteOnTermination").intValue
Encrypted = jResp.IntOf("imageRecipe.blockDeviceMappings[i].ebs.encrypted").intValue
Iops = jResp.IntOf("imageRecipe.blockDeviceMappings[i].ebs.iops").intValue
KmsKeyId = jResp.StringOf("imageRecipe.blockDeviceMappings[i].ebs.kmsKeyId")
SnapshotId = jResp.StringOf("imageRecipe.blockDeviceMappings[i].ebs.snapshotId")
Throughput = jResp.IntOf("imageRecipe.blockDeviceMappings[i].ebs.throughput").intValue
VolumeSize = jResp.IntOf("imageRecipe.blockDeviceMappings[i].ebs.volumeSize").intValue
VolumeType = jResp.StringOf("imageRecipe.blockDeviceMappings[i].ebs.volumeType")
noDevice = jResp.StringOf("imageRecipe.blockDeviceMappings[i].noDevice")
virtualName = jResp.StringOf("imageRecipe.blockDeviceMappings[i].virtualName")
i = i + 1
}
i = 0
count_i = jResp.SizeOfArray("imageRecipe.components").intValue
while i < count_i {
jResp.I = i
componentArn = jResp.StringOf("imageRecipe.components[i].componentArn")
j = 0
count_j = jResp.SizeOfArray("imageRecipe.components[i].parameters").intValue
while j < count_j {
jResp.J = j
name = jResp.StringOf("imageRecipe.components[i].parameters[j].name")
k = 0
count_k = jResp.SizeOfArray("imageRecipe.components[i].parameters[j].value").intValue
while k < count_k {
jResp.K = k
strVal = jResp.StringOf("imageRecipe.components[i].parameters[j].value[k]")
k = k + 1
}
j = j + 1
}
i = i + 1
}
// A sample JSON response body parsed by the above code:
// {
// "imageRecipe": {
// "additionalInstanceConfiguration": {
// "systemsManagerAgent": {
// "uninstallAfterBuild": boolean
// },
// "userDataOverride": "string"
// },
// "arn": "string",
// "blockDeviceMappings": [
// {
// "deviceName": "string",
// "ebs": {
// "deleteOnTermination": boolean,
// "encrypted": boolean,
// "iops": number,
// "kmsKeyId": "string",
// "snapshotId": "string",
// "throughput": number,
// "volumeSize": number,
// "volumeType": "string"
// },
// "noDevice": "string",
// "virtualName": "string"
// }
// ],
// "components": [
// {
// "componentArn": "string",
// "parameters": [
// {
// "name": "string",
// "value": [
// "string"
// ]
// }
// ]
// }
// ],
// "dateCreated": "string",
// "description": "string",
// "name": "string",
// "owner": "string",
// "parentImage": "string",
// "platform": "string",
// "tags": {
// "string": "string"
// },
// "type": "string",
// "version": "string",
// "workingDirectory": "string"
// },
// "requestId": "string"
// }
}