AWS Security ChangesHomeSearch

AWS code-library documentation change

Service: code-library · 2025-08-01 · Documentation low

File: code-library/latest/ug/ec2_example_ec2_DescribeSecurityGroups_section.md

Summary

Added Swift SDK examples for DescribeSecurityGroups API with pagination and direct query implementations

Security assessment

Provides documentation for security group enumeration features but doesn't fix vulnerabilities. While security group configuration is security-critical, the change only adds API usage examples without addressing specific security weaknesses.

Diff

diff --git a/code-library/latest/ug/ec2_example_ec2_DescribeSecurityGroups_section.md b/code-library/latest/ug/ec2_example_ec2_DescribeSecurityGroups_section.md
index f048de684..dd7f05404 100644
--- a//code-library/latest/ug/ec2_example_ec2_DescribeSecurityGroups_section.md
+++ b//code-library/latest/ug/ec2_example_ec2_DescribeSecurityGroups_section.md
@@ -847,0 +848,85 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+Swift
+    
+
+**SDK for Swift**
+    
+
+###### Note
+
+There's more on GitHub. Find the complete example and learn how to set up and run in the [AWS Code Examples Repository](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/swift/example_code/ec2#code-examples). 
+
+Using pagination with `describeSecurityGroupsPaginated()`.
+    
+    
+    import AWSEC2
+    
+        /// Return an array of strings giving the names of every security group
+        /// the user is a member of.
+        ///
+        /// - Parameter ec2Client: The `EC2Client` to use when calling
+        ///   `describeSecurityGroupsPaginated()`.
+        ///
+        /// - Returns: An array of strings giving the names of every security
+        ///   group the user is a member of.
+        func getSecurityGroupNames(ec2Client: EC2Client) async -> [String] {
+            let pages = ec2Client.describeSecurityGroupsPaginated(
+                input: DescribeSecurityGroupsInput()
+            )
+    
+            var groupNames: [String] = []
+    
+            do {
+                for try await page in pages {
+                    guard let groups = page.securityGroups else {
+                        print("*** Error: No groups returned.")
+                        continue
+                    }
+    
+                    for group in groups {
+                        groupNames.append(group.groupName ?? "<unknown>")
+                    }
+                }
+            } catch {
+                print("*** Error: \(error.localizedDescription)")
+            }
+    
+            return groupNames
+        }
+    
+    
+
+Without pagination.
+    
+    
+    import AWSEC2
+    
+        func describeSecurityGroups(groupId: String) async -> Bool {
+            do {
+                let output = try await ec2Client.describeSecurityGroups(
+                    input: DescribeSecurityGroupsInput(
+                        groupIds: [groupId]
+                    )
+                )
+    
+                guard let securityGroups = output.securityGroups else {
+                    print("No security groups found.")
+                    return true
+                }
+    
+                for group in securityGroups {
+                    print("Group \(group.groupId ?? "<unknown>") found with VPC \(group.vpcId ?? "<unknown>")")
+                }
+                return true
+            } catch {
+                print("*** Error getting security group details: \(error.localizedDescription)")
+                return false
+            }
+        }
+    
+    
+
+  * For API details, see [DescribeSecurityGroups](https://sdk.amazonaws.com/swift/api/awsec2/latest/documentation/awsec2/ec2client/describesecuritygroups\(input:\)) in _AWS SDK for Swift API reference_. 
+
+
+
+