DescribeInstances VB6 Example
' This example requires the Chilkat API to have been previously unlocked.
' See Global Unlock Sample for sample code.
Dim rest As New ChilkatRest
Dim success As Long
Dim authAws As New ChilkatAuthAws
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 = "opsworks"
' SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
success = rest.SetAuthAws(authAws)
' URL: https://opsworks.us-west-2.amazonaws.com/
' Use the same region as specified above.
success = rest.Connect("opsworks.us-west-2.amazonaws.com",443,1,1)
If (success <> 1) Then
Debug.Print "ConnectFailReason: " & rest.ConnectFailReason
Debug.Print rest.LastErrorText
Exit Sub
End If
' 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
Dim json As New ChilkatJsonObject
success = json.UpdateString("InstanceIds[0]","string")
success = json.UpdateString("LayerId","string")
success = json.UpdateString("StackId","string")
' The JSON request body created by the above code:
' {
' "InstanceIds": [
' "string"
' ],
' "LayerId": "string",
' "StackId": "string"
' }
success = rest.AddHeader("Content-Type","application/x-amz-json-1.1")
success = rest.AddHeader("X-Amz-Target","OpsWorks_20130218.DescribeInstances")
Dim sbRequestBody As New ChilkatStringBuilder
success = json.EmitSb(sbRequestBody)
Dim sbResponseBody As New ChilkatStringBuilder
success = rest.FullRequestSb("POST","/",sbRequestBody,sbResponseBody)
If (success <> 1) Then
Debug.Print rest.LastErrorText
Exit Sub
End If
Dim respStatusCode As Long
respStatusCode = rest.ResponseStatusCode
Debug.Print "response status code = " & respStatusCode
If (respStatusCode <> 200) Then
Debug.Print "Response Header:"
Debug.Print rest.ResponseHeader
Debug.Print "Response Body:"
Debug.Print sbResponseBody.GetAsString()
Exit Sub
End If
Dim jResp As New ChilkatJsonObject
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 AgentVersion As String
Dim AmiId As String
Dim Architecture As String
Dim Arn As String
Dim AutoScalingType As String
Dim AvailabilityZone As String
Dim CreatedAt As String
Dim EbsOptimized As Long
Dim Ec2InstanceId As String
Dim EcsClusterArn As String
Dim EcsContainerInstanceArn As String
Dim ElasticIp As String
Dim Hostname As String
Dim InfrastructureClass As String
Dim InstallUpdatesOnBoot As Long
Dim InstanceId As String
Dim InstanceProfileArn As String
Dim InstanceType As String
Dim LastServiceErrorId As String
Dim Os As String
Dim Platform As String
Dim PrivateDns As String
Dim PrivateIp As String
Dim PublicDns As String
Dim PublicIp As String
Dim RegisteredBy As String
Dim ReportedAgentVersion As String
Dim Family As String
Dim Name As String
Dim Version As String
Dim RootDeviceType As String
Dim RootDeviceVolumeId As String
Dim SshHostDsaKeyFingerprint As String
Dim SshHostRsaKeyFingerprint As String
Dim SshKeyName As String
Dim StackId As String
Dim Status As String
Dim SubnetId As String
Dim Tenancy As String
Dim VirtualizationType As String
Dim j As Long
Dim count_j As Long
Dim DeviceName As String
Dim DeleteOnTermination As Long
Dim Iops As Long
Dim SnapshotId As String
Dim VolumeSize As Long
Dim VolumeType As String
Dim NoDevice As String
Dim VirtualName As String
Dim strVal As String
Dim i As Long
i = 0
Dim count_i As Long
count_i = jResp.SizeOfArray("Instances")
Do While i < count_i
jResp.I = i
AgentVersion = jResp.StringOf("Instances[i].AgentVersion")
AmiId = jResp.StringOf("Instances[i].AmiId")
Architecture = jResp.StringOf("Instances[i].Architecture")
Arn = jResp.StringOf("Instances[i].Arn")
AutoScalingType = jResp.StringOf("Instances[i].AutoScalingType")
AvailabilityZone = jResp.StringOf("Instances[i].AvailabilityZone")
CreatedAt = jResp.StringOf("Instances[i].CreatedAt")
EbsOptimized = jResp.IntOf("Instances[i].EbsOptimized")
Ec2InstanceId = jResp.StringOf("Instances[i].Ec2InstanceId")
EcsClusterArn = jResp.StringOf("Instances[i].EcsClusterArn")
EcsContainerInstanceArn = jResp.StringOf("Instances[i].EcsContainerInstanceArn")
ElasticIp = jResp.StringOf("Instances[i].ElasticIp")
Hostname = jResp.StringOf("Instances[i].Hostname")
InfrastructureClass = jResp.StringOf("Instances[i].InfrastructureClass")
InstallUpdatesOnBoot = jResp.IntOf("Instances[i].InstallUpdatesOnBoot")
InstanceId = jResp.StringOf("Instances[i].InstanceId")
InstanceProfileArn = jResp.StringOf("Instances[i].InstanceProfileArn")
InstanceType = jResp.StringOf("Instances[i].InstanceType")
LastServiceErrorId = jResp.StringOf("Instances[i].LastServiceErrorId")
Os = jResp.StringOf("Instances[i].Os")
Platform = jResp.StringOf("Instances[i].Platform")
PrivateDns = jResp.StringOf("Instances[i].PrivateDns")
PrivateIp = jResp.StringOf("Instances[i].PrivateIp")
PublicDns = jResp.StringOf("Instances[i].PublicDns")
PublicIp = jResp.StringOf("Instances[i].PublicIp")
RegisteredBy = jResp.StringOf("Instances[i].RegisteredBy")
ReportedAgentVersion = jResp.StringOf("Instances[i].ReportedAgentVersion")
Family = jResp.StringOf("Instances[i].ReportedOs.Family")
Name = jResp.StringOf("Instances[i].ReportedOs.Name")
Version = jResp.StringOf("Instances[i].ReportedOs.Version")
RootDeviceType = jResp.StringOf("Instances[i].RootDeviceType")
RootDeviceVolumeId = jResp.StringOf("Instances[i].RootDeviceVolumeId")
SshHostDsaKeyFingerprint = jResp.StringOf("Instances[i].SshHostDsaKeyFingerprint")
SshHostRsaKeyFingerprint = jResp.StringOf("Instances[i].SshHostRsaKeyFingerprint")
SshKeyName = jResp.StringOf("Instances[i].SshKeyName")
StackId = jResp.StringOf("Instances[i].StackId")
Status = jResp.StringOf("Instances[i].Status")
SubnetId = jResp.StringOf("Instances[i].SubnetId")
Tenancy = jResp.StringOf("Instances[i].Tenancy")
VirtualizationType = jResp.StringOf("Instances[i].VirtualizationType")
j = 0
count_j = jResp.SizeOfArray("Instances[i].BlockDeviceMappings")
Do While j < count_j
jResp.J = j
DeviceName = jResp.StringOf("Instances[i].BlockDeviceMappings[j].DeviceName")
DeleteOnTermination = jResp.IntOf("Instances[i].BlockDeviceMappings[j].Ebs.DeleteOnTermination")
Iops = jResp.IntOf("Instances[i].BlockDeviceMappings[j].Ebs.Iops")
SnapshotId = jResp.StringOf("Instances[i].BlockDeviceMappings[j].Ebs.SnapshotId")
VolumeSize = jResp.IntOf("Instances[i].BlockDeviceMappings[j].Ebs.VolumeSize")
VolumeType = jResp.StringOf("Instances[i].BlockDeviceMappings[j].Ebs.VolumeType")
NoDevice = jResp.StringOf("Instances[i].BlockDeviceMappings[j].NoDevice")
VirtualName = jResp.StringOf("Instances[i].BlockDeviceMappings[j].VirtualName")
j = j + 1
Loop
j = 0
count_j = jResp.SizeOfArray("Instances[i].LayerIds")
Do While j < count_j
jResp.J = j
strVal = jResp.StringOf("Instances[i].LayerIds[j]")
j = j + 1
Loop
j = 0
count_j = jResp.SizeOfArray("Instances[i].SecurityGroupIds")
Do While j < count_j
jResp.J = j
strVal = jResp.StringOf("Instances[i].SecurityGroupIds[j]")
j = j + 1
Loop
i = i + 1
Loop
' A sample JSON response body parsed by the above code:
' {
' "Instances": [
' {
' "AgentVersion": "string",
' "AmiId": "string",
' "Architecture": "string",
' "Arn": "string",
' "AutoScalingType": "string",
' "AvailabilityZone": "string",
' "BlockDeviceMappings": [
' {
' "DeviceName": "string",
' "Ebs": {
' "DeleteOnTermination": boolean,
' "Iops": number,
' "SnapshotId": "string",
' "VolumeSize": number,
' "VolumeType": "string"
' },
' "NoDevice": "string",
' "VirtualName": "string"
' }
' ],
' "CreatedAt": "string",
' "EbsOptimized": boolean,
' "Ec2InstanceId": "string",
' "EcsClusterArn": "string",
' "EcsContainerInstanceArn": "string",
' "ElasticIp": "string",
' "Hostname": "string",
' "InfrastructureClass": "string",
' "InstallUpdatesOnBoot": boolean,
' "InstanceId": "string",
' "InstanceProfileArn": "string",
' "InstanceType": "string",
' "LastServiceErrorId": "string",
' "LayerIds": [
' "string"
' ],
' "Os": "string",
' "Platform": "string",
' "PrivateDns": "string",
' "PrivateIp": "string",
' "PublicDns": "string",
' "PublicIp": "string",
' "RegisteredBy": "string",
' "ReportedAgentVersion": "string",
' "ReportedOs": {
' "Family": "string",
' "Name": "string",
' "Version": "string"
' },
' "RootDeviceType": "string",
' "RootDeviceVolumeId": "string",
' "SecurityGroupIds": [
' "string"
' ],
' "SshHostDsaKeyFingerprint": "string",
' "SshHostRsaKeyFingerprint": "string",
' "SshKeyName": "string",
' "StackId": "string",
' "Status": "string",
' "SubnetId": "string",
' "Tenancy": "string",
' "VirtualizationType": "string"
' }
' ]
' }