use of com.amazonaws.services.ec2.model.DescribeTagsRequest in project chassis by Kixeye.
the class AwsUtils method getInstanceName.
/**
* Fetches and instance's name Tag or null if it does not have one
* @param instanceId
* @param amazonEC2
* @return
*/
public static String getInstanceName(String instanceId, AmazonEC2 amazonEC2) {
DescribeTagsResult result = amazonEC2.describeTags(new DescribeTagsRequest().withFilters(new Filter().withName("resource-id").withValues(instanceId), new Filter().withName("resource-type").withValues("instance"), new Filter().withName("key").withValues(TAG_KEY_NAME)));
if (result.getTags().isEmpty()) {
return null;
}
String name = result.getTags().get(0).getValue();
return name == null || name.trim().equals("") ? null : name;
}
Aggregations