开发者

How to check EC2instance is running or stop in AWS using java?

how do i know my instance is running or stop on EC2 using AWS-java开发者_运维知识库-sdk

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

i try with this but its not give me output as i requires

any one help for instance is running or stop on EC2 ?


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("------------------------------------------------");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜