作者:nana-Wang2602915845 | 来源:互联网 | 2023-09-13 18:32
我怎么知道我的实例正在使用AWS-java-sdk在EC2上运行或停止DescribeInstancesRequestdisnewDescribeInstancesRequest(
我怎么知道我的实例正在使用AWS-java-sdk在EC2上运行或停止
DescribeInstancesRequest dis =new DescribeInstancesRequest();
dis.setInstanceIds(instancesList);
System.out.println(ec2.describeInstances(dis));
我尝试这个,但它不给我输出,因为我需要
例如,任何一个帮助都在EC2上运行或停止?
解决方法:
DescribeInstancesRequest dis = new DescribeInstancesRequest();
dis.setInstanceIds(instancesList);
DescribeInstancesResult disresult = ec2.describeInstances(dis);
List list = disresult.getReservations();
System.out.println("-------------- status of instances -------------");
for (Reservation res : list) {
List instancelist = res.getInstances();
for (Instance instance : instancelist) {
System.out.println("Instance Status : " + instance.getState().getName());
List t1 = instance.getTags();
for (Tag teg : t1) {
System.out.println("Instance Name : "+ teg.getValue());
}
}
System.out.println("------------------------------------------------");
}