Search in sources :

Example 1 with DescribeTagsRequest

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;
}
Also used : DescribeTagsRequest(com.amazonaws.services.ec2.model.DescribeTagsRequest) DescribeTagsResult(com.amazonaws.services.ec2.model.DescribeTagsResult) Filter(com.amazonaws.services.ec2.model.Filter)

Aggregations

DescribeTagsRequest (com.amazonaws.services.ec2.model.DescribeTagsRequest)1 DescribeTagsResult (com.amazonaws.services.ec2.model.DescribeTagsResult)1 Filter (com.amazonaws.services.ec2.model.Filter)1