DescribeInstances Foxpro Example
LOCAL loRest
LOCAL lnSuccess
LOCAL loAuthAws
LOCAL loJson
LOCAL loSbRequestBody
LOCAL loSbResponseBody
LOCAL lnRespStatusCode
LOCAL loJResp
LOCAL lcAgentVersion
LOCAL lcAmiId
LOCAL lcArchitecture
LOCAL lcArn
LOCAL lcAutoScalingType
LOCAL lcAvailabilityZone
LOCAL lcCreatedAt
LOCAL lnEbsOptimized
LOCAL lcEc2InstanceId
LOCAL lcEcsClusterArn
LOCAL lcEcsContainerInstanceArn
LOCAL lcElasticIp
LOCAL lcHostname
LOCAL lcInfrastructureClass
LOCAL lnInstallUpdatesOnBoot
LOCAL lcInstanceId
LOCAL lcInstanceProfileArn
LOCAL lcInstanceType
LOCAL lcLastServiceErrorId
LOCAL lcOs
LOCAL lcPlatform
LOCAL lcPrivateDns
LOCAL lcPrivateIp
LOCAL lcPublicDns
LOCAL lcPublicIp
LOCAL lcRegisteredBy
LOCAL lcReportedAgentVersion
LOCAL lcFamily
LOCAL lcName
LOCAL lcVersion
LOCAL lcRootDeviceType
LOCAL lcRootDeviceVolumeId
LOCAL lcSshHostDsaKeyFingerprint
LOCAL lcSshHostRsaKeyFingerprint
LOCAL lcSshKeyName
LOCAL lcStackId
LOCAL lcStatus
LOCAL lcSubnetId
LOCAL lcTenancy
LOCAL lcVirtualizationType
LOCAL j
LOCAL lnCount_j
LOCAL lcDeviceName
LOCAL lnDeleteOnTermination
LOCAL lnIops
LOCAL lcSnapshotId
LOCAL lnVolumeSize
LOCAL lcVolumeType
LOCAL lcNoDevice
LOCAL lcVirtualName
LOCAL lcStrVal
LOCAL i
LOCAL lnCount_i
* This example requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
loRest = CreateObject('Chilkat_9_5_0.Rest')
loAuthAws = CreateObject('Chilkat_9_5_0.AuthAws')
loAuthAws.AccessKey = "AWS_ACCESS_KEY"
loAuthAws.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.)
loAuthAws.Region = "us-west-2"
loAuthAws.ServiceName = "opsworks"
* SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
loRest.SetAuthAws(loAuthAws)
* URL: https://opsworks.us-west-2.amazonaws.com/
* Use the same region as specified above.
lnSuccess = loRest.Connect("opsworks.us-west-2.amazonaws.com",443,1,1)
IF (lnSuccess <> 1) THEN
? "ConnectFailReason: " + STR(loRest.ConnectFailReason)
? loRest.LastErrorText
RELEASE loRest
RELEASE loAuthAws
CANCEL
ENDIF
* 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
loJson = CreateObject('Chilkat_9_5_0.JsonObject')
loJson.UpdateString("InstanceIds[0]","string")
loJson.UpdateString("LayerId","string")
loJson.UpdateString("StackId","string")
* The JSON request body created by the above code:
* {
* "InstanceIds": [
* "string"
* ],
* "LayerId": "string",
* "StackId": "string"
* }
loRest.AddHeader("Content-Type","application/x-amz-json-1.1")
loRest.AddHeader("X-Amz-Target","OpsWorks_20130218.DescribeInstances")
loSbRequestBody = CreateObject('Chilkat_9_5_0.StringBuilder')
loJson.EmitSb(loSbRequestBody)
loSbResponseBody = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestSb("POST","/",loSbRequestBody,loSbResponseBody)
IF (lnSuccess <> 1) THEN
? loRest.LastErrorText
RELEASE loRest
RELEASE loAuthAws
RELEASE loJson
RELEASE loSbRequestBody
RELEASE loSbResponseBody
CANCEL
ENDIF
lnRespStatusCode = loRest.ResponseStatusCode
? "response status code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode <> 200) THEN
? "Response Header:"
? loRest.ResponseHeader
? "Response Body:"
? loSbResponseBody.GetAsString()
RELEASE loRest
RELEASE loAuthAws
RELEASE loJson
RELEASE loSbRequestBody
RELEASE loSbResponseBody
CANCEL
ENDIF
loJResp = CreateObject('Chilkat_9_5_0.JsonObject')
loJResp.LoadSb(loSbResponseBody)
* 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
i = 0
lnCount_i = loJResp.SizeOfArray("Instances")
DO WHILE i < lnCount_i
loJResp.I = i
lcAgentVersion = loJResp.StringOf("Instances[i].AgentVersion")
lcAmiId = loJResp.StringOf("Instances[i].AmiId")
lcArchitecture = loJResp.StringOf("Instances[i].Architecture")
lcArn = loJResp.StringOf("Instances[i].Arn")
lcAutoScalingType = loJResp.StringOf("Instances[i].AutoScalingType")
lcAvailabilityZone = loJResp.StringOf("Instances[i].AvailabilityZone")
lcCreatedAt = loJResp.StringOf("Instances[i].CreatedAt")
lnEbsOptimized = loJResp.IntOf("Instances[i].EbsOptimized")
lcEc2InstanceId = loJResp.StringOf("Instances[i].Ec2InstanceId")
lcEcsClusterArn = loJResp.StringOf("Instances[i].EcsClusterArn")
lcEcsContainerInstanceArn = loJResp.StringOf("Instances[i].EcsContainerInstanceArn")
lcElasticIp = loJResp.StringOf("Instances[i].ElasticIp")
lcHostname = loJResp.StringOf("Instances[i].Hostname")
lcInfrastructureClass = loJResp.StringOf("Instances[i].InfrastructureClass")
lnInstallUpdatesOnBoot = loJResp.IntOf("Instances[i].InstallUpdatesOnBoot")
lcInstanceId = loJResp.StringOf("Instances[i].InstanceId")
lcInstanceProfileArn = loJResp.StringOf("Instances[i].InstanceProfileArn")
lcInstanceType = loJResp.StringOf("Instances[i].InstanceType")
lcLastServiceErrorId = loJResp.StringOf("Instances[i].LastServiceErrorId")
lcOs = loJResp.StringOf("Instances[i].Os")
lcPlatform = loJResp.StringOf("Instances[i].Platform")
lcPrivateDns = loJResp.StringOf("Instances[i].PrivateDns")
lcPrivateIp = loJResp.StringOf("Instances[i].PrivateIp")
lcPublicDns = loJResp.StringOf("Instances[i].PublicDns")
lcPublicIp = loJResp.StringOf("Instances[i].PublicIp")
lcRegisteredBy = loJResp.StringOf("Instances[i].RegisteredBy")
lcReportedAgentVersion = loJResp.StringOf("Instances[i].ReportedAgentVersion")
lcFamily = loJResp.StringOf("Instances[i].ReportedOs.Family")
lcName = loJResp.StringOf("Instances[i].ReportedOs.Name")
lcVersion = loJResp.StringOf("Instances[i].ReportedOs.Version")
lcRootDeviceType = loJResp.StringOf("Instances[i].RootDeviceType")
lcRootDeviceVolumeId = loJResp.StringOf("Instances[i].RootDeviceVolumeId")
lcSshHostDsaKeyFingerprint = loJResp.StringOf("Instances[i].SshHostDsaKeyFingerprint")
lcSshHostRsaKeyFingerprint = loJResp.StringOf("Instances[i].SshHostRsaKeyFingerprint")
lcSshKeyName = loJResp.StringOf("Instances[i].SshKeyName")
lcStackId = loJResp.StringOf("Instances[i].StackId")
lcStatus = loJResp.StringOf("Instances[i].Status")
lcSubnetId = loJResp.StringOf("Instances[i].SubnetId")
lcTenancy = loJResp.StringOf("Instances[i].Tenancy")
lcVirtualizationType = loJResp.StringOf("Instances[i].VirtualizationType")
j = 0
lnCount_j = loJResp.SizeOfArray("Instances[i].BlockDeviceMappings")
DO WHILE j < lnCount_j
loJResp.J = j
lcDeviceName = loJResp.StringOf("Instances[i].BlockDeviceMappings[j].DeviceName")
lnDeleteOnTermination = loJResp.IntOf("Instances[i].BlockDeviceMappings[j].Ebs.DeleteOnTermination")
lnIops = loJResp.IntOf("Instances[i].BlockDeviceMappings[j].Ebs.Iops")
lcSnapshotId = loJResp.StringOf("Instances[i].BlockDeviceMappings[j].Ebs.SnapshotId")
lnVolumeSize = loJResp.IntOf("Instances[i].BlockDeviceMappings[j].Ebs.VolumeSize")
lcVolumeType = loJResp.StringOf("Instances[i].BlockDeviceMappings[j].Ebs.VolumeType")
lcNoDevice = loJResp.StringOf("Instances[i].BlockDeviceMappings[j].NoDevice")
lcVirtualName = loJResp.StringOf("Instances[i].BlockDeviceMappings[j].VirtualName")
j = j + 1
ENDDO
j = 0
lnCount_j = loJResp.SizeOfArray("Instances[i].LayerIds")
DO WHILE j < lnCount_j
loJResp.J = j
lcStrVal = loJResp.StringOf("Instances[i].LayerIds[j]")
j = j + 1
ENDDO
j = 0
lnCount_j = loJResp.SizeOfArray("Instances[i].SecurityGroupIds")
DO WHILE j < lnCount_j
loJResp.J = j
lcStrVal = loJResp.StringOf("Instances[i].SecurityGroupIds[j]")
j = j + 1
ENDDO
i = i + 1
ENDDO
* 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"
* }
* ]
* }
RELEASE loRest
RELEASE loAuthAws
RELEASE loJson
RELEASE loSbRequestBody
RELEASE loSbResponseBody
RELEASE loJResp