Chilkat Online Tools

DescribeInstances autoit Example

AWS OpsWorks

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

$oRest = ObjCreate("Chilkat_9_5_0.Rest")
Local $bSuccess

$oAuthAws = ObjCreate("Chilkat_9_5_0.AuthAws")
$oAuthAws.AccessKey = "AWS_ACCESS_KEY"
$oAuthAws.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.)
$oAuthAws.Region = "us-west-2"
$oAuthAws.ServiceName = "opsworks"
; SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
$oRest.SetAuthAws($oAuthAws)

; URL: https://opsworks.us-west-2.amazonaws.com/
; Use the same region as specified above.
$bSuccess = $oRest.Connect("opsworks.us-west-2.amazonaws.com",443,True,True)
If ($bSuccess <> True) Then
    ConsoleWrite("ConnectFailReason: " & $oRest.ConnectFailReason & @CRLF)
    ConsoleWrite($oRest.LastErrorText & @CRLF)
    Exit
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

$oJson = ObjCreate("Chilkat_9_5_0.JsonObject")
$oJson.UpdateString("InstanceIds[0]","string")
$oJson.UpdateString("LayerId","string")
$oJson.UpdateString("StackId","string")

; The JSON request body created by the above code:

; {
;   "InstanceIds": [
;     "string"
;   ],
;   "LayerId": "string",
;   "StackId": "string"
; }

$oRest.AddHeader("Content-Type","application/x-amz-json-1.1")
$oRest.AddHeader("X-Amz-Target","OpsWorks_20130218.DescribeInstances")

$oSbRequestBody = ObjCreate("Chilkat_9_5_0.StringBuilder")
$oJson.EmitSb($oSbRequestBody)
$oSbResponseBody = ObjCreate("Chilkat_9_5_0.StringBuilder")
$bSuccess = $oRest.FullRequestSb("POST","/",$oSbRequestBody,$oSbResponseBody)
If ($bSuccess <> True) Then
    ConsoleWrite($oRest.LastErrorText & @CRLF)
    Exit
EndIf

Local $iRespStatusCode = $oRest.ResponseStatusCode
ConsoleWrite("response status code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode <> 200) Then
    ConsoleWrite("Response Header:" & @CRLF)
    ConsoleWrite($oRest.ResponseHeader & @CRLF)
    ConsoleWrite("Response Body:" & @CRLF)
    ConsoleWrite($oSbResponseBody.GetAsString() & @CRLF)
    Exit
EndIf

$oJResp = ObjCreate("Chilkat_9_5_0.JsonObject")
$oJResp.LoadSb($oSbResponseBody)

; 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

Local $sAgentVersion
Local $sAmiId
Local $sArchitecture
Local $sArn
Local $sAutoScalingType
Local $sAvailabilityZone
Local $sCreatedAt
Local $iEbsOptimized
Local $sEc2InstanceId
Local $sEcsClusterArn
Local $sEcsContainerInstanceArn
Local $sElasticIp
Local $sHostname
Local $sInfrastructureClass
Local $iInstallUpdatesOnBoot
Local $sInstanceId
Local $sInstanceProfileArn
Local $sInstanceType
Local $sLastServiceErrorId
Local $sOs
Local $sPlatform
Local $sPrivateDns
Local $sPrivateIp
Local $sPublicDns
Local $sPublicIp
Local $sRegisteredBy
Local $sReportedAgentVersion
Local $sFamily
Local $sName
Local $sVersion
Local $sRootDeviceType
Local $sRootDeviceVolumeId
Local $sSshHostDsaKeyFingerprint
Local $sSshHostRsaKeyFingerprint
Local $sSshKeyName
Local $sStackId
Local $sStatus
Local $sSubnetId
Local $sTenancy
Local $sVirtualizationType
Local $iJ
Local $iCount_j
Local $sDeviceName
Local $iDeleteOnTermination
Local $iIops
Local $sSnapshotId
Local $iVolumeSize
Local $sVolumeType
Local $sNoDevice
Local $sVirtualName
Local $strVal

Local $i = 0
Local $iCount_i = $oJResp.SizeOfArray("Instances")
While $i < $iCount_i
    $oJResp.I = $i
    $sAgentVersion = $oJResp.StringOf("Instances[i].AgentVersion")
    $sAmiId = $oJResp.StringOf("Instances[i].AmiId")
    $sArchitecture = $oJResp.StringOf("Instances[i].Architecture")
    $sArn = $oJResp.StringOf("Instances[i].Arn")
    $sAutoScalingType = $oJResp.StringOf("Instances[i].AutoScalingType")
    $sAvailabilityZone = $oJResp.StringOf("Instances[i].AvailabilityZone")
    $sCreatedAt = $oJResp.StringOf("Instances[i].CreatedAt")
    $iEbsOptimized = $oJResp.IntOf("Instances[i].EbsOptimized")
    $sEc2InstanceId = $oJResp.StringOf("Instances[i].Ec2InstanceId")
    $sEcsClusterArn = $oJResp.StringOf("Instances[i].EcsClusterArn")
    $sEcsContainerInstanceArn = $oJResp.StringOf("Instances[i].EcsContainerInstanceArn")
    $sElasticIp = $oJResp.StringOf("Instances[i].ElasticIp")
    $sHostname = $oJResp.StringOf("Instances[i].Hostname")
    $sInfrastructureClass = $oJResp.StringOf("Instances[i].InfrastructureClass")
    $iInstallUpdatesOnBoot = $oJResp.IntOf("Instances[i].InstallUpdatesOnBoot")
    $sInstanceId = $oJResp.StringOf("Instances[i].InstanceId")
    $sInstanceProfileArn = $oJResp.StringOf("Instances[i].InstanceProfileArn")
    $sInstanceType = $oJResp.StringOf("Instances[i].InstanceType")
    $sLastServiceErrorId = $oJResp.StringOf("Instances[i].LastServiceErrorId")
    $sOs = $oJResp.StringOf("Instances[i].Os")
    $sPlatform = $oJResp.StringOf("Instances[i].Platform")
    $sPrivateDns = $oJResp.StringOf("Instances[i].PrivateDns")
    $sPrivateIp = $oJResp.StringOf("Instances[i].PrivateIp")
    $sPublicDns = $oJResp.StringOf("Instances[i].PublicDns")
    $sPublicIp = $oJResp.StringOf("Instances[i].PublicIp")
    $sRegisteredBy = $oJResp.StringOf("Instances[i].RegisteredBy")
    $sReportedAgentVersion = $oJResp.StringOf("Instances[i].ReportedAgentVersion")
    $sFamily = $oJResp.StringOf("Instances[i].ReportedOs.Family")
    $sName = $oJResp.StringOf("Instances[i].ReportedOs.Name")
    $sVersion = $oJResp.StringOf("Instances[i].ReportedOs.Version")
    $sRootDeviceType = $oJResp.StringOf("Instances[i].RootDeviceType")
    $sRootDeviceVolumeId = $oJResp.StringOf("Instances[i].RootDeviceVolumeId")
    $sSshHostDsaKeyFingerprint = $oJResp.StringOf("Instances[i].SshHostDsaKeyFingerprint")
    $sSshHostRsaKeyFingerprint = $oJResp.StringOf("Instances[i].SshHostRsaKeyFingerprint")
    $sSshKeyName = $oJResp.StringOf("Instances[i].SshKeyName")
    $sStackId = $oJResp.StringOf("Instances[i].StackId")
    $sStatus = $oJResp.StringOf("Instances[i].Status")
    $sSubnetId = $oJResp.StringOf("Instances[i].SubnetId")
    $sTenancy = $oJResp.StringOf("Instances[i].Tenancy")
    $sVirtualizationType = $oJResp.StringOf("Instances[i].VirtualizationType")
    $iJ = 0
    $iCount_j = $oJResp.SizeOfArray("Instances[i].BlockDeviceMappings")
    While $iJ < $iCount_j
        $oJResp.J = $iJ
        $sDeviceName = $oJResp.StringOf("Instances[i].BlockDeviceMappings[j].DeviceName")
        $iDeleteOnTermination = $oJResp.IntOf("Instances[i].BlockDeviceMappings[j].Ebs.DeleteOnTermination")
        $iIops = $oJResp.IntOf("Instances[i].BlockDeviceMappings[j].Ebs.Iops")
        $sSnapshotId = $oJResp.StringOf("Instances[i].BlockDeviceMappings[j].Ebs.SnapshotId")
        $iVolumeSize = $oJResp.IntOf("Instances[i].BlockDeviceMappings[j].Ebs.VolumeSize")
        $sVolumeType = $oJResp.StringOf("Instances[i].BlockDeviceMappings[j].Ebs.VolumeType")
        $sNoDevice = $oJResp.StringOf("Instances[i].BlockDeviceMappings[j].NoDevice")
        $sVirtualName = $oJResp.StringOf("Instances[i].BlockDeviceMappings[j].VirtualName")
        $iJ = $iJ + 1
    Wend
    $iJ = 0
    $iCount_j = $oJResp.SizeOfArray("Instances[i].LayerIds")
    While $iJ < $iCount_j
        $oJResp.J = $iJ
        $strVal = $oJResp.StringOf("Instances[i].LayerIds[j]")
        $iJ = $iJ + 1
    Wend
    $iJ = 0
    $iCount_j = $oJResp.SizeOfArray("Instances[i].SecurityGroupIds")
    While $iJ < $iCount_j
        $oJResp.J = $iJ
        $strVal = $oJResp.StringOf("Instances[i].SecurityGroupIds[j]")
        $iJ = $iJ + 1
    Wend
    $i = $i + 1
Wend

; 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"
;     }
;   ]
; }