DescribeInstances DataFlex Example
Use ChilkatAx-9.5.0-win32.pkg
Procedure Test
Handle hoRest
Boolean iSuccess
Variant vAuthAws
Handle hoAuthAws
Handle hoJson
Variant vSbRequestBody
Handle hoSbRequestBody
Variant vSbResponseBody
Handle hoSbResponseBody
Integer iRespStatusCode
Handle hoJResp
String sAgentVersion
String sAmiId
String sArchitecture
String sArn
String sAutoScalingType
String sAvailabilityZone
String sCreatedAt
Integer iEbsOptimized
String sEc2InstanceId
String sEcsClusterArn
String sEcsContainerInstanceArn
String sElasticIp
String sHostname
String sInfrastructureClass
Integer iInstallUpdatesOnBoot
String sInstanceId
String sInstanceProfileArn
String sInstanceType
String sLastServiceErrorId
String sOs
String sPlatform
String sPrivateDns
String sPrivateIp
String sPublicDns
String sPublicIp
String sRegisteredBy
String sReportedAgentVersion
String sFamily
String sName
String sVersion
String sRootDeviceType
String sRootDeviceVolumeId
String sSshHostDsaKeyFingerprint
String sSshHostRsaKeyFingerprint
String sSshKeyName
String sStackId
String sStatus
String sSubnetId
String sTenancy
String sVirtualizationType
Integer j
Integer iCount_j
String sDeviceName
Integer iDeleteOnTermination
Integer iIops
String sSnapshotId
Integer iVolumeSize
String sVolumeType
String sNoDevice
String sVirtualName
String sStrVal
Integer i
Integer iCount_i
String sTemp1
Integer iTemp1
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatRest)) To hoRest
If (Not(IsComObjectCreated(hoRest))) Begin
Send CreateComObject of hoRest
End
Get Create (RefClass(cComChilkatAuthAws)) To hoAuthAws
If (Not(IsComObjectCreated(hoAuthAws))) Begin
Send CreateComObject of hoAuthAws
End
Set ComAccessKey Of hoAuthAws To "AWS_ACCESS_KEY"
Set ComSecretKey Of hoAuthAws To "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.)
Set ComRegion Of hoAuthAws To "us-west-2"
Set ComServiceName Of hoAuthAws To "opsworks"
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
Get pvComObject of hoAuthAws to vAuthAws
Get ComSetAuthAws Of hoRest vAuthAws To iSuccess
// URL: https://opsworks.us-west-2.amazonaws.com/
// Use the same region as specified above.
Get ComConnect Of hoRest "opsworks.us-west-2.amazonaws.com" 443 True True To iSuccess
If (iSuccess <> True) Begin
Get ComConnectFailReason Of hoRest To iTemp1
Showln "ConnectFailReason: " iTemp1
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
// 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
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get ComUpdateString Of hoJson "InstanceIds[0]" "string" To iSuccess
Get ComUpdateString Of hoJson "LayerId" "string" To iSuccess
Get ComUpdateString Of hoJson "StackId" "string" To iSuccess
// The JSON request body created by the above code:
// {
// "InstanceIds": [
// "string"
// ],
// "LayerId": "string",
// "StackId": "string"
// }
Get ComAddHeader Of hoRest "Content-Type" "application/x-amz-json-1.1" To iSuccess
Get ComAddHeader Of hoRest "X-Amz-Target" "OpsWorks_20130218.DescribeInstances" To iSuccess
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbRequestBody
If (Not(IsComObjectCreated(hoSbRequestBody))) Begin
Send CreateComObject of hoSbRequestBody
End
Get pvComObject of hoSbRequestBody to vSbRequestBody
Get ComEmitSb Of hoJson vSbRequestBody To iSuccess
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
Send CreateComObject of hoSbResponseBody
End
Get pvComObject of hoSbRequestBody to vSbRequestBody
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComFullRequestSb Of hoRest "POST" "/" vSbRequestBody vSbResponseBody To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComResponseStatusCode Of hoRest To iRespStatusCode
Showln "response status code = " iRespStatusCode
If (iRespStatusCode <> 200) Begin
Showln "Response Header:"
Get ComResponseHeader Of hoRest To sTemp1
Showln sTemp1
Showln "Response Body:"
Get ComGetAsString Of hoSbResponseBody To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
If (Not(IsComObjectCreated(hoJResp))) Begin
Send CreateComObject of hoJResp
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
// 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
Move 0 To i
Get ComSizeOfArray Of hoJResp "Instances" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Get ComStringOf Of hoJResp "Instances[i].AgentVersion" To sAgentVersion
Get ComStringOf Of hoJResp "Instances[i].AmiId" To sAmiId
Get ComStringOf Of hoJResp "Instances[i].Architecture" To sArchitecture
Get ComStringOf Of hoJResp "Instances[i].Arn" To sArn
Get ComStringOf Of hoJResp "Instances[i].AutoScalingType" To sAutoScalingType
Get ComStringOf Of hoJResp "Instances[i].AvailabilityZone" To sAvailabilityZone
Get ComStringOf Of hoJResp "Instances[i].CreatedAt" To sCreatedAt
Get ComIntOf Of hoJResp "Instances[i].EbsOptimized" To iEbsOptimized
Get ComStringOf Of hoJResp "Instances[i].Ec2InstanceId" To sEc2InstanceId
Get ComStringOf Of hoJResp "Instances[i].EcsClusterArn" To sEcsClusterArn
Get ComStringOf Of hoJResp "Instances[i].EcsContainerInstanceArn" To sEcsContainerInstanceArn
Get ComStringOf Of hoJResp "Instances[i].ElasticIp" To sElasticIp
Get ComStringOf Of hoJResp "Instances[i].Hostname" To sHostname
Get ComStringOf Of hoJResp "Instances[i].InfrastructureClass" To sInfrastructureClass
Get ComIntOf Of hoJResp "Instances[i].InstallUpdatesOnBoot" To iInstallUpdatesOnBoot
Get ComStringOf Of hoJResp "Instances[i].InstanceId" To sInstanceId
Get ComStringOf Of hoJResp "Instances[i].InstanceProfileArn" To sInstanceProfileArn
Get ComStringOf Of hoJResp "Instances[i].InstanceType" To sInstanceType
Get ComStringOf Of hoJResp "Instances[i].LastServiceErrorId" To sLastServiceErrorId
Get ComStringOf Of hoJResp "Instances[i].Os" To sOs
Get ComStringOf Of hoJResp "Instances[i].Platform" To sPlatform
Get ComStringOf Of hoJResp "Instances[i].PrivateDns" To sPrivateDns
Get ComStringOf Of hoJResp "Instances[i].PrivateIp" To sPrivateIp
Get ComStringOf Of hoJResp "Instances[i].PublicDns" To sPublicDns
Get ComStringOf Of hoJResp "Instances[i].PublicIp" To sPublicIp
Get ComStringOf Of hoJResp "Instances[i].RegisteredBy" To sRegisteredBy
Get ComStringOf Of hoJResp "Instances[i].ReportedAgentVersion" To sReportedAgentVersion
Get ComStringOf Of hoJResp "Instances[i].ReportedOs.Family" To sFamily
Get ComStringOf Of hoJResp "Instances[i].ReportedOs.Name" To sName
Get ComStringOf Of hoJResp "Instances[i].ReportedOs.Version" To sVersion
Get ComStringOf Of hoJResp "Instances[i].RootDeviceType" To sRootDeviceType
Get ComStringOf Of hoJResp "Instances[i].RootDeviceVolumeId" To sRootDeviceVolumeId
Get ComStringOf Of hoJResp "Instances[i].SshHostDsaKeyFingerprint" To sSshHostDsaKeyFingerprint
Get ComStringOf Of hoJResp "Instances[i].SshHostRsaKeyFingerprint" To sSshHostRsaKeyFingerprint
Get ComStringOf Of hoJResp "Instances[i].SshKeyName" To sSshKeyName
Get ComStringOf Of hoJResp "Instances[i].StackId" To sStackId
Get ComStringOf Of hoJResp "Instances[i].Status" To sStatus
Get ComStringOf Of hoJResp "Instances[i].SubnetId" To sSubnetId
Get ComStringOf Of hoJResp "Instances[i].Tenancy" To sTenancy
Get ComStringOf Of hoJResp "Instances[i].VirtualizationType" To sVirtualizationType
Move 0 To j
Get ComSizeOfArray Of hoJResp "Instances[i].BlockDeviceMappings" To iCount_j
While (j < iCount_j)
Set ComJ Of hoJResp To j
Get ComStringOf Of hoJResp "Instances[i].BlockDeviceMappings[j].DeviceName" To sDeviceName
Get ComIntOf Of hoJResp "Instances[i].BlockDeviceMappings[j].Ebs.DeleteOnTermination" To iDeleteOnTermination
Get ComIntOf Of hoJResp "Instances[i].BlockDeviceMappings[j].Ebs.Iops" To iIops
Get ComStringOf Of hoJResp "Instances[i].BlockDeviceMappings[j].Ebs.SnapshotId" To sSnapshotId
Get ComIntOf Of hoJResp "Instances[i].BlockDeviceMappings[j].Ebs.VolumeSize" To iVolumeSize
Get ComStringOf Of hoJResp "Instances[i].BlockDeviceMappings[j].Ebs.VolumeType" To sVolumeType
Get ComStringOf Of hoJResp "Instances[i].BlockDeviceMappings[j].NoDevice" To sNoDevice
Get ComStringOf Of hoJResp "Instances[i].BlockDeviceMappings[j].VirtualName" To sVirtualName
Move (j + 1) To j
Loop
Move 0 To j
Get ComSizeOfArray Of hoJResp "Instances[i].LayerIds" To iCount_j
While (j < iCount_j)
Set ComJ Of hoJResp To j
Get ComStringOf Of hoJResp "Instances[i].LayerIds[j]" To sStrVal
Move (j + 1) To j
Loop
Move 0 To j
Get ComSizeOfArray Of hoJResp "Instances[i].SecurityGroupIds" To iCount_j
While (j < iCount_j)
Set ComJ Of hoJResp To j
Get ComStringOf Of hoJResp "Instances[i].SecurityGroupIds[j]" To sStrVal
Move (j + 1) To j
Loop
Move (i + 1) To i
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"
// }
// ]
// }
End_Procedure