Chilkat Online Tools

DescribeInstances Go Example

AWS OpsWorks

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

    rest := chilkat.NewRest()
    var success bool

    authAws := chilkat.NewAuthAws()
    authAws.SetAccessKey("AWS_ACCESS_KEY")
    authAws.SetSecretKey("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.SetRegion("us-west-2")
    authAws.SetServiceName("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 {
        fmt.Println("ConnectFailReason: ", rest.ConnectFailReason())
        fmt.Println(rest.LastErrorText())
        rest.DisposeRest()
        authAws.DisposeAuthAws()
        return
    }

    // 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 := chilkat.NewJsonObject()
    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 := chilkat.NewStringBuilder()
    json.EmitSb(sbRequestBody)
    sbResponseBody := chilkat.NewStringBuilder()
    success = rest.FullRequestSb("POST","/",sbRequestBody,sbResponseBody)
    if success != true {
        fmt.Println(rest.LastErrorText())
        rest.DisposeRest()
        authAws.DisposeAuthAws()
        json.DisposeJsonObject()
        sbRequestBody.DisposeStringBuilder()
        sbResponseBody.DisposeStringBuilder()
        return
    }

    respStatusCode := rest.ResponseStatusCode()
    fmt.Println("response status code = ", respStatusCode)
    if respStatusCode != 200 {
        fmt.Println("Response Header:")
        fmt.Println(rest.ResponseHeader())
        fmt.Println("Response Body:")
        fmt.Println(*sbResponseBody.GetAsString())
        rest.DisposeRest()
        authAws.DisposeAuthAws()
        json.DisposeJsonObject()
        sbRequestBody.DisposeStringBuilder()
        sbResponseBody.DisposeStringBuilder()
        return
    }

    jResp := chilkat.NewJsonObject()
    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

AgentVersion_DECLARATION
AmiId_DECLARATION
Architecture_DECLARATION
Arn_DECLARATION
AutoScalingType_DECLARATION
AvailabilityZone_DECLARATION
CreatedAt_DECLARATION
    var EbsOptimized int
Ec2InstanceId_DECLARATION
EcsClusterArn_DECLARATION
EcsContainerInstanceArn_DECLARATION
ElasticIp_DECLARATION
Hostname_DECLARATION
InfrastructureClass_DECLARATION
    var InstallUpdatesOnBoot int
InstanceId_DECLARATION
InstanceProfileArn_DECLARATION
InstanceType_DECLARATION
LastServiceErrorId_DECLARATION
Os_DECLARATION
Platform_DECLARATION
PrivateDns_DECLARATION
PrivateIp_DECLARATION
PublicDns_DECLARATION
PublicIp_DECLARATION
RegisteredBy_DECLARATION
ReportedAgentVersion_DECLARATION
Family_DECLARATION
Name_DECLARATION
Version_DECLARATION
RootDeviceType_DECLARATION
RootDeviceVolumeId_DECLARATION
SshHostDsaKeyFingerprint_DECLARATION
SshHostRsaKeyFingerprint_DECLARATION
SshKeyName_DECLARATION
StackId_DECLARATION
Status_DECLARATION
SubnetId_DECLARATION
Tenancy_DECLARATION
VirtualizationType_DECLARATION
    var j int
    var count_j int
DeviceName_DECLARATION
    var DeleteOnTermination int
    var Iops int
SnapshotId_DECLARATION
    var VolumeSize int
VolumeType_DECLARATION
NoDevice_DECLARATION
VirtualName_DECLARATION
strVal_DECLARATION

    i := 0
    count_i := jResp.SizeOfArray("Instances")
    for i < count_i {
        jResp.SetI(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")
        for j < count_j {
            jResp.SetJ(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")
        for j < count_j {
            jResp.SetJ(j)
            strVal = *jResp.StringOf("Instances[i].LayerIds[j]")
            j = j + 1
        }

        j = 0
        count_j = jResp.SizeOfArray("Instances[i].SecurityGroupIds")
        for j < count_j {
            jResp.SetJ(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"
    //     }
    //   ]
    // }

    rest.DisposeRest()
    authAws.DisposeAuthAws()
    json.DisposeJsonObject()
    sbRequestBody.DisposeStringBuilder()
    sbResponseBody.DisposeStringBuilder()
    jResp.DisposeJsonObject()