Search in sources :

Example 1 with DescribeSecurityGroupsResponse

use of software.amazon.awssdk.services.ec2.model.DescribeSecurityGroupsResponse 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 (software.amazon.awssdk.services.ec2.model.DescribeSecurityGroupsRequest)1 DescribeSecurityGroupsResponse (software.amazon.awssdk.services.ec2.model.DescribeSecurityGroupsResponse)1 Ec2Exception (software.amazon.awssdk.services.ec2.model.Ec2Exception)1 SecurityGroup (software.amazon.awssdk.services.ec2.model.SecurityGroup)1