Skip to content

Commit 17ed17b

Browse files
committed
separate protocol for simpler lambda (no init)
1 parent 2ed058b commit 17ed17b

File tree

18 files changed

+81
-149
lines changed

18 files changed

+81
-149
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/Deployment/Sources/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/Deployment/Sources/HelloWorld/HelloWorldHandler.swift

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

1717
// introductory example, the obligatory "hello, world!"
1818
@main
19-
struct HelloWorldHandler: LambdaHandler {
19+
struct HelloWorldHandler: SimpleLambdaHandler {
2020
func handle(_ event: String, context: LambdaContext) async throws -> String {
2121
"hello, world"
2222
}

Examples/Echo/Lambda.swift

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

1919
@main
20-
struct MyLambda: LambdaHandler {
20+
struct MyLambda: SimpleLambdaHandler {
2121
func handle(_ input: String, context: LambdaContext) async throws -> String {
2222
// as an example, respond with the input's reversed
2323
String(input.reversed())

Examples/ErrorHandling/Lambda.swift

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

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

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 {

Examples/JSON/Lambda.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ struct Response: Codable {
2626
// codables to model your request and response objects
2727

2828
@main
29-
struct MyLambda: LambdaHandler {
30-
typealias Event = Request
31-
typealias Output = Response
32-
29+
struct MyLambda: SimpleLambdaHandler {
3330
func handle(_ event: Request, context: LambdaContext) async throws -> Response {
3431
// as an example, respond with the input event's reversed body
3532
Response(body: String(event.body.reversed()))

Examples/LocalDebugging/MyLambda/Lambda.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ import Shared
1919
// a local server simulator which will allow local debugging
2020

2121
@main
22-
struct MyLambda: LambdaHandler {
23-
typealias Event = Request
24-
typealias Output = Response
25-
22+
struct MyLambda: SimpleLambdaHandler {
2623
func handle(_ request: Request, context: LambdaContext) async throws -> Response {
2724
// TODO: something useful
2825
Response(message: "Hello, \(request.name)!")

Examples/Testing/Sources/Lambda.swift

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

1919
@main
20-
struct MyLambda: LambdaHandler {
20+
struct MyLambda: SimpleLambdaHandler {
2121
func handle(_ event: String, context: LambdaContext) async throws -> String {
2222
// as an example, respond with the event's reversed body
2323
String(event.reversed())

Sources/AWSLambdaRuntimeCore/Lambda+String.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import NIOCore
1919
extension LambdaHandler where Event == String {
2020
/// Implementation of a `ByteBuffer` to `String` decoding.
2121
@inlinable
22-
public func decode(buffer: ByteBuffer) throws -> String {
22+
public func decode(buffer: ByteBuffer) throws -> Event {
2323
guard let value = buffer.getString(at: buffer.readerIndex, length: buffer.readableBytes) else {
2424
throw CodecError.invalidString
2525
}
@@ -31,7 +31,7 @@ extension LambdaHandler where Event == String {
3131
extension LambdaHandler where Output == String {
3232
/// Implementation of `String` to `ByteBuffer` encoding.
3333
@inlinable
34-
public func encode(value: String, into buffer: inout ByteBuffer) throws {
34+
public func encode(value: Output, into buffer: inout ByteBuffer) throws {
3535
buffer.writeString(value)
3636
}
3737
}
@@ -41,7 +41,7 @@ extension LambdaHandler where Output == String {
4141
extension EventLoopLambdaHandler where Event == String {
4242
/// Implementation of `String` to `ByteBuffer` encoding.
4343
@inlinable
44-
public func decode(buffer: ByteBuffer) throws -> String {
44+
public func decode(buffer: ByteBuffer) throws -> Event {
4545
guard let value = buffer.getString(at: buffer.readerIndex, length: buffer.readableBytes) else {
4646
throw CodecError.invalidString
4747
}
@@ -52,7 +52,7 @@ extension EventLoopLambdaHandler where Event == String {
5252
extension EventLoopLambdaHandler where Output == String {
5353
/// Implementation of a `ByteBuffer` to `String` decoding.
5454
@inlinable
55-
public func encode(value: String, into buffer: inout ByteBuffer) throws {
55+
public func encode(value: Output, into buffer: inout ByteBuffer) throws {
5656
buffer.writeString(value)
5757
}
5858
}

0 commit comments

Comments
 (0)