Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS get instance name in Java

I am developing an application in Java and I am able to list the instances:

for (Reservation reservation : result.getReservations()) {
    for (Instance instance : reservation.getInstances()) {
        System.out.println("Instance id:"
                + instance.getInstanceId());
    }
}

How do I get the instance name?

like image 692
Viswanath Alikonda Avatar asked Mar 11 '23 02:03

Viswanath Alikonda


1 Answers

You can access tags associated with the instance:

for (Reservation reservation : result.getReservations()) {
    for (Instance instance : reservation.getInstances()) {
        System.out.println("Instance id:" + instance.getInstanceId());

        if (instance.getTags() != null) {
            for (Tag tag : instance.getTags()) {
                System.out.println(String.format(
                    "%s: %s", 
                    tag.getKey(), 
                    tag.getValue()
                ));
            }
        }
    }
}
like image 67
Dave Maple Avatar answered Mar 16 '23 05:03

Dave Maple