Jelaskan instans Amazon EC2 menggunakan SDK AWS - Amazon Elastic Compute Cloud

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Jelaskan instans Amazon EC2 menggunakan SDK AWS

Contoh kode berikut ini menunjukkan cara menjelaskan instans Amazon EC2.

Contoh tindakan adalah kutipan kode dari program yang lebih besar dan harus dijalankan dalam konteks. Anda dapat melihat tindakan ini dalam konteks dalam contoh kode berikut:

.NET
AWS SDK for .NET
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode AWS.

/// <summary> /// Get information about existing EC2 images. /// </summary> /// <returns>Async task.</returns> public async Task DescribeInstances() { // List all EC2 instances. await GetInstanceDescriptions(); string tagName = "IncludeInList"; string tagValue = "Yes"; await GetInstanceDescriptionsFiltered(tagName, tagValue); } /// <summary> /// Get information for all existing Amazon EC2 instances. /// </summary> /// <returns>Async task.</returns> public async Task GetInstanceDescriptions() { Console.WriteLine("Showing all instances:"); var paginator = _amazonEC2.Paginators.DescribeInstances(new DescribeInstancesRequest()); await foreach (var response in paginator.Responses) { foreach (var reservation in response.Reservations) { foreach (var instance in reservation.Instances) { Console.Write($"Instance ID: {instance.InstanceId}"); Console.WriteLine($"\tCurrent State: {instance.State.Name}"); } } } } /// <summary> /// Get information about EC2 instances filtered by a tag name and value. /// </summary> /// <param name="tagName">The name of the tag to filter on.</param> /// <param name="tagValue">The value of the tag to look for.</param> /// <returns>Async task.</returns> public async Task GetInstanceDescriptionsFiltered(string tagName, string tagValue) { // This tag filters the results of the instance list. var filters = new List<Filter> { new Filter { Name = $"tag:{tagName}", Values = new List<string> { tagValue, }, }, }; var request = new DescribeInstancesRequest { Filters = filters, }; Console.WriteLine("\nShowing instances with tag: \"IncludeInList\" set to \"Yes\"."); var paginator = _amazonEC2.Paginators.DescribeInstances(request); await foreach (var response in paginator.Responses) { foreach (var reservation in response.Reservations) { foreach (var instance in reservation.Instances) { Console.Write($"Instance ID: {instance.InstanceId} "); Console.WriteLine($"\tCurrent State: {instance.State.Name}"); } } } }
C++
SDK for C++
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode AWS.

Aws::EC2::EC2Client ec2Client(clientConfiguration); Aws::EC2::Model::DescribeInstancesRequest request; bool header = false; bool done = false; while (!done) { auto outcome = ec2Client.DescribeInstances(request); if (outcome.IsSuccess()) { if (!header) { std::cout << std::left << std::setw(48) << "Name" << std::setw(20) << "ID" << std::setw(25) << "Ami" << std::setw(15) << "Type" << std::setw(15) << "State" << std::setw(15) << "Monitoring" << std::endl; header = true; } const std::vector<Aws::EC2::Model::Reservation> &reservations = outcome.GetResult().GetReservations(); for (const auto &reservation: reservations) { const std::vector<Aws::EC2::Model::Instance> &instances = reservation.GetInstances(); for (const auto &instance: instances) { Aws::String instanceStateString = Aws::EC2::Model::InstanceStateNameMapper::GetNameForInstanceStateName( instance.GetState().GetName()); Aws::String typeString = Aws::EC2::Model::InstanceTypeMapper::GetNameForInstanceType( instance.GetInstanceType()); Aws::String monitorString = Aws::EC2::Model::MonitoringStateMapper::GetNameForMonitoringState( instance.GetMonitoring().GetState()); Aws::String name = "Unknown"; const std::vector<Aws::EC2::Model::Tag> &tags = instance.GetTags(); auto nameIter = std::find_if(tags.cbegin(), tags.cend(), [](const Aws::EC2::Model::Tag &tag) { return tag.GetKey() == "Name"; }); if (nameIter != tags.cend()) { name = nameIter->GetValue(); } std::cout << std::setw(48) << name << std::setw(20) << instance.GetInstanceId() << std::setw(25) << instance.GetImageId() << std::setw(15) << typeString << std::setw(15) << instanceStateString << std::setw(15) << monitorString << std::endl; } } if (!outcome.GetResult().GetNextToken().empty()) { request.SetNextToken(outcome.GetResult().GetNextToken()); } else { done = true; } } else { std::cerr << "Failed to describe EC2 instances:" << outcome.GetError().GetMessage() << std::endl; return false; } }
CLI
AWS CLI

Contoh 1: Untuk menjelaskan instans

Contoh describe-instances berikut menjelaskan instans tertentu.

aws ec2 describe-instances \ --instance-ids i-1234567890abcdef0

Output:

{ "Reservations": [ { "Groups": [], "Instances": [ { "AmiLaunchIndex": 0, "ImageId": "ami-0abcdef1234567890", "InstanceId": "i-1234567890abcdef0", "InstanceType": "t3.nano", "KeyName": "my-key-pair", "LaunchTime": "2022-11-15T10:48:59+00:00", "Monitoring": { "State": "disabled" }, "Placement": { "AvailabilityZone": "us-east-2a", "GroupName": "", "Tenancy": "default" }, "PrivateDnsName": "ip-10-0-0-157.us-east-2.compute.internal", "PrivateIpAddress": "10-0-0-157", "ProductCodes": [], "PublicDnsName": "ec2-34-253-223-13.us-east-2.compute.amazonaws.com", "PublicIpAddress": "34.253.223.13", "State": { "Code": 16, "Name": "running" }, "StateTransitionReason": "", "SubnetId": "subnet-04a636d18e83cfacb", "VpcId": "vpc-1234567890abcdef0", "Architecture": "x86_64", "BlockDeviceMappings": [ { "DeviceName": "/dev/xvda", "Ebs": { "AttachTime": "2022-11-15T10:49:00+00:00", "DeleteOnTermination": true, "Status": "attached", "VolumeId": "vol-02e6ccdca7de29cf2" } } ], "ClientToken": "1234abcd-1234-abcd-1234-d46a8903e9bc", "EbsOptimized": true, "EnaSupport": true, "Hypervisor": "xen", "IamInstanceProfile": { "Arn": "arn:aws:iam::111111111111:instance-profile/AmazonSSMRoleForInstancesQuickSetup", "Id": "111111111111111111111" }, "NetworkInterfaces": [ { "Association": { "IpOwnerId": "amazon", "PublicDnsName": "ec2-34-253-223-13.us-east-2.compute.amazonaws.com", "PublicIp": "34.253.223.13" }, "Attachment": { "AttachTime": "2022-11-15T10:48:59+00:00", "AttachmentId": "eni-attach-1234567890abcdefg", "DeleteOnTermination": true, "DeviceIndex": 0, "Status": "attached", "NetworkCardIndex": 0 }, "Description": "", "Groups": [ { "GroupName": "launch-wizard-146", "GroupId": "sg-1234567890abcdefg" } ], "Ipv6Addresses": [], "MacAddress": "00:11:22:33:44:55", "NetworkInterfaceId": "eni-1234567890abcdefg", "OwnerId": "104024344472", "PrivateDnsName": "ip-10-0-0-157.us-east-2.compute.internal", "PrivateIpAddress": "10-0-0-157", "PrivateIpAddresses": [ { "Association": { "IpOwnerId": "amazon", "PublicDnsName": "ec2-34-253-223-13.us-east-2.compute.amazonaws.com", "PublicIp": "34.253.223.13" }, "Primary": true, "PrivateDnsName": "ip-10-0-0-157.us-east-2.compute.internal", "PrivateIpAddress": "10-0-0-157" } ], "SourceDestCheck": true, "Status": "in-use", "SubnetId": "subnet-1234567890abcdefg", "VpcId": "vpc-1234567890abcdefg", "InterfaceType": "interface" } ], "RootDeviceName": "/dev/xvda", "RootDeviceType": "ebs", "SecurityGroups": [ { "GroupName": "launch-wizard-146", "GroupId": "sg-1234567890abcdefg" } ], "SourceDestCheck": true, "Tags": [ { "Key": "Name", "Value": "my-instance" } ], "VirtualizationType": "hvm", "CpuOptions": { "CoreCount": 1, "ThreadsPerCore": 2 }, "CapacityReservationSpecification": { "CapacityReservationPreference": "open" }, "HibernationOptions": { "Configured": false }, "MetadataOptions": { "State": "applied", "HttpTokens": "optional", "HttpPutResponseHopLimit": 1, "HttpEndpoint": "enabled", "HttpProtocolIpv6": "disabled", "InstanceMetadataTags": "enabled" }, "EnclaveOptions": { "Enabled": false }, "PlatformDetails": "Linux/UNIX", "UsageOperation": "RunInstances", "UsageOperationUpdateTime": "2022-11-15T10:48:59+00:00", "PrivateDnsNameOptions": { "HostnameType": "ip-name", "EnableResourceNameDnsARecord": true, "EnableResourceNameDnsAAAARecord": false }, "MaintenanceOptions": { "AutoRecovery": "default" } } ], "OwnerId": "111111111111", "ReservationId": "r-1234567890abcdefg" } ] }

Contoh 2: Untuk memfilter instans dengan tipe tertentu

Contoh describe-instances berikut menggunakan filter guna mencakup hasil untuk instans dari tipe tertentu.

aws ec2 describe-instances \ --filters Name=instance-type,Values=m5.large

Untuk contoh output, lihat Contoh 1.

Untuk informasi selengkapnya, lihat Cantumkan dan filter menggunakan CLI di Panduan Pengguna Amazon EC2.

Contoh 3: Untuk memfilter instans dengan tipe dan Zona Ketersediaan tertentu

Contoh describe-instances berikut menggunakan banyak filter guna mencakup hasil untuk instans dengan tipe tertentu yang juga ada di Zona Ketersediaan tertentu.

aws ec2 describe-instances \ --filters Name=instance-type,Values=t2.micro,t3.micro Name=availability-zone,Values=us-east-2c

Untuk contoh output, lihat Contoh 1.

Contoh 4: Untuk memfilter instans dengan tipe dan Zona Ketersediaan tertentu menggunakan file JSON

Contoh describe-instances berikut menggunakan file input JSON untuk melakukan pemfilteran yang sama seperti contoh sebelumnya. Ketika filter menjadi lebih rumit, filter tersebut dapat lebih mudah ditentukan dalam file JSON.

aws ec2 describe-instances \ --filters file://filters.json

Isi dari filters.json:

[ { "Name": "instance-type", "Values": ["t2.micro", "t3.micro"] }, { "Name": "availability-zone", "Values": ["us-east-2c"] } ]

Untuk contoh output, lihat Contoh 1.

Contoh 5: Untuk memfilter instans dengan tanda Pemilik tertentu

Contoh describe-instances berikut menggunakan filter tanda guna mencakup hasil untuk instans yang memiliki tanda dengan kunci tanda tertentu (Pemilik), terlepas dari nilai tandanya.

aws ec2 describe-instances \ --filters "Name=tag-key,Values=Owner"

Untuk contoh output, lihat Contoh 1.

Contoh 6: Untuk memfilter instans dengan nilai tanda my-team tertentu

Contoh describe-instances berikut menggunakan filter tanda guna mencakup hasil untuk instans yang memiliki tanda dengan kunci tanda tertentu (my-team), terlepas dari nilai tandanya.

aws ec2 describe-instances \ --filters "Name=tag-value,Values=my-team"

Untuk contoh output, lihat Contoh 1.

Contoh 7: Untuk memfilter instans dengan tanda Pemilik dan nilai my-team tertentu

Contoh describe-instances berikut menggunakan filter tanda guna mencakup hasil untuk instans yang memiliki tanda tertentu (Pemilik=my-team).

aws ec2 describe-instances \ --filters "Name=tag:Owner,Values=my-team"

Untuk contoh output, lihat Contoh 1.

Contoh 8: Guna hanya menampilkan ID instans dan subnet untuk semua instans

Contoh describe-instances berikut menggunakan parameter --query untuk hanya menampilkan ID instans dan subnet untuk semua instans, dalam format JSON.

Linux dan macOS:

aws ec2 describe-instances \ --query 'Reservations[*].Instances[*].{Instance:InstanceId,Subnet:SubnetId}' \ --output json

Windows:

aws ec2 describe-instances ^ --query "Reservations[*].Instances[*].{Instance:InstanceId,Subnet:SubnetId}" ^ --output json

Output:

[ { "Instance": "i-057750d42936e468a", "Subnet": "subnet-069beee9b12030077" }, { "Instance": "i-001efd250faaa6ffa", "Subnet": "subnet-0b715c6b7db68927a" }, { "Instance": "i-027552a73f021f3bd", "Subnet": "subnet-0250c25a1f4e15235" } ... ]

Contoh 9: Untuk memfilter instans dari tipe tertentu dan hanya menampilkan ID instansnya

Contoh describe-instances berikut menggunakan filter guna mencakup hasil untuk instans dari tipe tertentu dan parameter --query agar hanya menampilkan ID instans.

aws ec2 describe-instances \ --filters "Name=instance-type,Values=t2.micro" \ --query "Reservations[*].Instances[*].[InstanceId]" \ --output text

Output:

i-031c0dc19de2fb70c i-00d8bff789a736b75 i-0b715c6b7db68927a i-0626d4edd54f1286d i-00b8ae04f9f99908e i-0fc71c25d2374130c

Contoh 10: Untuk memfilter instans dari tipe tertentu dan hanya menampilkan ID instans, Zona Ketersediaan, dan nilai tanda tertentu

Contoh describe-instances berikut menampilkan ID instans, Zona Ketersediaan, dan nilai dari tanda Name untuk instans yang memiliki tanda dengan nama tag-key, dalam format tabel.

Linux dan macOS:

aws ec2 describe-instances \ --filters Name=tag-key,Values=Name \ --query 'Reservations[*].Instances[*].{Instance:InstanceId,AZ:Placement.AvailabilityZone,Name:Tags[?Key==`Name`]|[0].Value}' \ --output table

Windows:

aws ec2 describe-instances ^ --filters Name=tag-key,Values=Name ^ --query "Reservations[*].Instances[*].{Instance:InstanceId,AZ:Placement.AvailabilityZone,Name:Tags[?Key=='Name']|[0].Value}" ^ --output table

Output:

------------------------------------------------------------- | DescribeInstances | +--------------+-----------------------+--------------------+ | AZ | Instance | Name | +--------------+-----------------------+--------------------+ | us-east-2b | i-057750d42936e468a | my-prod-server | | us-east-2a | i-001efd250faaa6ffa | test-server-1 | | us-east-2a | i-027552a73f021f3bd | test-server-2 | +--------------+-----------------------+--------------------+

Contoh 11: Untuk menjelaskan instans dalam grup penempatan partisi

Contoh describe-instances berikut menjelaskan instans tertentu. Output-nya mencakup informasi penempatan untuk instans, yang berisi nama grup penempatan dan nomor partisi untuk instans tersebut.

aws ec2 describe-instances \ --instance-ids i-0123a456700123456 \ --query "Reservations[*].Instances[*].Placement"

Output:

[ [ { "AvailabilityZone": "us-east-1c", "GroupName": "HDFS-Group-A", "PartitionNumber": 3, "Tenancy": "default" } ] ]

Untuk informasi selengkapnya, lihat Menjelaskan instans dalam grup penempatan di Panduan Pengguna Amazon EC2.

Contoh 12: Untuk memfilter ke instans dengan grup penempatan dan nomor partisi tertentu

Contoh describe-instances berikut memfilter hasil menjadi hanya instans dengan grup penempatan dan nomor partisi tertentu.

aws ec2 describe-instances \ --filters "Name=placement-group-name,Values=HDFS-Group-A" "Name=placement-partition-number,Values=7"

Berikut ini hanya menunjukkan informasi yang relevan dari output.

"Instances": [ { "InstanceId": "i-0123a456700123456", "InstanceType": "r4.large", "Placement": { "AvailabilityZone": "us-east-1c", "GroupName": "HDFS-Group-A", "PartitionNumber": 7, "Tenancy": "default" } }, { "InstanceId": "i-9876a543210987654", "InstanceType": "r4.large", "Placement": { "AvailabilityZone": "us-east-1c", "GroupName": "HDFS-Group-A", "PartitionNumber": 7, "Tenancy": "default" } ],

Untuk informasi selengkapnya, lihat Menjelaskan instans dalam grup penempatan di Panduan Pengguna Amazon EC2.

Contoh 13: Untuk memfilter ke instans yang dikonfigurasikan guna memungkinkan akses ke tanda dari metadata instans

Contoh describe-instances berikut memfilter hasil menjadi hanya instans yang dikonfigurasikan guna memungkinkan akses ke tanda instans dari metadata instans.

aws ec2 describe-instances \ --filters "Name=metadata-options.instance-metadata-tags,Values=enabled" \ --query "Reservations[*].Instances[*].InstanceId" \ --output text

Berikut menunjukkan output yang diharapkan.

i-1234567890abcdefg i-abcdefg1234567890 i-11111111aaaaaaaaa i-aaaaaaaa111111111

Untuk informasi selengkapnya, lihat Bekerja dengan tanda instans dalam metadata instans di Panduan Pengguna Amazon EC2.

Java
SDK for Java 2.x
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode AWS.

public static String describeEC2Instances(Ec2Client ec2, String newInstanceId) { try { String pubAddress = ""; boolean isRunning = false; DescribeInstancesRequest request = DescribeInstancesRequest.builder() .instanceIds(newInstanceId) .build(); while (!isRunning) { DescribeInstancesResponse response = ec2.describeInstances(request); String state = response.reservations().get(0).instances().get(0).state().name().name(); if (state.compareTo("RUNNING") == 0) { System.out.println("Image id is " + response.reservations().get(0).instances().get(0).imageId()); System.out.println( "Instance type is " + response.reservations().get(0).instances().get(0).instanceType()); System.out.println( "Instance state is " + response.reservations().get(0).instances().get(0).state().name()); pubAddress = response.reservations().get(0).instances().get(0).publicIpAddress(); System.out.println("Instance address is " + pubAddress); isRunning = true; } } return pubAddress; } catch (SsmException e) { System.err.println(e.getMessage()); System.exit(1); } return ""; }
JavaScript
SDK untuk JavaScript (v3)
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode AWS.

import { DescribeInstancesCommand } from "@aws-sdk/client-ec2"; import { client } from "../libs/client.js"; // List all of your EC2 instances running with x86_64 architecture that were // launched this month. export const main = async () => { const d = new Date(); const year = d.getFullYear(); const month = `0${d.getMonth() + 1}`.slice(-2); const launchTimePattern = `${year}-${month}-*`; const command = new DescribeInstancesCommand({ Filters: [ { Name: "architecture", Values: ["x86_64"] }, { Name: "instance-state-name", Values: ["running"] }, { Name: "launch-time", Values: [launchTimePattern], }, ], }); try { const { Reservations } = await client.send(command); const instanceList = Reservations.reduce((prev, current) => { return prev.concat(current.Instances); }, []); console.log(instanceList); } catch (err) { console.error(err); } };
Kotlin
SDK for Kotlin
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode AWS.

suspend fun describeEC2Instances() { val request = DescribeInstancesRequest { maxResults = 6 } Ec2Client { region = "us-west-2" }.use { ec2 -> val response = ec2.describeInstances(request) response.reservations?.forEach { reservation -> reservation.instances?.forEach { instance -> println("Instance Id is ${instance.instanceId}") println("Image id is ${instance.imageId}") println("Instance type is ${instance.instanceType}") println("Instance state name is ${instance.state?.name}") println("monitoring information is ${instance.monitoring?.state}") } } } }
Python
SDK for Python (Boto3)
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode AWS.

class InstanceWrapper: """Encapsulates Amazon Elastic Compute Cloud (Amazon EC2) instance actions.""" def __init__(self, ec2_resource, instance=None): """ :param ec2_resource: A Boto3 Amazon EC2 resource. This high-level resource is used to create additional high-level objects that wrap low-level Amazon EC2 service actions. :param instance: A Boto3 Instance object. This is a high-level object that wraps instance actions. """ self.ec2_resource = ec2_resource self.instance = instance @classmethod def from_resource(cls): ec2_resource = boto3.resource("ec2") return cls(ec2_resource) def display(self, indent=1): """ Displays information about an instance. :param indent: The visual indent to apply to the output. """ if self.instance is None: logger.info("No instance to display.") return try: self.instance.load() ind = "\t" * indent print(f"{ind}ID: {self.instance.id}") print(f"{ind}Image ID: {self.instance.image_id}") print(f"{ind}Instance type: {self.instance.instance_type}") print(f"{ind}Key name: {self.instance.key_name}") print(f"{ind}VPC ID: {self.instance.vpc_id}") print(f"{ind}Public IP: {self.instance.public_ip_address}") print(f"{ind}State: {self.instance.state['Name']}") except ClientError as err: logger.error( "Couldn't display your instance. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise
  • Untuk detail API, lihat DescribeInstancesdi AWSSDK for Python (Boto3) Referensi API.

Ruby
SDK for Ruby
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode AWS.

require "aws-sdk-ec2" # @param ec2_resource [Aws::EC2::Resource] An initialized EC2 resource object. # @example # list_instance_ids_states(Aws::EC2::Resource.new(region: 'us-west-2')) def list_instance_ids_states(ec2_resource) response = ec2_resource.instances if response.count.zero? puts "No instances found." else puts "Instances -- ID, state:" response.each do |instance| puts "#{instance.id}, #{instance.state.name}" end end rescue StandardError => e puts "Error getting information about instances: #{e.message}" end #Full example call: def run_me region = "" # Print usage information and then stop. if ARGV[0] == "--help" || ARGV[0] == "-h" puts "Usage: ruby ec2-ruby-example-get-all-instance-info.rb REGION" # Replace us-west-2 with the AWS Region you're using for Amazon EC2. puts "Example: ruby ec2-ruby-example-get-all-instance-info.rb us-west-2" exit 1 # If no values are specified at the command prompt, use these default values. # Replace us-west-2 with the AWS Region you're using for Amazon EC2. elsif ARGV.count.zero? region = "us-west-2" # Otherwise, use the values as specified at the command prompt. else region = ARGV[0] end ec2_resource = Aws::EC2::Resource.new(region: region) list_instance_ids_states(ec2_resource) end run_me if $PROGRAM_NAME == __FILE__
Rust
SDK for Rust
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode AWS.

async fn show_state(client: &Client, ids: Option<Vec<String>>) -> Result<(), Error> { let resp = client .describe_instances() .set_instance_ids(ids) .send() .await?; for reservation in resp.reservations() { for instance in reservation.instances() { println!("Instance ID: {}", instance.instance_id().unwrap()); println!( "State: {:?}", instance.state().unwrap().name().unwrap() ); println!(); } } Ok(()) }
SAP ABAP
SDK untuk SAP ABAP
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode AWS.

TRY. oo_result = lo_ec2->describeinstances( ) . " oo_result is returned for testing purposes. " " Retrieving details of EC2 instances. " DATA: lv_istance_id TYPE /aws1/ec2string, lv_status TYPE /aws1/ec2instancestatename, lv_instance_type TYPE /aws1/ec2instancetype, lv_image_id TYPE /aws1/ec2string. LOOP AT oo_result->get_reservations( ) INTO DATA(lo_reservation). LOOP AT lo_reservation->get_instances( ) INTO DATA(lo_instance). lv_istance_id = lo_instance->get_instanceid( ). lv_status = lo_instance->get_state( )->get_name( ). lv_instance_type = lo_instance->get_instancetype( ). lv_image_id = lo_instance->get_imageid( ). ENDLOOP. ENDLOOP. MESSAGE 'Retrieved information about EC2 instances.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.

Untuk melihat daftar lengkap panduan developer SDK AWS dan contoh-contoh kode, silakan lihat Menggunakan layanan ini dengan AWS SDK. Topik ini juga mencakup informasi tentang cara memulai dan detail tentang versi SDK sebelumnya.