简体   繁体   中英

How I can get the EC2 Instance Name using C#

Dears, I wrote a code to List Instance Proparties and Display using C#

AmazonEC2Client amazonEC2Client = new AmazonEC2Client("id", "password", Amazon.RegionEndpoint.USEast1))           
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest();
DescribeInstancesResponse describeInstancesResponse = amazonEC2Client.DescribeInstances(describeInstancesRequest);
List<Reservation> result = describeInstancesResponse.Reservations;

then I Can get Values of EC2 Attributes using this code:

               foreach (var reservation in result)
                {
                    foreach (var instance in reservation.Instances)
                    {

                        instance.InstanceId;
                    }
                }

I need to get the Name Proparty Advise Please Thanks in Advance

Just like you have retrieved InstanceId, all the information which you can receive about an instance is listed in this API doc.

Name is basically a Tag, so look into instance.Tags

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM