//snippet-sourcedescription:[DescribeSecurityGroups.java demonstrates how to get information about all the EC2 security groups.]
//snippet-keyword:[SDK for Java 2.0]
//snippet-keyword:[Code Sample]
//snippet-service:[ec2]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[]
//snippet-sourceauthor:[soo-aws]
/*
 * Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. 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.
 */
package com.example.ec2;
// snippet-start:[ec2.java2.describe_security_groups.complete]
// snippet-start:[ec2.java2.describe_security_groups.import]
import software.amazon.awssdk.services.ec2.Ec2Client;
import software.amazon.awssdk.services.ec2.model.DescribeSecurityGroupsRequest;
import software.amazon.awssdk.services.ec2.model.DescribeSecurityGroupsResponse;
import software.amazon.awssdk.services.ec2.model.SecurityGroup;
 
// snippet-end:[ec2.java2.describe_security_groups.import]
/**
 * Describes all security groups
 */
public class DescribeSecurityGroups
{
    public static void main(String[] args)
    {
        final String USAGE =
            "To run this example, supply a group id\n" +
            "Ex: DescribeSecurityGroups <group-id>\n";

        if (args.length != 1) {
            System.out.println(USAGE);
            System.exit(1);
        }

        String group_id = args[0];
        // snippet-start:[ec2.java2.describe_security_groups.main]

        Ec2Client ec2 = Ec2Client.create();

        DescribeSecurityGroupsRequest request =
            DescribeSecurityGroupsRequest.builder()
                .groupIds(group_id).build();

        DescribeSecurityGroupsResponse response =
            ec2.describeSecurityGroups(request);

        // snippet-end:[ec2.java2.describe_security_groups.main]
        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());
        }
    }
}
 
// snippet-end:[ec2.java2.describe_security_groups.complete]

@@ -278,16 +278,26 @@
 cedate:%5B
+11/02/2020
 %5D%0D%0A//sni
@@ -320,14 +320,15 @@
 r:%5Bs
-oo-aws
+cmacdon
 %5D%0D%0A/
@@ -354,10 +354,10 @@
 0-20
-19
+20
  Ama
@@ -1360,17 +1360,78 @@
 Group;%0D%0A
- 
+import software.amazon.awssdk.services.ec2.model.Ec2Exception;
 %0D%0A// sni
@@ -1484,16 +1484,18 @@
 mport%5D%0D%0A
+%0D%0A
 /**%0D%0A * 
@@ -1569,11 +1569,12 @@
 oups
+ %7B
 %0D%0A
-%7B
 %0D%0A  
@@ -1613,21 +1613,16 @@
 %5B%5D args)
-%0D%0A   
  %7B%0D%0A    
@@ -1643,24 +1643,28 @@
 ng USAGE =%0D%0A
+    
             
@@ -1705,24 +1705,36 @@
 up id%5Cn%22 +%0D%0A
+            
             
@@ -1914,18 +1914,17 @@
 ng group
-_i
+I
 d = args
@@ -2042,24 +2042,45 @@
 reate();%0D%0A%0D%0A
+        try %7B%0D%0A%0D%0A    
         Desc
@@ -2120,32 +2120,36 @@
  =%0D%0A            
+  
+  
 DescribeSecurity
@@ -2189,16 +2189,24 @@
         
+        
 .groupId
@@ -2216,10 +2216,9 @@
 roup
-_i
+I
 d).b
@@ -2224,24 +2224,28 @@
 build();%0D%0A%0D%0A
+    
         Desc
@@ -2295,16 +2295,20 @@
         
+    
 ec2.desc
@@ -2339,24 +2339,26 @@
 st);%0D%0A%0D%0A
+%0D%0A
         
 // snipp
@@ -2341,32 +2341,36 @@
 );%0D%0A%0D%0A%0D%0A        
+    
 // snippet-end:%5B
@@ -2419,16 +2419,21 @@
         
+  
+   
 for(Secu
@@ -2484,32 +2484,36 @@
  %7B%0D%0A            
+   
+ 
 System.out.print
@@ -2516,16 +2516,20 @@
 rintf(%0D%0A
+    
         
@@ -2591,16 +2591,28 @@
         
+      
+      
 %22vpc id 
@@ -2615,24 +2615,36 @@
  id %25s %22 +%0D%0A
+            
             
@@ -2670,16 +2670,20 @@
 n %25s%22,%0D%0A
+    
         
@@ -2720,24 +2720,28 @@
             
+    
 group.vpcId(
@@ -2740,24 +2740,28 @@
 p.vpcId(),%0D%0A
+    
             
@@ -2783,24 +2783,107 @@
 iption());%0D%0A
+            %7D%0D%0A        %7D catch (Ec2Exception e) %7B%0D%0A            e.getStackTrace();%0D%0A
         %7D%0D%0A 
@@ -2891,17 +2891,16 @@
   %7D%0D%0A%7D%0D%0A
- 
 %0D%0A// sni

Update DescribeSecurityGroups.java