Chilkat Online Tools

MoveReplicationTask 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.update("ReplicationTaskArn", value: "string")
    json.update("TargetReplicationInstanceArn", value: "string")

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

    // {
    //   "ReplicationTaskArn": "string",
    //   "TargetReplicationInstanceArn": "string"
    // }

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

    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 CdcStartPosition: String? = jResp.string(of: "ReplicationTask.CdcStartPosition")
    var CdcStopPosition: String? = jResp.string(of: "ReplicationTask.CdcStopPosition")
    var LastFailureMessage: String? = jResp.string(of: "ReplicationTask.LastFailureMessage")
    var MigrationType: String? = jResp.string(of: "ReplicationTask.MigrationType")
    var RecoveryCheckpoint: String? = jResp.string(of: "ReplicationTask.RecoveryCheckpoint")
    var ReplicationInstanceArn: String? = jResp.string(of: "ReplicationTask.ReplicationInstanceArn")
    var ReplicationTaskArn: String? = jResp.string(of: "ReplicationTask.ReplicationTaskArn")
    var ReplicationTaskCreationDate: Int = jResp.int(of: "ReplicationTask.ReplicationTaskCreationDate").intValue
    var ReplicationTaskIdentifier: String? = jResp.string(of: "ReplicationTask.ReplicationTaskIdentifier")
    var ReplicationTaskSettings: String? = jResp.string(of: "ReplicationTask.ReplicationTaskSettings")
    var ReplicationTaskStartDate: Int = jResp.int(of: "ReplicationTask.ReplicationTaskStartDate").intValue
    var ElapsedTimeMillis: Int = jResp.int(of: "ReplicationTask.ReplicationTaskStats.ElapsedTimeMillis").intValue
    var FreshStartDate: Int = jResp.int(of: "ReplicationTask.ReplicationTaskStats.FreshStartDate").intValue
    var FullLoadFinishDate: Int = jResp.int(of: "ReplicationTask.ReplicationTaskStats.FullLoadFinishDate").intValue
    var FullLoadProgressPercent: Int = jResp.int(of: "ReplicationTask.ReplicationTaskStats.FullLoadProgressPercent").intValue
    var FullLoadStartDate: Int = jResp.int(of: "ReplicationTask.ReplicationTaskStats.FullLoadStartDate").intValue
    var StartDate: Int = jResp.int(of: "ReplicationTask.ReplicationTaskStats.StartDate").intValue
    var StopDate: Int = jResp.int(of: "ReplicationTask.ReplicationTaskStats.StopDate").intValue
    var TablesErrored: Int = jResp.int(of: "ReplicationTask.ReplicationTaskStats.TablesErrored").intValue
    var TablesLoaded: Int = jResp.int(of: "ReplicationTask.ReplicationTaskStats.TablesLoaded").intValue
    var TablesLoading: Int = jResp.int(of: "ReplicationTask.ReplicationTaskStats.TablesLoading").intValue
    var TablesQueued: Int = jResp.int(of: "ReplicationTask.ReplicationTaskStats.TablesQueued").intValue
    var SourceEndpointArn: String? = jResp.string(of: "ReplicationTask.SourceEndpointArn")
    var Status: String? = jResp.string(of: "ReplicationTask.Status")
    var StopReason: String? = jResp.string(of: "ReplicationTask.StopReason")
    var TableMappings: String? = jResp.string(of: "ReplicationTask.TableMappings")
    var TargetEndpointArn: String? = jResp.string(of: "ReplicationTask.TargetEndpointArn")
    var TargetReplicationInstanceArn: String? = jResp.string(of: "ReplicationTask.TargetReplicationInstanceArn")
    var TaskData: String? = jResp.string(of: "ReplicationTask.TaskData")

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

    // {
    //   "ReplicationTask": {
    //     "CdcStartPosition": "string",
    //     "CdcStopPosition": "string",
    //     "LastFailureMessage": "string",
    //     "MigrationType": "string",
    //     "RecoveryCheckpoint": "string",
    //     "ReplicationInstanceArn": "string",
    //     "ReplicationTaskArn": "string",
    //     "ReplicationTaskCreationDate": number,
    //     "ReplicationTaskIdentifier": "string",
    //     "ReplicationTaskSettings": "string",
    //     "ReplicationTaskStartDate": number,
    //     "ReplicationTaskStats": {
    //       "ElapsedTimeMillis": number,
    //       "FreshStartDate": number,
    //       "FullLoadFinishDate": number,
    //       "FullLoadProgressPercent": number,
    //       "FullLoadStartDate": number,
    //       "StartDate": number,
    //       "StopDate": number,
    //       "TablesErrored": number,
    //       "TablesLoaded": number,
    //       "TablesLoading": number,
    //       "TablesQueued": number
    //     },
    //     "SourceEndpointArn": "string",
    //     "Status": "string",
    //     "StopReason": "string",
    //     "TableMappings": "string",
    //     "TargetEndpointArn": "string",
    //     "TargetReplicationInstanceArn": "string",
    //     "TaskData": "string"
    //   }
    // }

}