*
* @param groupNames the names of the groups to find
* @return a list of matching groups
*/
public List<SecurityGroup> describeSecurityGroups(String... groupNames) {
AmazonEC2 ec2Client = ec2Client();
DescribeSecurityGroupsRequest request = new DescribeSecurityGroupsRequest();
if (groupNames == null || groupNames.length == 0) {
LOGGER.info(String.format("Getting all EC2 security groups in region %s.", region));
} else {
LOGGER.info(String.format("Getting EC2 security groups for %d names in region %s.", groupNames.length,
region));
request.withGroupNames(groupNames);
}
DescribeSecurityGroupsResult result;
try {
result = ec2Client.describeSecurityGroups(request);
} catch (AmazonServiceException e) {
if (e.getErrorCode().equals("InvalidGroup.NotFound")) {
LOGGER.info("Got InvalidGroup.NotFound error for security groups; returning empty list");
return Collections.emptyList();
}