Skip to content

Commit bca8701

Browse files
shepazonbrmur
authored andcommitted
More progress
1 parent 94b552f commit bca8701

File tree

1 file changed

+65
-2
lines changed

1 file changed

+65
-2
lines changed

swift/example_code/glue/scenario/Sources/entry.swift

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import ArgumentParser
3636
import AWSS3
3737
import Foundation
38+
import Smithy
3839

3940
// snippet-start:[swift.glue.import]
4041
import AWSClientRuntime
@@ -146,8 +147,11 @@ struct ExampleCommand: ParsableCommand {
146147

147148
/// Called by ``main()`` to run the bulk of the example.
148149
func runAsync() async throws {
149-
let config = try await GlueClient.GlueClientConfiguration(region: awsRegion)
150-
let glueClient = GlueClient(config: config)
150+
let glueConfig = try await GlueClient.GlueClientConfiguration(region: awsRegion)
151+
let glueClient = GlueClient(config: glueConfig)
152+
153+
let s3Config = try await S3Client.S3ClientConfiguration(region: awsRegion)
154+
let s3Client = S3Client(config: s3Config)
151155

152156
print("Welcome to the AWS SDK for Swift basic scenario for AWS Glue!")
153157

@@ -173,6 +177,65 @@ struct ExampleCommand: ParsableCommand {
173177
// 0. Upload the Python script to the target bucket so it's available
174178
// for use by the Amazon Glue service.
175179
//=====================================================================
180+
181+
do {
182+
print("Uploading the Python script: \(script) as key \(scriptName)")
183+
print("Destination bucket: \(bucket)")
184+
185+
let fileData = try Data(contentsOf: URL(fileURLWithPath: script))
186+
let dataStream = ByteStream.data(fileData)
187+
_ = try await s3Client.putObject(
188+
input: PutObjectInput(
189+
body: dataStream,
190+
bucket: bucket,
191+
key: scriptName
192+
)
193+
)
194+
} catch {
195+
print("*** An unexpected error occurred uploading the script to the Amazon S3 bucket \"\(bucket)\".")
196+
return
197+
}
198+
199+
//=====================================================================
200+
// 1. Create the database and crawler. This also creates the database
201+
// named `databaseName`.
202+
//=====================================================================
203+
204+
print("Creating crawler \"\(crawlerName)\"...")
205+
206+
let s3Target = GlueClientTypes.S3Target(path: s3url)
207+
let targetList = GlueClientTypes.CrawlerTargets(s3Targets: [s3Target])
208+
209+
do {
210+
_ = try await glueClient.createCrawler(
211+
input: CreateCrawlerInput(
212+
databaseName: databaseName,
213+
description: "Created by the AWS SDK for Swift Scenario Example for AWS Glue.",
214+
name: crawlerName,
215+
role: role,
216+
schedule: cron,
217+
tablePrefix: tablePrefix,
218+
targets: targetList
219+
)
220+
)
221+
} catch _ as AlreadyExistsException {
222+
print("*** A crawler named \"\(crawlerName)\" already exists.")
223+
return
224+
} catch _ as OperationTimeoutException {
225+
print("*** The attempt to create the AWS Glue crawler timed out.")
226+
return
227+
} catch {
228+
print("*** An unexpected error occurred creating the AWS Glue crawler: \(error.localizedDescription)")
229+
return
230+
}
231+
232+
//=====================================================================
233+
// 2. Start the crawler, then call `getCaller()` in a loop to wait for
234+
// it to be ready.
235+
//=====================================================================
236+
237+
print("Starting the crawler and waiting until it's ready...")
238+
176239
}
177240
}
178241

0 commit comments

Comments
 (0)