private void setup()
{
log.info("Checking if security group \"" + groupName + "\" is set up.");
DescribeSecurityGroupsResult describeResult = ec2Client.describeSecurityGroups(new DescribeSecurityGroupsRequest().
withFilters(new Filter().withName("group-name").withValues(groupName),
new Filter().withName("ip-permission.cidr").withValues(cidr),
new Filter().withName("ip-permission.from-port").withValues(new Integer(port).toString()),
new Filter().withName("ip-permission.to-port").withValues(new Integer(port).toString()),
new Filter().withName("ip-permission.protocol").withValues("tcp")));
if (!describeResult.getSecurityGroups().isEmpty())
{
groupId = describeResult.getSecurityGroups().get(0).getGroupId();
}
else
{
log.info("Security group \"" + groupName + "\" is not set up. Checking if it exists.");
describeResult = ec2Client.describeSecurityGroups(new DescribeSecurityGroupsRequest().
withFilters(new Filter().withName("group-name").withValues(groupName)));
if (!describeResult.getSecurityGroups().isEmpty())
{
log.info("Security group \"" + groupName + "\" exists.");
groupId = describeResult.getSecurityGroups().get(0).getGroupId();
}