Chilkat Online Tools

GetLifecyclePolicy Xojo Example

Amazon Data Lifecycle Manager

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

Dim rest As New Chilkat.Rest
Dim success As Boolean

Dim authAws As New Chilkat.AuthAws
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
success = 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",443,True,True)
If (success <> True) Then
    System.DebugLog("ConnectFailReason: " + Str(rest.ConnectFailReason))
    System.DebugLog(rest.LastErrorText)
    Return
End If

success = rest.AddHeader("Content-Type","application/x-amz-json-1.1")
success = rest.AddHeader("X-Amz-Target","GetLifecyclePolicy")

Dim sbResponseBody As New Chilkat.StringBuilder
success = rest.FullRequestNoBodySb("GET","/policies/{policyId}/",sbResponseBody)
If (success <> True) Then
    System.DebugLog(rest.LastErrorText)
    Return
End If

Dim respStatusCode As Int32
respStatusCode = rest.ResponseStatusCode
System.DebugLog("response status code = " + Str(respStatusCode))
If (respStatusCode <> 200) Then
    System.DebugLog("Response Header:")
    System.DebugLog(rest.ResponseHeader)
    System.DebugLog("Response Body:")
    System.DebugLog(sbResponseBody.GetAsString())
    Return
End If

Dim jResp As New Chilkat.JsonObject
success = 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

Dim Name As String
Dim j As Int32
Dim count_j As Int32
Dim CmkArn As String
Dim Encrypted As Int32
Dim Interval As Int32
Dim IntervalUnit As String
Dim Target As String
Dim strVal As String
Dim CopyTags As Int32
Dim CronExpression As String
Dim CreateRuleInterval As Int32
Dim CreateRuleIntervalUnit As String
Dim Location As String
Dim Count As Int32
Dim DeprecateRuleInterval As Int32
Dim DeprecateRuleIntervalUnit As String
Dim FastRestoreRuleCount As Int32
Dim FastRestoreRuleInterval As Int32
Dim FastRestoreRuleIntervalUnit As String
Dim RetainRuleCount As Int32
Dim RetainRuleInterval As Int32
Dim RetainRuleIntervalUnit As String
Dim TargetRegion As String
Dim UnshareInterval As Int32
Dim UnshareIntervalUnit As String
Dim k As Int32
Dim count_k As Int32
Dim Key As String
Dim Value As String

Dim DateCreated As Int32
DateCreated = jResp.IntOf("Policy.DateCreated")
Dim DateModified As Int32
DateModified = jResp.IntOf("Policy.DateModified")
Dim Description As String
Description = jResp.StringOf("Policy.Description")
Dim ExecutionRoleArn As String
ExecutionRoleArn = jResp.StringOf("Policy.ExecutionRoleArn")
Dim PolicyArn As String
PolicyArn = jResp.StringOf("Policy.PolicyArn")
Dim DescriptionRegex As String
DescriptionRegex = jResp.StringOf("Policy.PolicyDetails.EventSource.Parameters.DescriptionRegex")
Dim EventType As String
EventType = jResp.StringOf("Policy.PolicyDetails.EventSource.Parameters.EventType")
Dim v_Type As String
v_Type = jResp.StringOf("Policy.PolicyDetails.EventSource.Type")
Dim ExcludeBootVolume As Int32
ExcludeBootVolume = jResp.IntOf("Policy.PolicyDetails.Parameters.ExcludeBootVolume")
Dim NoReboot As Int32
NoReboot = jResp.IntOf("Policy.PolicyDetails.Parameters.NoReboot")
Dim PolicyType As String
PolicyType = jResp.StringOf("Policy.PolicyDetails.PolicyType")
Dim PolicyId As String
PolicyId = jResp.StringOf("Policy.PolicyId")
Dim State As String
State = jResp.StringOf("Policy.State")
Dim StatusMessage As String
StatusMessage = jResp.StringOf("Policy.StatusMessage")
Dim v_String As String
v_String = jResp.StringOf("Policy.Tags.string")
Dim i As Int32
i = 0
Dim count_i As Int32
count_i = jResp.SizeOfArray("Policy.PolicyDetails.Actions")
While i < count_i
    jResp.I = i
    Name = jResp.StringOf("Policy.PolicyDetails.Actions[i].Name")
    j = 0
    count_j = jResp.SizeOfArray("Policy.PolicyDetails.Actions[i].CrossRegionCopy")
    While j < count_j
        jResp.J = j
        CmkArn = jResp.StringOf("Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].EncryptionConfiguration.CmkArn")
        Encrypted = jResp.IntOf("Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].EncryptionConfiguration.Encrypted")
        Interval = jResp.IntOf("Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].RetainRule.Interval")
        IntervalUnit = jResp.StringOf("Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].RetainRule.IntervalUnit")
        Target = jResp.StringOf("Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].Target")
        j = j + 1
    Wend
    i = i + 1
Wend
i = 0
count_i = jResp.SizeOfArray("Policy.PolicyDetails.EventSource.Parameters.SnapshotOwner")
While i < count_i
    jResp.I = i
    strVal = jResp.StringOf("Policy.PolicyDetails.EventSource.Parameters.SnapshotOwner[i]")
    i = i + 1
Wend
i = 0
count_i = jResp.SizeOfArray("Policy.PolicyDetails.ResourceLocations")
While i < count_i
    jResp.I = i
    strVal = jResp.StringOf("Policy.PolicyDetails.ResourceLocations[i]")
    i = i + 1
Wend
i = 0
count_i = jResp.SizeOfArray("Policy.PolicyDetails.ResourceTypes")
While i < count_i
    jResp.I = i
    strVal = jResp.StringOf("Policy.PolicyDetails.ResourceTypes[i]")
    i = i + 1
Wend
i = 0
count_i = jResp.SizeOfArray("Policy.PolicyDetails.Schedules")
While i < count_i
    jResp.I = i
    CopyTags = jResp.IntOf("Policy.PolicyDetails.Schedules[i].CopyTags")
    CronExpression = jResp.StringOf("Policy.PolicyDetails.Schedules[i].CreateRule.CronExpression")
    CreateRuleInterval = jResp.IntOf("Policy.PolicyDetails.Schedules[i].CreateRule.Interval")
    CreateRuleIntervalUnit = jResp.StringOf("Policy.PolicyDetails.Schedules[i].CreateRule.IntervalUnit")
    Location = jResp.StringOf("Policy.PolicyDetails.Schedules[i].CreateRule.Location")
    Count = jResp.IntOf("Policy.PolicyDetails.Schedules[i].DeprecateRule.Count")
    DeprecateRuleInterval = jResp.IntOf("Policy.PolicyDetails.Schedules[i].DeprecateRule.Interval")
    DeprecateRuleIntervalUnit = jResp.StringOf("Policy.PolicyDetails.Schedules[i].DeprecateRule.IntervalUnit")
    FastRestoreRuleCount = jResp.IntOf("Policy.PolicyDetails.Schedules[i].FastRestoreRule.Count")
    FastRestoreRuleInterval = jResp.IntOf("Policy.PolicyDetails.Schedules[i].FastRestoreRule.Interval")
    FastRestoreRuleIntervalUnit = jResp.StringOf("Policy.PolicyDetails.Schedules[i].FastRestoreRule.IntervalUnit")
    Name = jResp.StringOf("Policy.PolicyDetails.Schedules[i].Name")
    RetainRuleCount = jResp.IntOf("Policy.PolicyDetails.Schedules[i].RetainRule.Count")
    RetainRuleInterval = jResp.IntOf("Policy.PolicyDetails.Schedules[i].RetainRule.Interval")
    RetainRuleIntervalUnit = jResp.StringOf("Policy.PolicyDetails.Schedules[i].RetainRule.IntervalUnit")
    j = 0
    count_j = jResp.SizeOfArray("Policy.PolicyDetails.Schedules[i].CreateRule.Times")
    While j < count_j
        jResp.J = j
        strVal = jResp.StringOf("Policy.PolicyDetails.Schedules[i].CreateRule.Times[j]")
        j = j + 1
    Wend
    j = 0
    count_j = jResp.SizeOfArray("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules")
    While j < count_j
        jResp.J = j
        CmkArn = jResp.StringOf("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].CmkArn")
        CopyTags = jResp.IntOf("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].CopyTags")
        DeprecateRuleInterval = jResp.IntOf("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].DeprecateRule.Interval")
        DeprecateRuleIntervalUnit = jResp.StringOf("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].DeprecateRule.IntervalUnit")
        Encrypted = jResp.IntOf("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].Encrypted")
        RetainRuleInterval = jResp.IntOf("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].RetainRule.Interval")
        RetainRuleIntervalUnit = jResp.StringOf("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].RetainRule.IntervalUnit")
        Target = jResp.StringOf("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].Target")
        TargetRegion = jResp.StringOf("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].TargetRegion")
        j = j + 1
    Wend
    j = 0
    count_j = jResp.SizeOfArray("Policy.PolicyDetails.Schedules[i].FastRestoreRule.AvailabilityZones")
    While j < count_j
        jResp.J = j
        strVal = jResp.StringOf("Policy.PolicyDetails.Schedules[i].FastRestoreRule.AvailabilityZones[j]")
        j = j + 1
    Wend
    j = 0
    count_j = jResp.SizeOfArray("Policy.PolicyDetails.Schedules[i].ShareRules")
    While j < count_j
        jResp.J = j
        UnshareInterval = jResp.IntOf("Policy.PolicyDetails.Schedules[i].ShareRules[j].UnshareInterval")
        UnshareIntervalUnit = jResp.StringOf("Policy.PolicyDetails.Schedules[i].ShareRules[j].UnshareIntervalUnit")
        k = 0
        count_k = jResp.SizeOfArray("Policy.PolicyDetails.Schedules[i].ShareRules[j].TargetAccounts")
        While k < count_k
            jResp.K = k
            strVal = jResp.StringOf("Policy.PolicyDetails.Schedules[i].ShareRules[j].TargetAccounts[k]")
            k = k + 1
        Wend
        j = j + 1
    Wend
    j = 0
    count_j = jResp.SizeOfArray("Policy.PolicyDetails.Schedules[i].TagsToAdd")
    While j < count_j
        jResp.J = j
        Key = jResp.StringOf("Policy.PolicyDetails.Schedules[i].TagsToAdd[j].Key")
        Value = jResp.StringOf("Policy.PolicyDetails.Schedules[i].TagsToAdd[j].Value")
        j = j + 1
    Wend
    j = 0
    count_j = jResp.SizeOfArray("Policy.PolicyDetails.Schedules[i].VariableTags")
    While j < count_j
        jResp.J = j
        Key = jResp.StringOf("Policy.PolicyDetails.Schedules[i].VariableTags[j].Key")
        Value = jResp.StringOf("Policy.PolicyDetails.Schedules[i].VariableTags[j].Value")
        j = j + 1
    Wend
    i = i + 1
Wend
i = 0
count_i = jResp.SizeOfArray("Policy.PolicyDetails.TargetTags")
While i < count_i
    jResp.I = i
    Key = jResp.StringOf("Policy.PolicyDetails.TargetTags[i].Key")
    Value = jResp.StringOf("Policy.PolicyDetails.TargetTags[i].Value")
    i = i + 1
Wend

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

// {
//   "Policy": {
//     "DateCreated": number,
//     "DateModified": number,
//     "Description": "string",
//     "ExecutionRoleArn": "string",
//     "PolicyArn": "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"
//         }
//       ]
//     },
//     "PolicyId": "string",
//     "State": "string",
//     "StatusMessage": "string",
//     "Tags": {
//       "string": "string"
//     }
//   }
// }