6
6
// client used by an Amazon Web Services (AWS) service client.
7
7
8
8
import ArgumentParser
9
- import AWSClientRuntime
9
+ // snippet-start:[swift.http-config.imports]
10
10
import ClientRuntime
11
11
import AWSS3
12
- import Foundation
13
12
import SmithyHTTPAPI
14
13
import AwsCommonRuntimeKit
14
+ // snippet-end:[swift.http-config.imports]
15
15
16
16
struct ExampleCommand : ParsableCommand {
17
17
@Option ( help: " Name of the Amazon Region to use " )
@@ -28,14 +28,10 @@ struct ExampleCommand: ParsableCommand {
28
28
29
29
/// Called by ``main()`` to run the bulk of the example.
30
30
func runAsync( ) async throws {
31
- //await SDKLoggingSystem().initialize(logLevel: .trace)
32
- //SDKDefaultIO.setLogLevel(level: .trace)
33
- // snippet-start:[swift.http-config.configure]
31
+ // snippet-start:[swift.http-config.headers]
34
32
let config = try await S3Client . S3ClientConfiguration (
35
33
region: region,
36
34
httpClientConfiguration: HttpClientConfiguration (
37
- connectTimeout: 2 ,
38
- socketTimeout: 5 ,
39
35
defaultHeaders: Headers (
40
36
[
41
37
" X-My-Custom-Header " : " CustomHeaderValue " ,
@@ -45,28 +41,30 @@ struct ExampleCommand: ParsableCommand {
45
41
)
46
42
)
47
43
let s3Client = S3Client ( config: config)
48
- // snippet-end:[swift.http-config.configure ]
44
+ // snippet-end:[swift.http-config.headers ]
49
45
50
- print ( " *** Getting list of buckets *** " )
51
- let output : ListBucketsOutput = try await s3Client. listBuckets ( input: ListBucketsInput ( ) )
46
+ print ( " *** Getting list of buckets... " )
47
+ _ = try await s3Client. listBuckets ( input: ListBucketsInput ( ) )
48
+ print ( " *** Success! \n " )
52
49
53
- print ( " *** Getting bucket list with very short timeout *** " )
50
+ print ( " *** Getting bucket list with custom timeouts... " )
54
51
55
52
// snippet-start: [swift.http-config.timeouts]
56
53
do {
57
54
let config = try await S3Client . S3ClientConfiguration (
58
55
region: region,
59
56
httpClientConfiguration: HttpClientConfiguration (
60
- connectTimeout: 0.001 ,
61
- socketTimeout: 0.005
57
+ connectTimeout: 2 ,
58
+ socketTimeout: 5
62
59
)
63
60
)
64
61
let s3Client = S3Client ( config: config)
65
- let output : ListBucketsOutput = try await s3Client. listBuckets ( input: ListBucketsInput ( ) )
62
+ _ = try await s3Client. listBuckets ( input: ListBucketsInput ( ) )
63
+ print ( " *** Success! " )
66
64
} catch CommonRunTimeError . crtError( let crtError) {
67
65
print ( " *** An error occurred accessing the bucket list: \( crtError. message) " )
68
66
} catch {
69
- print ( " *** Unexpected error requesting bucket list. " )
67
+ print ( " *** Unexpected error occurred requesting the bucket list. " )
70
68
}
71
69
// snippet-end: [swift.http-config.timeouts]
72
70
0 commit comments