@@ -0,0 +1,2408 @@
+/*%0A * Copyright 2013-2014 Amazon Technologies, Inc.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at:%0A *%0A *    http://aws.amazon.com/apache2.0%0A *%0A * This file is distributed on an %22AS IS%22 BASIS, WITHOUT WARRANTIES%0A * OR CONDITIONS OF ANY KIND, either express or implied. See the%0A * License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage com.amazonaws.services.ec2.util;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Aimport com.amazonaws.AmazonClientException;%0Aimport com.amazonaws.AmazonServiceException;%0Aimport com.amazonaws.services.ec2.AmazonEC2;%0Aimport com.amazonaws.services.ec2.model.DescribeSecurityGroupsRequest;%0A%0Apublic class SecurityGroups %7B%0A    /**%0A     * %3Cp%3E%0A     * doesSecurityGroupExist provides a quick answer to whether a security group exists. %0A     * %3C/p%3E%0A     * @param ec2 Amazon EC2 client%0A     * @param securityGroupName Security group name.%0A     * @return%0A     * @throws AmazonClientException%0A     *             If any internal errors are encountered inside the client while%0A     *             attempting to make the request or handle the response.  For example%0A     *             if a network connection is not available.%0A     * @throws AmazonServiceException%0A     *             If an error response is returned by AmazonEC2 indicating%0A     *             either a problem with the data in the request, or a server side issue.%0A     */%0A    public static boolean doesSecurityGroupExist(AmazonEC2 ec2, String securityGroupName)%0A    %09throws AmazonClientException, AmazonServiceException %7B%0A    %09List%3CString%3E securityGroupNames = new ArrayList%3CString%3E();%0A    %09securityGroupNames.add(securityGroupName);%0A    %09%0A    %09DescribeSecurityGroupsRequest securityGroupsRequest = new DescribeSecurityGroupsRequest()%0A    %09%09%09%09%09%09%09%09%09%09%09%09%09%09%09.withGroupNames(securityGroupNames);%0A    %09%0A    %09try %7B%0A    %09%09ec2.describeSecurityGroups(securityGroupsRequest);%0A    %09%09return true;%0A    %09%7D catch (AmazonServiceException ase) %7B%0A    %09%09if (ase.getErrorCode().equalsIgnoreCase(%22InvalidAccessKeyId%22) %7C%7C%0A    %09%09%09ase.getErrorCode().equalsIgnoreCase(%22SignatureDoesNotMatch%22)) %7B%0A    %09%09%09throw ase;%0A    %09%09%7D%0A    %09%09%0A    %09%09switch (ase.getStatusCode()) %7B%0A    %09%09case 400:%0A    %09%09%09return false;%0A    %09%09default:%0A    %09%09%09throw ase;%0A    %09%09%7D%0A    %09%7D%0A    %7D%0A%7D%0A

Add doesSecurityGroupsExist in SecurityGroups util class