CreateNodegroup Swift3 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 = "eks"
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
rest.setAuthAws(authAws)
// URL: https://eks.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = rest.connect("eks.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("amiType", value: "string")
json.update("capacityType", value: "string")
json.update("clientRequestToken", value: "string")
json.updateInt("diskSize", value: 123)
json.update("instanceTypes[0]", value: "string")
json.update("labels.string", value: "string")
json.update("launchTemplate.id", value: "string")
json.update("launchTemplate.name", value: "string")
json.update("launchTemplate.version", value: "string")
json.update("nodegroupName", value: "string")
json.update("nodeRole", value: "string")
json.update("releaseVersion", value: "string")
json.update("remoteAccess.ec2SshKey", value: "string")
json.update("remoteAccess.sourceSecurityGroups[0]", value: "string")
json.updateInt("scalingConfig.desiredSize", value: 123)
json.updateInt("scalingConfig.maxSize", value: 123)
json.updateInt("scalingConfig.minSize", value: 123)
json.update("subnets[0]", value: "string")
json.update("tags.string", value: "string")
json.update("taints[0].effect", value: "string")
json.update("taints[0].key", value: "string")
json.update("taints[0].value", value: "string")
json.updateInt("updateConfig.maxUnavailable", value: 123)
json.updateInt("updateConfig.maxUnavailablePercentage", value: 123)
json.update("version", value: "string")
// The JSON request body created by the above code:
// {
// "amiType": "string",
// "capacityType": "string",
// "clientRequestToken": "string",
// "diskSize": number,
// "instanceTypes": [
// "string"
// ],
// "labels": {
// "string": "string"
// },
// "launchTemplate": {
// "id": "string",
// "name": "string",
// "version": "string"
// },
// "nodegroupName": "string",
// "nodeRole": "string",
// "releaseVersion": "string",
// "remoteAccess": {
// "ec2SshKey": "string",
// "sourceSecurityGroups": [
// "string"
// ]
// },
// "scalingConfig": {
// "desiredSize": number,
// "maxSize": number,
// "minSize": number
// },
// "subnets": [
// "string"
// ],
// "tags": {
// "string": "string"
// },
// "taints": [
// {
// "effect": "string",
// "key": "string",
// "value": "string"
// }
// ],
// "updateConfig": {
// "maxUnavailable": number,
// "maxUnavailablePercentage": number
// },
// "version": "string"
// }
rest.addHeader("Content-Type", value: "application/x-amz-json-1.1")
rest.addHeader("X-Amz-Target", value: "CreateNodegroup")
let sbRequestBody = CkoStringBuilder()!
json.emitSb(sbRequestBody)
let sbResponseBody = CkoStringBuilder()!
success = rest.fullRequestSb("POST", uriPath: "/clusters/{name}/node-groups", 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 code: String?
var message: String?
var j: Int
var count_j: Int
var strVal: String?
var name: String?
var effect: String?
var key: String?
var value: String?
var AmiType: String? = jResp.string(of: "nodegroup.amiType")
var CapacityType: String? = jResp.string(of: "nodegroup.capacityType")
var ClusterName: String? = jResp.string(of: "nodegroup.clusterName")
var CreatedAt: Int = jResp.int(of: "nodegroup.createdAt").intValue
var DiskSize: Int = jResp.int(of: "nodegroup.diskSize").intValue
var v_String: String? = jResp.string(of: "nodegroup.labels.string")
var Id: String? = jResp.string(of: "nodegroup.launchTemplate.id")
var Name: String? = jResp.string(of: "nodegroup.launchTemplate.name")
var Version: String? = jResp.string(of: "nodegroup.launchTemplate.version")
var ModifiedAt: Int = jResp.int(of: "nodegroup.modifiedAt").intValue
var NodegroupArn: String? = jResp.string(of: "nodegroup.nodegroupArn")
var NodegroupName: String? = jResp.string(of: "nodegroup.nodegroupName")
var NodeRole: String? = jResp.string(of: "nodegroup.nodeRole")
var ReleaseVersion: String? = jResp.string(of: "nodegroup.releaseVersion")
var Ec2SshKey: String? = jResp.string(of: "nodegroup.remoteAccess.ec2SshKey")
var RemoteAccessSecurityGroup: String? = jResp.string(of: "nodegroup.resources.remoteAccessSecurityGroup")
var DesiredSize: Int = jResp.int(of: "nodegroup.scalingConfig.desiredSize").intValue
var MaxSize: Int = jResp.int(of: "nodegroup.scalingConfig.maxSize").intValue
var MinSize: Int = jResp.int(of: "nodegroup.scalingConfig.minSize").intValue
var Status: String? = jResp.string(of: "nodegroup.status")
var TagsString: String? = jResp.string(of: "nodegroup.tags.string")
var MaxUnavailable: Int = jResp.int(of: "nodegroup.updateConfig.maxUnavailable").intValue
var MaxUnavailablePercentage: Int = jResp.int(of: "nodegroup.updateConfig.maxUnavailablePercentage").intValue
var nodegroupVersion: String? = jResp.string(of: "nodegroup.version")
var i: Int = 0
var count_i: Int = jResp.size(ofArray: "nodegroup.health.issues").intValue
while i < count_i {
jResp.i = i
code = jResp.string(of: "nodegroup.health.issues[i].code")
message = jResp.string(of: "nodegroup.health.issues[i].message")
j = 0
count_j = jResp.size(ofArray: "nodegroup.health.issues[i].resourceIds").intValue
while j < count_j {
jResp.j = j
strVal = jResp.string(of: "nodegroup.health.issues[i].resourceIds[j]")
j = j + 1
}
i = i + 1
}
i = 0
count_i = jResp.size(ofArray: "nodegroup.instanceTypes").intValue
while i < count_i {
jResp.i = i
strVal = jResp.string(of: "nodegroup.instanceTypes[i]")
i = i + 1
}
i = 0
count_i = jResp.size(ofArray: "nodegroup.remoteAccess.sourceSecurityGroups").intValue
while i < count_i {
jResp.i = i
strVal = jResp.string(of: "nodegroup.remoteAccess.sourceSecurityGroups[i]")
i = i + 1
}
i = 0
count_i = jResp.size(ofArray: "nodegroup.resources.autoScalingGroups").intValue
while i < count_i {
jResp.i = i
name = jResp.string(of: "nodegroup.resources.autoScalingGroups[i].name")
i = i + 1
}
i = 0
count_i = jResp.size(ofArray: "nodegroup.subnets").intValue
while i < count_i {
jResp.i = i
strVal = jResp.string(of: "nodegroup.subnets[i]")
i = i + 1
}
i = 0
count_i = jResp.size(ofArray: "nodegroup.taints").intValue
while i < count_i {
jResp.i = i
effect = jResp.string(of: "nodegroup.taints[i].effect")
key = jResp.string(of: "nodegroup.taints[i].key")
value = jResp.string(of: "nodegroup.taints[i].value")
i = i + 1
}
// A sample JSON response body parsed by the above code:
// {
// "nodegroup": {
// "amiType": "string",
// "capacityType": "string",
// "clusterName": "string",
// "createdAt": number,
// "diskSize": number,
// "health": {
// "issues": [
// {
// "code": "string",
// "message": "string",
// "resourceIds": [
// "string"
// ]
// }
// ]
// },
// "instanceTypes": [
// "string"
// ],
// "labels": {
// "string": "string"
// },
// "launchTemplate": {
// "id": "string",
// "name": "string",
// "version": "string"
// },
// "modifiedAt": number,
// "nodegroupArn": "string",
// "nodegroupName": "string",
// "nodeRole": "string",
// "releaseVersion": "string",
// "remoteAccess": {
// "ec2SshKey": "string",
// "sourceSecurityGroups": [
// "string"
// ]
// },
// "resources": {
// "autoScalingGroups": [
// {
// "name": "string"
// }
// ],
// "remoteAccessSecurityGroup": "string"
// },
// "scalingConfig": {
// "desiredSize": number,
// "maxSize": number,
// "minSize": number
// },
// "status": "string",
// "subnets": [
// "string"
// ],
// "tags": {
// "string": "string"
// },
// "taints": [
// {
// "effect": "string",
// "key": "string",
// "value": "string"
// }
// ],
// "updateConfig": {
// "maxUnavailable": number,
// "maxUnavailablePercentage": number
// },
// "version": "string"
// }
// }
}