AWS Security ChangesHomeSearch

AWS code-library documentation change

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

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

Summary

Added Swift SDK code example for AWS Glue crawler and job scenario including package configuration, command structure, resource management, and API references

Security assessment

The changes add implementation examples for AWS Glue operations but contain no security vulnerability fixes or security feature documentation. While the code demonstrates IAM role usage and resource cleanup, these are standard cloud practices rather than security-specific updates.

Diff

diff --git a/code-library/latest/ug/glue_example_glue_Scenario_GetStartedCrawlersJobs_section.md b/code-library/latest/ug/glue_example_glue_Scenario_GetStartedCrawlersJobs_section.md
index 79358655f..d5156dee1 100644
--- a//code-library/latest/ug/glue_example_glue_Scenario_GetStartedCrawlersJobs_section.md
+++ b//code-library/latest/ug/glue_example_glue_Scenario_GetStartedCrawlersJobs_section.md
@@ -4870,0 +4871,911 @@ Delete all resources created by the demo.
+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/glue#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: "glue-scenario",
+        // 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: "glue-scenario",
+                dependencies: [
+                    .product(name: "AWSGlue", package: "aws-sdk-swift"),
+                    .product(name: "AWSS3", package: "aws-sdk-swift"),
+                    .product(name: "ArgumentParser", package: "swift-argument-parser")
+                ],
+                path: "Sources")
+    
+        ]
+    )
+    
+    
+
+The Swift code file, `entry.swift`.
+    
+    
+    // An example that shows how to use the AWS SDK for Swift to demonstrate
+    // creating and using crawlers and jobs using AWS Glue.
+    //
+    // 0. Upload the Python job script to Amazon S3 so it can be used when
+    //    calling `startJobRun()` later.
+    // 1. Create a crawler, pass it the IAM role and the URL of the public Amazon
+    //    S3 bucket that contains the source data:
+    //    s3://crawler-public-us-east-1/flight/2016/csv.
+    // 2. Start the crawler. This takes time, so after starting it, use a loop
+    //    that calls `getCrawler()` until the state is "READY".
+    // 3. Get the database created by the crawler, and the tables in the
+    //    database. Display them to the user.
+    // 4. Create a job. Pass it the IAM role and the URL to a Python ETL script
+    //    previously uploaded to the user's S3 bucket.
+    // 5. Start a job run, passing the following custom arguments. These are
+    //    expected by the ETL script, so must exactly match.
+    //    * `--input_database: <name of the database created by the crawler>`
+    //    * `--input_table: <name of the table created by the crawler>`
+    //    * `--output_bucket_url: <URL to the scaffold bucket created for the
+    //      user>`
+    // 6. Loop and get the job run until it returns one of the following states:
+    //    "SUCCEEDED", "STOPPED", "FAILED", or "TIMEOUT".
+    // 7. Output data is stored in a group of files in the user's S3 bucket.
+    //    Either direct the user to their location or download a file and display
+    //    the results inline.
+    // 8. List the jobs for the user's account.
+    // 9. Get job run details for a job run.
+    // 10. Delete the demo job.
+    // 11. Delete the database and tables created by the example.
+    // 12. Delete the crawler created by the example.
+    
+    import ArgumentParser
+    import AWSS3
+    import Foundation
+    import Smithy
+    
+    import AWSClientRuntime
+    import AWSGlue
+    
+    struct ExampleCommand: ParsableCommand {
+        @Option(help: "The AWS IAM role to use for AWS Glue calls.")
+        var role: String
+    
+        @Option(help: "The Amazon S3 bucket to use for this example.")
+        var bucket: String
+    
+        @Option(help: "The Amazon S3 URL of the data to crawl.")
+        var s3url: String = "s3://crawler-public-us-east-1/flight/2016/csv"
+    
+        @Option(help: "The Python script to run as a job with AWS Glue.")
+        var script: String = "./flight_etl_job_script.py"
+    
+        @Option(help: "The AWS Region to run AWS API calls in.")
+        var awsRegion = "us-east-1"
+    
+        @Option(help: "A prefix string to use when naming tables.")
+        var tablePrefix = "swift-glue-basics-table"
+    
+        @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: "glue-scenario",
+            abstract: """
+            Demonstrates various features of AWS Glue.
+            """,
+            discussion: """
+            An example showing how to use AWS Glue to create, run, and monitor
+            crawlers and jobs.
+            """
+        )
+    
+        /// Generate and return a unique file name that begins with the specified
+        /// string.
+        ///
+        /// - Parameters:
+        ///   - prefix: Text to use at the beginning of the returned name.
+        ///
+        /// - Returns: A string containing a unique filename that begins with the
+        ///   specified `prefix`.
+        ///
+        /// The returned name uses a random number between 1 million and 1 billion to
+        /// provide reasonable certainty of uniqueness for the purposes of this
+        /// example.
+        func tempName(prefix: String) -> String {
+            return "\(prefix)-\(Int.random(in: 1000000..<1000000000))"
+        }
+    
+        /// Upload a file to an Amazon S3 bucket.
+        /// 
+        /// - Parameters:
+        ///   - s3Client: The S3 client to use when uploading the file.
+        ///   - path: The local path of the source file to upload.
+        ///   - toBucket: The name of the S3 bucket into which to upload the file.
+        ///   - key: The key (name) to give the file in the S3 bucket.
+        ///
+        /// - Returns: `true` if the file is uploaded successfully, otherwise `false`.
+        func uploadFile(s3Client: S3Client, path: String, toBucket: String, key: String) async -> Bool {
+            do {
+                let fileData: Data = try Data(contentsOf: URL(fileURLWithPath: path))
+                let dataStream = ByteStream.data(fileData)
+                _ = try await s3Client.putObject(
+                    input: PutObjectInput(
+                        body: dataStream,
+                        bucket: toBucket,
+                        key: key
+                    )
+                )
+            } catch {
+                print("*** An unexpected error occurred uploading the script to the Amazon S3 bucket \"\(bucket)\".")
+                return false
+            }
+    
+            return true
+        }
+    
+        /// Create a new AWS Glue crawler.
+        /// 
+        /// - Parameters:
+        ///   - glueClient: An AWS Glue client to use for the crawler.
+        ///   - crawlerName: A name for the new crawler.
+        ///   - iamRole: The name of an Amazon IAM role for the crawler to use.
+        ///   - s3Path: The path of an Amazon S3 folder to use as a target location.
+        ///   - cronSchedule: A `cron` schedule indicating when to run the crawler.
+        ///   - databaseName: The name of an AWS Glue database to operate on.
+        ///