Skip to content

Commit 1030816

Browse files
committed
use trailing closure syntax + reuse S3 client
1 parent 83446a8 commit 1030816

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Examples/AWSSDK/Sources/main.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@
1414

1515
import AWSLambdaEvents
1616
import AWSLambdaRuntime
17-
import AWSS3
1817

19-
func handler(event: APIGatewayV2Request, context: LambdaContext) async throws -> APIGatewayV2Response {
18+
@preconcurrency import AWSS3
19+
let client = try await S3Client()
20+
21+
let runtime = LambdaRuntime.init { (event: APIGatewayV2Request, context: LambdaContext) async throws -> APIGatewayV2Response in
2022

2123
var response: APIGatewayV2Response
2224
do {
2325
// read the list of buckets
2426
context.logger.debug("Reading list of buckets")
25-
let client = try await S3Client()
2627
let output = try await client.listBuckets(input: ListBucketsInput())
2728
let bucketList = output.buckets?.compactMap { $0.name }
2829
response = APIGatewayV2Response(statusCode: .ok, body: bucketList?.joined(separator: "\n"))
@@ -33,5 +34,4 @@ func handler(event: APIGatewayV2Request, context: LambdaContext) async throws ->
3334
return response
3435
}
3536

36-
let runtime = LambdaRuntime.init(body: handler)
3737
try await runtime.run()

0 commit comments

Comments
 (0)