4

我如何使用 AWS-java-sdk 知道我的实例在 EC2 上运行或停止

   DescribeInstancesRequest dis =new DescribeInstancesRequest();   
   dis.setInstanceIds(instancesList);
   System.out.println(ec2.describeInstances(dis));

我尝试了这个,但它没有按照我的要求给我输出

例如,任何一项帮助正在 EC2 上运行或停止?

4

1 回答 1

5
DescribeInstancesRequest dis = new DescribeInstancesRequest();   
dis.setInstanceIds(instancesList);
DescribeInstancesResult disresult = ec2.describeInstances(dis);
List<Reservation> list = disresult.getReservations();

System.out.println("-------------- status of instances -------------");
for (Reservation res : list) {
    List <Instance> instancelist = res.getInstances();

    for (Instance instance : instancelist) {
        System.out.println("Instance Status : " + instance.getState().getName());
        List <Tag> t1 = instance.getTags();
        for (Tag teg : t1) {
            System.out.println("Instance Name : "+ teg.getValue());
        }
    }   
    System.out.println("------------------------------------------------");
}
于 2011-09-26T10:31:12.763 回答