Chilkat Online Tools

CreateReplicationInstance Swift3 Example

AWS Database Migration Service

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 = "dms"
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.setAuthAws(authAws)

    // URL: https://dms.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.connect("dms.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.updateInt("AllocatedStorage", value: 123)
    json.updateInt("AutoMinorVersionUpgrade", value: 123)
    json.update("AvailabilityZone", value: "string")
    json.update("DnsNameServers", value: "string")
    json.update("EngineVersion", value: "string")
    json.update("KmsKeyId", value: "string")
    json.updateInt("MultiAZ", value: 123)
    json.update("PreferredMaintenanceWindow", value: "string")
    json.updateInt("PubliclyAccessible", value: 123)
    json.update("ReplicationInstanceClass", value: "string")
    json.update("ReplicationInstanceIdentifier", value: "string")
    json.update("ReplicationSubnetGroupIdentifier", value: "string")
    json.update("ResourceIdentifier", value: "string")
    json.update("Tags[0].Key", value: "string")
    json.update("Tags[0].ResourceArn", value: "string")
    json.update("Tags[0].Value", value: "string")
    json.update("VpcSecurityGroupIds[0]", value: "string")

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

    // {
    //   "AllocatedStorage": number,
    //   "AutoMinorVersionUpgrade": boolean,
    //   "AvailabilityZone": "string",
    //   "DnsNameServers": "string",
    //   "EngineVersion": "string",
    //   "KmsKeyId": "string",
    //   "MultiAZ": boolean,
    //   "PreferredMaintenanceWindow": "string",
    //   "PubliclyAccessible": boolean,
    //   "ReplicationInstanceClass": "string",
    //   "ReplicationInstanceIdentifier": "string",
    //   "ReplicationSubnetGroupIdentifier": "string",
    //   "ResourceIdentifier": "string",
    //   "Tags": [
    //     {
    //       "Key": "string",
    //       "ResourceArn": "string",
    //       "Value": "string"
    //     }
    //   ],
    //   "VpcSecurityGroupIds": [
    //     "string"
    //   ]
    // }

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

    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 strVal: String?
    var Name: String?
    var SubnetIdentifier: String?
    var SubnetStatus: String?
    var Status: String?
    var VpcSecurityGroupId: String?

    var AllocatedStorage: Int = jResp.int(of: "ReplicationInstance.AllocatedStorage").intValue
    var AutoMinorVersionUpgrade: Int = jResp.int(of: "ReplicationInstance.AutoMinorVersionUpgrade").intValue
    var AvailabilityZone: String? = jResp.string(of: "ReplicationInstance.AvailabilityZone")
    var DnsNameServers: String? = jResp.string(of: "ReplicationInstance.DnsNameServers")
    var EngineVersion: String? = jResp.string(of: "ReplicationInstance.EngineVersion")
    var FreeUntil: Int = jResp.int(of: "ReplicationInstance.FreeUntil").intValue
    var InstanceCreateTime: Int = jResp.int(of: "ReplicationInstance.InstanceCreateTime").intValue
    var KmsKeyId: String? = jResp.string(of: "ReplicationInstance.KmsKeyId")
    var MultiAZ: Int = jResp.int(of: "ReplicationInstance.MultiAZ").intValue
    var PendingModifiedValuesAllocatedStorage: Int = jResp.int(of: "ReplicationInstance.PendingModifiedValues.AllocatedStorage").intValue
    var PendingModifiedValuesEngineVersion: String? = jResp.string(of: "ReplicationInstance.PendingModifiedValues.EngineVersion")
    var PendingModifiedValuesMultiAZ: Int = jResp.int(of: "ReplicationInstance.PendingModifiedValues.MultiAZ").intValue
    var ReplicationInstanceClass: String? = jResp.string(of: "ReplicationInstance.PendingModifiedValues.ReplicationInstanceClass")
    var PreferredMaintenanceWindow: String? = jResp.string(of: "ReplicationInstance.PreferredMaintenanceWindow")
    var PubliclyAccessible: Int = jResp.int(of: "ReplicationInstance.PubliclyAccessible").intValue
    var ReplicationInstanceArn: String? = jResp.string(of: "ReplicationInstance.ReplicationInstanceArn")
    var ReplicationInstanceReplicationInstanceClass: String? = jResp.string(of: "ReplicationInstance.ReplicationInstanceClass")
    var ReplicationInstanceIdentifier: String? = jResp.string(of: "ReplicationInstance.ReplicationInstanceIdentifier")
    var ReplicationInstancePrivateIpAddress: String? = jResp.string(of: "ReplicationInstance.ReplicationInstancePrivateIpAddress")
    var ReplicationInstancePublicIpAddress: String? = jResp.string(of: "ReplicationInstance.ReplicationInstancePublicIpAddress")
    var ReplicationInstanceStatus: String? = jResp.string(of: "ReplicationInstance.ReplicationInstanceStatus")
    var ReplicationSubnetGroupDescription: String? = jResp.string(of: "ReplicationInstance.ReplicationSubnetGroup.ReplicationSubnetGroupDescription")
    var ReplicationSubnetGroupIdentifier: String? = jResp.string(of: "ReplicationInstance.ReplicationSubnetGroup.ReplicationSubnetGroupIdentifier")
    var SubnetGroupStatus: String? = jResp.string(of: "ReplicationInstance.ReplicationSubnetGroup.SubnetGroupStatus")
    var VpcId: String? = jResp.string(of: "ReplicationInstance.ReplicationSubnetGroup.VpcId")
    var SecondaryAvailabilityZone: String? = jResp.string(of: "ReplicationInstance.SecondaryAvailabilityZone")
    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "ReplicationInstance.ReplicationInstancePrivateIpAddresses").intValue
    while i < count_i {
        jResp.i = i
        strVal = jResp.string(of: "ReplicationInstance.ReplicationInstancePrivateIpAddresses[i]")
        i = i + 1
    }

    i = 0
    count_i = jResp.size(ofArray: "ReplicationInstance.ReplicationInstancePublicIpAddresses").intValue
    while i < count_i {
        jResp.i = i
        strVal = jResp.string(of: "ReplicationInstance.ReplicationInstancePublicIpAddresses[i]")
        i = i + 1
    }

    i = 0
    count_i = jResp.size(ofArray: "ReplicationInstance.ReplicationSubnetGroup.Subnets").intValue
    while i < count_i {
        jResp.i = i
        Name = jResp.string(of: "ReplicationInstance.ReplicationSubnetGroup.Subnets[i].SubnetAvailabilityZone.Name")
        SubnetIdentifier = jResp.string(of: "ReplicationInstance.ReplicationSubnetGroup.Subnets[i].SubnetIdentifier")
        SubnetStatus = jResp.string(of: "ReplicationInstance.ReplicationSubnetGroup.Subnets[i].SubnetStatus")
        i = i + 1
    }

    i = 0
    count_i = jResp.size(ofArray: "ReplicationInstance.VpcSecurityGroups").intValue
    while i < count_i {
        jResp.i = i
        Status = jResp.string(of: "ReplicationInstance.VpcSecurityGroups[i].Status")
        VpcSecurityGroupId = jResp.string(of: "ReplicationInstance.VpcSecurityGroups[i].VpcSecurityGroupId")
        i = i + 1
    }

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

    // {
    //   "ReplicationInstance": {
    //     "AllocatedStorage": number,
    //     "AutoMinorVersionUpgrade": boolean,
    //     "AvailabilityZone": "string",
    //     "DnsNameServers": "string",
    //     "EngineVersion": "string",
    //     "FreeUntil": number,
    //     "InstanceCreateTime": number,
    //     "KmsKeyId": "string",
    //     "MultiAZ": boolean,
    //     "PendingModifiedValues": {
    //       "AllocatedStorage": number,
    //       "EngineVersion": "string",
    //       "MultiAZ": boolean,
    //       "ReplicationInstanceClass": "string"
    //     },
    //     "PreferredMaintenanceWindow": "string",
    //     "PubliclyAccessible": boolean,
    //     "ReplicationInstanceArn": "string",
    //     "ReplicationInstanceClass": "string",
    //     "ReplicationInstanceIdentifier": "string",
    //     "ReplicationInstancePrivateIpAddress": "string",
    //     "ReplicationInstancePrivateIpAddresses": [
    //       "string"
    //     ],
    //     "ReplicationInstancePublicIpAddress": "string",
    //     "ReplicationInstancePublicIpAddresses": [
    //       "string"
    //     ],
    //     "ReplicationInstanceStatus": "string",
    //     "ReplicationSubnetGroup": {
    //       "ReplicationSubnetGroupDescription": "string",
    //       "ReplicationSubnetGroupIdentifier": "string",
    //       "SubnetGroupStatus": "string",
    //       "Subnets": [
    //         {
    //           "SubnetAvailabilityZone": {
    //             "Name": "string"
    //           },
    //           "SubnetIdentifier": "string",
    //           "SubnetStatus": "string"
    //         }
    //       ],
    //       "VpcId": "string"
    //     },
    //     "SecondaryAvailabilityZone": "string",
    //     "VpcSecurityGroups": [
    //       {
    //         "Status": "string",
    //         "VpcSecurityGroupId": "string"
    //       }
    //     ]
    //   }
    // }

}