AWS Security ChangesHomeSearch

AWS code-library documentation change

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

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

Summary

Added Swift SDK code example demonstrating EC2 security group listing functionality

Security assessment

The change adds documentation about retrieving security group information, which is a security feature. However, there's no evidence of addressing a specific security vulnerability - this is standard API usage documentation.

Diff

diff --git a/code-library/latest/ug/ec2_example_ec2_Hello_section.md b/code-library/latest/ug/ec2_example_ec2_Hello_section.md
index 1581b2c59..b6e8e21b2 100644
--- a//code-library/latest/ug/ec2_example_ec2_Hello_section.md
+++ b//code-library/latest/ug/ec2_example_ec2_Hello_section.md
@@ -559,0 +560,164 @@ 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). 
+
+The `Package.swift` file.
+    
+    
+    // swift-tools-version: 5.9
+    //
+    // The swift-tools-version declares the minimum version of Swift required to
+    // build this package.
+    
+    import PackageDescription
+    
+    let package = Package(
+        name: "hello-ec2",
+        // Let Xcode know the minimum Apple platforms supported.
+        platforms: [
+            .macOS(.v13),
+            .iOS(.v15)
+        ],
+        dependencies: [
+            // Dependencies declare other packages that this package depends on.
+            .package(
+                url: "https://github.com/awslabs/aws-sdk-swift",
+                from: "1.0.0"),
+            .package(
+                url: "https://github.com/apple/swift-argument-parser.git",
+                branch: "main"
+            )
+        ],
+        targets: [
+            // Targets are the basic building blocks of a package, defining a module or a test suite.
+            // Targets can depend on other targets in this package and products
+            // from dependencies.
+            .executableTarget(
+                name: "hello-ec2",
+                dependencies: [
+                    .product(name: "AWSEC2", package: "aws-sdk-swift"),
+                    .product(name: "ArgumentParser", package: "swift-argument-parser")
+                ],
+                path: "Sources")
+    
+        ]
+    )
+    
+    
+
+The `entry.swift` file.
+    
+    
+    // An example that shows how to use the AWS SDK for Swift to perform a simple
+    // operation using Amazon Elastic Compute Cloud (EC2).
+    //
+    
+    import ArgumentParser
+    import Foundation
+    
+    import AWSEC2
+    
+    struct ExampleCommand: ParsableCommand {
+        @Option(help: "The AWS Region to run AWS API calls in.")
+        var awsRegion = "us-east-1"
+    
+        @Option(
+            help: ArgumentHelp("The level of logging for the Swift SDK to perform."),
+            completion: .list([
+                "critical",
+                "debug",
+                "error",
+                "info",
+                "notice",
+                "trace",
+                "warning"
+            ])
+        )
+        var logLevel: String = "error"
+    
+        static var configuration = CommandConfiguration(
+            commandName: "hello-ec2",
+            abstract: """
+            Demonstrates a simple operation using Amazon EC2.
+            """,
+            discussion: """
+            An example showing how to make a call to Amazon EC2 using the AWS SDK for Swift.
+            """
+        )
+    
+        /// 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
+        }
+    
+        /// Called by ``main()`` to run the bulk of the example.
+        func runAsync() async throws {
+            let ec2Config = try await EC2Client.EC2ClientConfiguration(region: awsRegion)
+            let ec2Client = EC2Client(config: ec2Config)
+    
+            let groupNames = await getSecurityGroupNames(ec2Client: ec2Client)
+    
+            print("Found \(groupNames.count) security group(s):")
+    
+            for group in groupNames {
+                print("    \(group)")
+            }
+        }
+    }
+    
+    /// The program's asynchronous entry point.
+    @main
+    struct Main {
+        static func main() async {
+            let args = Array(CommandLine.arguments.dropFirst())
+    
+            do {
+                let command = try ExampleCommand.parse(args)
+                try await command.runAsync()
+            } catch {
+                ExampleCommand.exit(withError: error)
+            }
+        }    
+    }
+    
+    
+
+  * 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_. 
+
+
+
+