Chilkat Online Tools

DescribeInstances phpExt Example

AWS OpsWorks

<?php

// The version number (9_5_0) should match version of the Chilkat extension used, omitting the micro-version number.
// For example, if using Chilkat v9.5.0.48, then include as shown here:
include("chilkat_9_5_0.php");

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

$rest = new CkRest();

$authAws = new CkAuthAws();
$authAws->put_AccessKey('AWS_ACCESS_KEY');
$authAws->put_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->put_Region('us-west-2');
$authAws->put_ServiceName('opsworks');
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
$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,true,true);
if ($success != true) {
    print 'ConnectFailReason: ' . $rest->get_ConnectFailReason() . "\n";
    print $rest->lastErrorText() . "\n";
    exit;
}

// 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

$json = new CkJsonObject();
$json->UpdateString('InstanceIds[0]','string');
$json->UpdateString('LayerId','string');
$json->UpdateString('StackId','string');

// The JSON request body created by the above code:

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

$rest->AddHeader('Content-Type','application/x-amz-json-1.1');
$rest->AddHeader('X-Amz-Target','OpsWorks_20130218.DescribeInstances');

$sbRequestBody = new CkStringBuilder();
$json->EmitSb($sbRequestBody);
$sbResponseBody = new CkStringBuilder();
$success = $rest->FullRequestSb('POST','/',$sbRequestBody,$sbResponseBody);
if ($success != true) {
    print $rest->lastErrorText() . "\n";
    exit;
}

$respStatusCode = $rest->get_ResponseStatusCode();
print 'response status code = ' . $respStatusCode . "\n";
if ($respStatusCode != 200) {
    print 'Response Header:' . "\n";
    print $rest->responseHeader() . "\n";
    print 'Response Body:' . "\n";
    print $sbResponseBody->getAsString() . "\n";
    exit;
}

$jResp = new CkJsonObject();
$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

$i = 0;
$count_i = $jResp->SizeOfArray('Instances');
while ($i < $count_i) {
    $jResp->put_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');
    while ($j < $count_j) {
        $jResp->put_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;
    }

    $j = 0;
    $count_j = $jResp->SizeOfArray('Instances[i].LayerIds');
    while ($j < $count_j) {
        $jResp->put_J($j);
        $strVal = $jResp->stringOf('Instances[i].LayerIds[j]');
        $j = $j + 1;
    }

    $j = 0;
    $count_j = $jResp->SizeOfArray('Instances[i].SecurityGroupIds');
    while ($j < $count_j) {
        $jResp->put_J($j);
        $strVal = $jResp->stringOf('Instances[i].SecurityGroupIds[j]');
        $j = $j + 1;
    }

    $i = $i + 1;
}

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

?>