Skip to content

Commit c915322

Browse files
tomerdyim-leefabianfett
authored
API Refactoring (#273)
motivation: define stable API in preperation 1.0 release changes: * require swift 5.7, remove redundant backwards compatibility code * make LambdaHandler, EventLoopLambdaHandler, and ByteBufferLambdaHandler disjointed protocols to reduce API surface area * create coding wrappers for LambdaHandler and EventLoopLambdaHandler to provide bridge to ByteBufferLambdaHandler * reuse output ByteBuffer to reduce allocations * add new SimpleLambdaHandler with no-op initializer for simple lambda use cases * update callsites and tests * update examples Co-authored-by: Yim Lee <[email protected]> Co-authored-by: Fabian Fett <[email protected]>
1 parent 98a23b6 commit c915322

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+798
-580
lines changed

Examples/Benchmark/BenchmarkHandler.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ import NIOCore
2222

2323
@main
2424
struct BenchmarkHandler: EventLoopLambdaHandler {
25-
typealias Event = String
26-
typealias Output = String
27-
2825
static func makeHandler(context: LambdaInitializationContext) -> EventLoopFuture<Self> {
2926
context.eventLoop.makeSucceededFuture(BenchmarkHandler())
3027
}

Examples/Benchmark/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.5
1+
// swift-tools-version:5.7
22

33
import PackageDescription
44

Examples/Deployment/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.5
1+
// swift-tools-version:5.7
22

33
import PackageDescription
44

Examples/Deployment/Sources/Benchmark/BenchmarkHandler.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
import AWSLambdaRuntimeCore
16-
import NIO
16+
import NIOCore
1717

1818
// If you would like to benchmark Swift's Lambda Runtime,
1919
// use this example which is more performant.
@@ -22,9 +22,6 @@ import NIO
2222

2323
@main
2424
struct BenchmarkHandler: EventLoopLambdaHandler {
25-
typealias Event = String
26-
typealias Output = String
27-
2825
static func makeHandler(context: LambdaInitializationContext) -> EventLoopFuture<Self> {
2926
context.eventLoop.makeSucceededFuture(BenchmarkHandler())
3027
}

Examples/Deployment/Sources/HelloWorld/HelloWorldHandler.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,7 @@ import AWSLambdaRuntime
1616

1717
// introductory example, the obligatory "hello, world!"
1818
@main
19-
struct HelloWorldHandler: LambdaHandler {
20-
typealias Event = String
21-
typealias Output = String
22-
23-
init(context: LambdaInitializationContext) async throws {
24-
// setup your resources that you want to reuse here.
25-
}
26-
19+
struct HelloWorldHandler: SimpleLambdaHandler {
2720
func handle(_ event: String, context: LambdaContext) async throws -> String {
2821
"hello, world"
2922
}

Examples/Echo/Lambda.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,7 @@ import AWSLambdaRuntime
1717
// in this example we are receiving and responding with strings
1818

1919
@main
20-
struct MyLambda: LambdaHandler {
21-
typealias Event = String
22-
typealias Output = String
23-
24-
init(context: LambdaInitializationContext) async throws {
25-
// setup your resources that you want to reuse for every invocation here.
26-
}
27-
20+
struct MyLambda: SimpleLambdaHandler {
2821
func handle(_ input: String, context: LambdaContext) async throws -> String {
2922
// as an example, respond with the input's reversed
3023
String(input.reversed())

Examples/Echo/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.5
1+
// swift-tools-version:5.7
22

33
import PackageDescription
44

Examples/ErrorHandling/Lambda.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ import AWSLambdaRuntime
1717
// MARK: - Run Lambda
1818

1919
@main
20-
struct MyLambda: LambdaHandler {
21-
typealias Event = Request
22-
typealias Output = Response
23-
24-
init(context: LambdaInitializationContext) async throws {}
25-
20+
struct MyLambda: SimpleLambdaHandler {
2621
func handle(_ request: Request, context: LambdaContext) async throws -> Response {
2722
// switch over the error type "requested" by the request, and trigger such error accordingly
2823
switch request.error {

Examples/ErrorHandling/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.5
1+
// swift-tools-version:5.7
22

33
import PackageDescription
44

Examples/Foundation/Lambda.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ import Logging
2525

2626
@main
2727
struct MyLambda: LambdaHandler {
28-
typealias Event = Request
29-
typealias Output = [Exchange]
30-
3128
let calculator: ExchangeRatesCalculator
3229

3330
init(context: LambdaInitializationContext) async throws {

0 commit comments

Comments
 (0)