Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  * Copyright 2013-2015 Amazon Technologies, Inc.
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at:
 * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
 * OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and
 * limitations under the License.
public class SecurityGroupUtils {
    private static final String INVALID_GROUP_NOT_FOUND = "InvalidGroup.NotFound";

Provides a quick answer to whether a security group exists.

ec2 the EC2 client to use for making service requests
securityGroupName the name of the security group being queried
com.amazonaws.AmazonClientException If any internal errors are encountered inside the client while attempting to make the request or handle the response. For example if a network connection is not available.
com.amazonaws.AmazonServiceException If an error response is returned by AmazonEC2 indicating either a problem with the data in the request, or a server side issue.
    public static boolean doesSecurityGroupExist(AmazonEC2 ec2,
            String securityGroupNamethrows AmazonClientException,
            AmazonServiceException {
        DescribeSecurityGroupsRequest securityGroupsRequest =
                new DescribeSecurityGroupsRequest()
        try {
            return true;
        } catch (AmazonServiceException ase) {
            if (.equals(ase.getErrorCode())) {
                return false;
            throw ase;
New to GrepCode? Check out our FAQ X