Search in sources :

Example 11 with DescribeSecurityGroupsRequest

use of software.amazon.awssdk.services.ec2.model.DescribeSecurityGroupsRequest in project Synapse-Stack-Builder by Sage-Bionetworks.

the class EC2SecuritySetup method describeResources.

public void describeResources() {
    DescribeSecurityGroupsRequest req = new DescribeSecurityGroupsRequest();
    req.setGroupNames(Arrays.asList(config.getElasticSecurityGroupName()));
    DescribeSecurityGroupsResult res = ec2Client.describeSecurityGroups(req);
    if ((res.getSecurityGroups() != null) && res.getSecurityGroups().size() == 1) {
        SecurityGroup grp = res.getSecurityGroups().get(0);
        resources.setElasticBeanstalkEC2SecurityGroup(grp);
        String kpName = config.getStackKeyPairName();
        KeyPairInfo inf = describeKeyPair();
        if (inf != null) {
            resources.setStackKeyPair(inf);
        }
    } else {
        throw new IllegalStateException("Did not find one and ony one EC2 secruity group with the name: " + req.getGroupNames());
    }
}
Also used : DescribeSecurityGroupsRequest(com.amazonaws.services.ec2.model.DescribeSecurityGroupsRequest) KeyPairInfo(com.amazonaws.services.ec2.model.KeyPairInfo) DescribeSecurityGroupsResult(com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult) SecurityGroup(com.amazonaws.services.ec2.model.SecurityGroup)

Example 12 with DescribeSecurityGroupsRequest

use of software.amazon.awssdk.services.ec2.model.DescribeSecurityGroupsRequest in project photon-model by vmware.

the class AWSSecurityGroupClient method getSecurityGroupById.

public SecurityGroup getSecurityGroupById(String groupId) {
    SecurityGroup cellGroup = null;
    DescribeSecurityGroupsRequest req = new DescribeSecurityGroupsRequest().withGroupIds(groupId);
    DescribeSecurityGroupsResult cellGroups = this.client.describeSecurityGroups(req);
    if (cellGroups != null) {
        cellGroup = cellGroups.getSecurityGroups().get(0);
    }
    return cellGroup;
}
Also used : DescribeSecurityGroupsRequest(com.amazonaws.services.ec2.model.DescribeSecurityGroupsRequest) SecurityGroup(com.amazonaws.services.ec2.model.SecurityGroup) DescribeSecurityGroupsResult(com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult)

Example 13 with DescribeSecurityGroupsRequest

use of software.amazon.awssdk.services.ec2.model.DescribeSecurityGroupsRequest in project photon-model by vmware.

the class TestAWSSetupUtils method getSecurityGroupsIdUsingEC2Client.

public static SecurityGroup getSecurityGroupsIdUsingEC2Client(AmazonEC2AsyncClient client, String awsGroupId) {
    if (awsGroupId == null) {
        return null;
    }
    DescribeSecurityGroupsRequest describeSGsRequest = new DescribeSecurityGroupsRequest().withFilters(new Filter(AWSConstants.AWS_GROUP_ID_FILTER, Collections.singletonList(awsGroupId)));
    DescribeSecurityGroupsResult describeSGResult = client.describeSecurityGroups(describeSGsRequest);
    if (describeSGResult.getSecurityGroups().size() > 0) {
        return describeSGResult.getSecurityGroups().get(0);
    } else {
        return null;
    }
}
Also used : DescribeSecurityGroupsRequest(com.amazonaws.services.ec2.model.DescribeSecurityGroupsRequest) AWSUtils.getAWSNonTerminatedInstancesFilter(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.getAWSNonTerminatedInstancesFilter) Filter(com.amazonaws.services.ec2.model.Filter) DescribeSecurityGroupsResult(com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult)

Example 14 with DescribeSecurityGroupsRequest

use of software.amazon.awssdk.services.ec2.model.DescribeSecurityGroupsRequest in project aws-doc-sdk-examples by awsdocs.

the class DescribeSecurityGroups method describeEC2SecurityGroups.

// snippet-start:[ec2.java2.describe_security_groups.main]
public static void describeEC2SecurityGroups(Ec2Client ec2, String groupId) {
    try {
        DescribeSecurityGroupsRequest request = DescribeSecurityGroupsRequest.builder().groupIds(groupId).build();
        DescribeSecurityGroupsResponse response = ec2.describeSecurityGroups(request);
        for (SecurityGroup group : response.securityGroups()) {
            System.out.printf("Found Security Group with id %s, " + "vpc id %s " + "and description %s", group.groupId(), group.vpcId(), group.description());
        }
    } catch (Ec2Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : DescribeSecurityGroupsRequest(software.amazon.awssdk.services.ec2.model.DescribeSecurityGroupsRequest) DescribeSecurityGroupsResponse(software.amazon.awssdk.services.ec2.model.DescribeSecurityGroupsResponse) Ec2Exception(software.amazon.awssdk.services.ec2.model.Ec2Exception) SecurityGroup(software.amazon.awssdk.services.ec2.model.SecurityGroup)

Aggregations

DescribeSecurityGroupsRequest (com.amazonaws.services.ec2.model.DescribeSecurityGroupsRequest)13 DescribeSecurityGroupsResult (com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult)12 SecurityGroup (com.amazonaws.services.ec2.model.SecurityGroup)9 Filter (com.amazonaws.services.ec2.model.Filter)8 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)4 DeleteSecurityGroupRequest (com.amazonaws.services.ec2.model.DeleteSecurityGroupRequest)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 AsyncHandler (com.amazonaws.handlers.AsyncHandler)1 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)1 AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)1 AmazonEC2Exception (com.amazonaws.services.ec2.model.AmazonEC2Exception)1 AttachInternetGatewayRequest (com.amazonaws.services.ec2.model.AttachInternetGatewayRequest)1 AttachNetworkInterfaceRequest (com.amazonaws.services.ec2.model.AttachNetworkInterfaceRequest)1 AttachNetworkInterfaceResult (com.amazonaws.services.ec2.model.AttachNetworkInterfaceResult)1 BlockDeviceMapping (com.amazonaws.services.ec2.model.BlockDeviceMapping)1 CreateNetworkInterfaceRequest (com.amazonaws.services.ec2.model.CreateNetworkInterfaceRequest)1 CreateNetworkInterfaceResult (com.amazonaws.services.ec2.model.CreateNetworkInterfaceResult)1 CreateSecurityGroupRequest (com.amazonaws.services.ec2.model.CreateSecurityGroupRequest)1