AWS gets instance name in Java

I am developing a Java application and I can list the instances:

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

How to get instance name?

+4
source share
1 answer

You can access tags associated with an 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()
                ));
            }
        }
    }
}
+5
source

Source: https://habr.com/ru/post/1667469/


All Articles