UpdateLifecyclePolicy 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 = "dlm"
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
rest.setAuthAws(authAws)
// URL: https://dlm.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = rest.connect("dlm.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("Description", value: "string")
json.update("ExecutionRoleArn", value: "string")
json.update("PolicyDetails.Actions[0].CrossRegionCopy[0].EncryptionConfiguration.CmkArn", value: "string")
json.updateInt("PolicyDetails.Actions[0].CrossRegionCopy[0].EncryptionConfiguration.Encrypted", value: 123)
json.updateInt("PolicyDetails.Actions[0].CrossRegionCopy[0].RetainRule.Interval", value: 123)
json.update("PolicyDetails.Actions[0].CrossRegionCopy[0].RetainRule.IntervalUnit", value: "string")
json.update("PolicyDetails.Actions[0].CrossRegionCopy[0].Target", value: "string")
json.update("PolicyDetails.Actions[0].Name", value: "string")
json.update("PolicyDetails.EventSource.Parameters.DescriptionRegex", value: "string")
json.update("PolicyDetails.EventSource.Parameters.EventType", value: "string")
json.update("PolicyDetails.EventSource.Parameters.SnapshotOwner[0]", value: "string")
json.update("PolicyDetails.EventSource.Type", value: "string")
json.updateInt("PolicyDetails.Parameters.ExcludeBootVolume", value: 123)
json.updateInt("PolicyDetails.Parameters.NoReboot", value: 123)
json.update("PolicyDetails.PolicyType", value: "string")
json.update("PolicyDetails.ResourceLocations[0]", value: "string")
json.update("PolicyDetails.ResourceTypes[0]", value: "string")
json.updateInt("PolicyDetails.Schedules[0].CopyTags", value: 123)
json.update("PolicyDetails.Schedules[0].CreateRule.CronExpression", value: "string")
json.updateInt("PolicyDetails.Schedules[0].CreateRule.Interval", value: 123)
json.update("PolicyDetails.Schedules[0].CreateRule.IntervalUnit", value: "string")
json.update("PolicyDetails.Schedules[0].CreateRule.Location", value: "string")
json.update("PolicyDetails.Schedules[0].CreateRule.Times[0]", value: "string")
json.update("PolicyDetails.Schedules[0].CrossRegionCopyRules[0].CmkArn", value: "string")
json.updateInt("PolicyDetails.Schedules[0].CrossRegionCopyRules[0].CopyTags", value: 123)
json.updateInt("PolicyDetails.Schedules[0].CrossRegionCopyRules[0].DeprecateRule.Interval", value: 123)
json.update("PolicyDetails.Schedules[0].CrossRegionCopyRules[0].DeprecateRule.IntervalUnit", value: "string")
json.updateInt("PolicyDetails.Schedules[0].CrossRegionCopyRules[0].Encrypted", value: 123)
json.updateInt("PolicyDetails.Schedules[0].CrossRegionCopyRules[0].RetainRule.Interval", value: 123)
json.update("PolicyDetails.Schedules[0].CrossRegionCopyRules[0].RetainRule.IntervalUnit", value: "string")
json.update("PolicyDetails.Schedules[0].CrossRegionCopyRules[0].Target", value: "string")
json.update("PolicyDetails.Schedules[0].CrossRegionCopyRules[0].TargetRegion", value: "string")
json.updateInt("PolicyDetails.Schedules[0].DeprecateRule.Count", value: 123)
json.updateInt("PolicyDetails.Schedules[0].DeprecateRule.Interval", value: 123)
json.update("PolicyDetails.Schedules[0].DeprecateRule.IntervalUnit", value: "string")
json.update("PolicyDetails.Schedules[0].FastRestoreRule.AvailabilityZones[0]", value: "string")
json.updateInt("PolicyDetails.Schedules[0].FastRestoreRule.Count", value: 123)
json.updateInt("PolicyDetails.Schedules[0].FastRestoreRule.Interval", value: 123)
json.update("PolicyDetails.Schedules[0].FastRestoreRule.IntervalUnit", value: "string")
json.update("PolicyDetails.Schedules[0].Name", value: "string")
json.updateInt("PolicyDetails.Schedules[0].RetainRule.Count", value: 123)
json.updateInt("PolicyDetails.Schedules[0].RetainRule.Interval", value: 123)
json.update("PolicyDetails.Schedules[0].RetainRule.IntervalUnit", value: "string")
json.update("PolicyDetails.Schedules[0].ShareRules[0].TargetAccounts[0]", value: "string")
json.updateInt("PolicyDetails.Schedules[0].ShareRules[0].UnshareInterval", value: 123)
json.update("PolicyDetails.Schedules[0].ShareRules[0].UnshareIntervalUnit", value: "string")
json.update("PolicyDetails.Schedules[0].TagsToAdd[0].Key", value: "string")
json.update("PolicyDetails.Schedules[0].TagsToAdd[0].Value", value: "string")
json.update("PolicyDetails.Schedules[0].VariableTags[0].Key", value: "string")
json.update("PolicyDetails.Schedules[0].VariableTags[0].Value", value: "string")
json.update("PolicyDetails.TargetTags[0].Key", value: "string")
json.update("PolicyDetails.TargetTags[0].Value", value: "string")
json.update("State", value: "string")
// The JSON request body created by the above code:
// {
// "Description": "string",
// "ExecutionRoleArn": "string",
// "PolicyDetails": {
// "Actions": [
// {
// "CrossRegionCopy": [
// {
// "EncryptionConfiguration": {
// "CmkArn": "string",
// "Encrypted": boolean
// },
// "RetainRule": {
// "Interval": number,
// "IntervalUnit": "string"
// },
// "Target": "string"
// }
// ],
// "Name": "string"
// }
// ],
// "EventSource": {
// "Parameters": {
// "DescriptionRegex": "string",
// "EventType": "string",
// "SnapshotOwner": [
// "string"
// ]
// },
// "Type": "string"
// },
// "Parameters": {
// "ExcludeBootVolume": boolean,
// "NoReboot": boolean
// },
// "PolicyType": "string",
// "ResourceLocations": [
// "string"
// ],
// "ResourceTypes": [
// "string"
// ],
// "Schedules": [
// {
// "CopyTags": boolean,
// "CreateRule": {
// "CronExpression": "string",
// "Interval": number,
// "IntervalUnit": "string",
// "Location": "string",
// "Times": [
// "string"
// ]
// },
// "CrossRegionCopyRules": [
// {
// "CmkArn": "string",
// "CopyTags": boolean,
// "DeprecateRule": {
// "Interval": number,
// "IntervalUnit": "string"
// },
// "Encrypted": boolean,
// "RetainRule": {
// "Interval": number,
// "IntervalUnit": "string"
// },
// "Target": "string",
// "TargetRegion": "string"
// }
// ],
// "DeprecateRule": {
// "Count": number,
// "Interval": number,
// "IntervalUnit": "string"
// },
// "FastRestoreRule": {
// "AvailabilityZones": [
// "string"
// ],
// "Count": number,
// "Interval": number,
// "IntervalUnit": "string"
// },
// "Name": "string",
// "RetainRule": {
// "Count": number,
// "Interval": number,
// "IntervalUnit": "string"
// },
// "ShareRules": [
// {
// "TargetAccounts": [
// "string"
// ],
// "UnshareInterval": number,
// "UnshareIntervalUnit": "string"
// }
// ],
// "TagsToAdd": [
// {
// "Key": "string",
// "Value": "string"
// }
// ],
// "VariableTags": [
// {
// "Key": "string",
// "Value": "string"
// }
// ]
// }
// ],
// "TargetTags": [
// {
// "Key": "string",
// "Value": "string"
// }
// ]
// },
// "State": "string"
// }
rest.addHeader("Content-Type", value: "application/x-amz-json-1.1")
rest.addHeader("X-Amz-Target", value: "UpdateLifecyclePolicy")
let sbRequestBody = CkoStringBuilder()!
json.emitSb(sbRequestBody)
let sbResponseBody = CkoStringBuilder()!
success = rest.fullRequestSb("PATCH", uriPath: "/policies/{policyId}", 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
// A sample JSON response body parsed by the above code:
// {}
}