Skip to content

Commit 501bc6e

Browse files
committed
Drop event label from handle method in LambdaHandlers
1 parent dbd675d commit 501bc6e

File tree

15 files changed

+40
-40
lines changed

15 files changed

+40
-40
lines changed

Examples/LambdaFunctions/Sources/Benchmark/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct BenchmarkHandler: EventLoopLambdaHandler {
2525
typealias In = String
2626
typealias Out = String
2727

28-
func handle(event: String, context: Lambda.Context) -> EventLoopFuture<String> {
28+
func handle(_ event: String, context: Lambda.Context) -> EventLoopFuture<String> {
2929
context.eventLoop.makeSucceededFuture("hello, world!")
3030
}
3131
}

Examples/LambdaFunctions/Sources/CurrencyExchange/CurrencyExchangeHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct CurrencyExchangeHandler: LambdaHandler {
3535
self.calculator = ExchangeRatesCalculator()
3636
}
3737

38-
func handle(event: Request, context: Lambda.Context) async throws -> [Exchange] {
38+
func handle(_ event: Request, context: Lambda.Context) async throws -> [Exchange] {
3939
try await withCheckedThrowingContinuation { continuation in
4040
self.calculator.run(logger: context.logger) { result in
4141
switch result {

Examples/LambdaFunctions/Sources/ErrorHandling/ErrorsHappenHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct ErrorsHappenHandler: LambdaHandler {
2323

2424
init(context: Lambda.InitializationContext) async throws {}
2525

26-
func handle(event request: Request, context: Lambda.Context) async throws -> Response {
26+
func handle(_ request: Request, context: Lambda.Context) async throws -> Response {
2727
// switch over the error type "requested" by the request, and trigger such error accordingly
2828
switch request.error {
2929
// no error here!

Examples/LambdaFunctions/Sources/HelloWorld/HelloWorldHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct HelloWorldHandler: LambdaHandler {
2424
// setup your resources that you want to reuse here.
2525
}
2626

27-
func handle(event: String, context: Lambda.Context) async throws -> String {
27+
func handle(_ event: String, context: Lambda.Context) async throws -> String {
2828
"hello, world"
2929
}
3030
}

Examples/LocalDebugging/MyLambda/Sources/MyLambda/MyLambdaHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct MyLambdaHandler: LambdaHandler {
2626
// setup your resources that you want to reuse for every invocation here.
2727
}
2828

29-
func handle(event request: Request, context: Lambda.Context) async throws -> Response {
29+
func handle(_ request: Request, context: Lambda.Context) async throws -> Response {
3030
// TODO: something useful
3131
Response(message: "Hello, \(request.name)!")
3232
}

Sources/AWSLambdaRuntimeCore/LambdaHandler.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ public protocol LambdaHandler: EventLoopLambdaHandler {
3838
/// - context: Runtime `Context`.
3939
///
4040
/// - Returns: A Lambda result ot type `Out`.
41-
func handle(event: In, context: Lambda.Context) async throws -> Out
41+
func handle(_ event: In, context: Lambda.Context) async throws -> Out
4242
}
4343

4444
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
4545
extension LambdaHandler {
46-
public func handle(event: In, context: Lambda.Context) -> EventLoopFuture<Out> {
46+
public func handle(_ event: In, context: Lambda.Context) -> EventLoopFuture<Out> {
4747
let promise = context.eventLoop.makePromise(of: Out.self)
4848
promise.completeWithTask {
49-
try await self.handle(event: event, context: context)
49+
try await self.handle(event, context: context)
5050
}
5151
return promise.futureResult
5252
}
@@ -82,7 +82,7 @@ public protocol EventLoopLambdaHandler: ByteBufferLambdaHandler {
8282
///
8383
/// - Returns: An `EventLoopFuture` to report the result of the Lambda back to the runtime engine.
8484
/// The `EventLoopFuture` should be completed with either a response of type `Out` or an `Error`
85-
func handle(event: In, context: Lambda.Context) -> EventLoopFuture<Out>
85+
func handle(_ event: In, context: Lambda.Context) -> EventLoopFuture<Out>
8686

8787
/// Encode a response of type `Out` to `ByteBuffer`
8888
/// Concrete Lambda handlers implement this method to provide coding functionality.
@@ -106,15 +106,15 @@ public protocol EventLoopLambdaHandler: ByteBufferLambdaHandler {
106106
extension EventLoopLambdaHandler {
107107
/// Driver for `ByteBuffer` -> `In` decoding and `Out` -> `ByteBuffer` encoding
108108
@inlinable
109-
public func handle(event: ByteBuffer, context: Lambda.Context) -> EventLoopFuture<ByteBuffer?> {
109+
public func handle(_ event: ByteBuffer, context: Lambda.Context) -> EventLoopFuture<ByteBuffer?> {
110110
let input: In
111111
do {
112112
input = try self.decode(buffer: event)
113113
} catch {
114114
return context.eventLoop.makeFailedFuture(CodecError.requestDecoding(error))
115115
}
116116

117-
return self.handle(event: input, context: context).flatMapThrowing { output in
117+
return self.handle(input, context: context).flatMapThrowing { output in
118118
do {
119119
return try self.encode(allocator: context.allocator, value: output)
120120
} catch {
@@ -148,7 +148,7 @@ public protocol ByteBufferLambdaHandler {
148148
///
149149
/// - Returns: An `EventLoopFuture` to report the result of the Lambda back to the runtime engine.
150150
/// The `EventLoopFuture` should be completed with either a response encoded as `ByteBuffer` or an `Error`
151-
func handle(event: ByteBuffer, context: Lambda.Context) -> EventLoopFuture<ByteBuffer?>
151+
func handle(_ event: ByteBuffer, context: Lambda.Context) -> EventLoopFuture<ByteBuffer?>
152152

153153
/// Clean up the Lambda resources asynchronously.
154154
/// Concrete Lambda handlers implement this method to shutdown resources like `HTTPClient`s and database connections.

Sources/AWSLambdaRuntimeCore/LambdaRunner.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ extension Lambda {
6262
self.isGettingNextInvocation = true
6363
return self.runtimeClient.getNextInvocation(logger: logger).peekError { error in
6464
logger.error("could not fetch work from lambda runtime engine: \(error)")
65-
}.flatMap { invocation, event in
65+
}.flatMap { invocation, bytes in
6666
// 2. send invocation to handler
6767
self.isGettingNextInvocation = false
6868
let context = Context(logger: logger,
6969
eventLoop: self.eventLoop,
7070
allocator: self.allocator,
7171
invocation: invocation)
7272
logger.debug("sending invocation to lambda handler \(handler)")
73-
return handler.handle(event: event, context: context)
73+
return handler.handle(bytes, context: context)
7474
// Hopping back to "our" EventLoop is important in case the handler returns a future that
7575
// originiated from a foreign EventLoop/EventLoopGroup.
7676
// This can happen if the handler uses a library (lets say a DB client) that manages its own threads/loops

Sources/AWSLambdaTesting/Lambda+Testing.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ extension Lambda {
9797
let handler = try promise.futureResult.wait()
9898

9999
return try eventLoop.flatSubmit {
100-
handler.handle(event: event, context: context)
100+
handler.handle(event, context: context)
101101
}.wait()
102102
}
103103
}

Sources/CodableSample/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct Handler: EventLoopLambdaHandler {
2929
typealias In = Request
3030
typealias Out = Response
3131

32-
func handle(event: Request, context: Lambda.Context) -> EventLoopFuture<Response> {
32+
func handle(_ event: Request, context: Lambda.Context) -> EventLoopFuture<Response> {
3333
// as an example, respond with the input event's reversed body
3434
context.eventLoop.makeSucceededFuture(Response(body: String(event.body.reversed())))
3535
}

Sources/StringSample/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct Handler: EventLoopLambdaHandler {
2020
typealias In = String
2121
typealias Out = String
2222

23-
func handle(event: String, context: Lambda.Context) -> EventLoopFuture<String> {
23+
func handle(_ event: String, context: Lambda.Context) -> EventLoopFuture<String> {
2424
// as an example, respond with the event's reversed body
2525
context.eventLoop.makeSucceededFuture(String(event.reversed()))
2626
}

Tests/AWSLambdaRuntimeCoreTests/LambdaHandlerTest.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class LambdaHandlerTest: XCTestCase {
3939
self.initialized = true
4040
}
4141

42-
func handle(event: String, context: Lambda.Context) async throws -> String {
42+
func handle(_ event: String, context: Lambda.Context) async throws -> String {
4343
event
4444
}
4545
}
@@ -68,7 +68,7 @@ class LambdaHandlerTest: XCTestCase {
6868
throw TestError("kaboom")
6969
}
7070

71-
func handle(event: String, context: Lambda.Context) async throws {
71+
func handle(_ event: String, context: Lambda.Context) async throws {
7272
XCTFail("How can this be called if init failed")
7373
}
7474
}
@@ -91,7 +91,7 @@ class LambdaHandlerTest: XCTestCase {
9191

9292
init(context: Lambda.InitializationContext) {}
9393

94-
func handle(event: String, context: Lambda.Context) async throws -> String {
94+
func handle(_ event: String, context: Lambda.Context) async throws -> String {
9595
event
9696
}
9797
}
@@ -114,7 +114,7 @@ class LambdaHandlerTest: XCTestCase {
114114

115115
init(context: Lambda.InitializationContext) {}
116116

117-
func handle(event: String, context: Lambda.Context) async throws {}
117+
func handle(_ event: String, context: Lambda.Context) async throws {}
118118
}
119119

120120
let maxTimes = Int.random(in: 1 ... 10)
@@ -136,7 +136,7 @@ class LambdaHandlerTest: XCTestCase {
136136

137137
init(context: Lambda.InitializationContext) {}
138138

139-
func handle(event: String, context: Lambda.Context) async throws -> String {
139+
func handle(_ event: String, context: Lambda.Context) async throws -> String {
140140
throw TestError("boom")
141141
}
142142
}
@@ -159,7 +159,7 @@ class LambdaHandlerTest: XCTestCase {
159159
typealias In = String
160160
typealias Out = String
161161

162-
func handle(event: String, context: Lambda.Context) -> EventLoopFuture<String> {
162+
func handle(_ event: String, context: Lambda.Context) -> EventLoopFuture<String> {
163163
context.eventLoop.makeSucceededFuture(event)
164164
}
165165
}
@@ -181,7 +181,7 @@ class LambdaHandlerTest: XCTestCase {
181181
typealias In = String
182182
typealias Out = Void
183183

184-
func handle(event: String, context: Lambda.Context) -> EventLoopFuture<Void> {
184+
func handle(_ event: String, context: Lambda.Context) -> EventLoopFuture<Void> {
185185
context.eventLoop.makeSucceededFuture(())
186186
}
187187
}
@@ -203,7 +203,7 @@ class LambdaHandlerTest: XCTestCase {
203203
typealias In = String
204204
typealias Out = String
205205

206-
func handle(event: String, context: Lambda.Context) -> EventLoopFuture<String> {
206+
func handle(_ event: String, context: Lambda.Context) -> EventLoopFuture<String> {
207207
context.eventLoop.makeFailedFuture(TestError("boom"))
208208
}
209209
}

Tests/AWSLambdaRuntimeCoreTests/LambdaHandlers.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct EchoHandler: EventLoopLambdaHandler {
1919
typealias In = String
2020
typealias Out = String
2121

22-
func handle(event: String, context: Lambda.Context) -> EventLoopFuture<String> {
22+
func handle(_ event: String, context: Lambda.Context) -> EventLoopFuture<String> {
2323
context.eventLoop.makeSucceededFuture(event)
2424
}
2525
}
@@ -34,7 +34,7 @@ struct FailedHandler: EventLoopLambdaHandler {
3434
self.reason = reason
3535
}
3636

37-
func handle(event: String, context: Lambda.Context) -> EventLoopFuture<Void> {
37+
func handle(_ event: String, context: Lambda.Context) -> EventLoopFuture<Void> {
3838
context.eventLoop.makeFailedFuture(TestError(self.reason))
3939
}
4040
}

Tests/AWSLambdaRuntimeCoreTests/LambdaLifecycleTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class LambdaLifecycleTest: XCTestCase {
5454
self.shutdown = shutdown
5555
}
5656

57-
func handle(event: ByteBuffer, context: Lambda.Context) -> EventLoopFuture<ByteBuffer?> {
57+
func handle(_ event: ByteBuffer, context: Lambda.Context) -> EventLoopFuture<ByteBuffer?> {
5858
self.handler(context, event)
5959
}
6060

Tests/AWSLambdaRuntimeTests/Lambda+CodeableTest.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class CodableLambdaTest: XCTestCase {
4343

4444
let expected: Request
4545

46-
func handle(event: Request, context: Lambda.Context) -> EventLoopFuture<Void> {
46+
func handle(_ event: Request, context: Lambda.Context) -> EventLoopFuture<Void> {
4747
XCTAssertEqual(event, self.expected)
4848
return context.eventLoop.makeSucceededVoidFuture()
4949
}
@@ -52,7 +52,7 @@ class CodableLambdaTest: XCTestCase {
5252
let handler = Handler(expected: request)
5353

5454
XCTAssertNoThrow(inputBuffer = try JSONEncoder().encode(request, using: self.allocator))
55-
XCTAssertNoThrow(outputBuffer = try handler.handle(event: XCTUnwrap(inputBuffer), context: self.newContext()).wait())
55+
XCTAssertNoThrow(outputBuffer = try handler.handle(XCTUnwrap(inputBuffer), context: self.newContext()).wait())
5656
XCTAssertNil(outputBuffer)
5757
}
5858

@@ -68,7 +68,7 @@ class CodableLambdaTest: XCTestCase {
6868

6969
let expected: Request
7070

71-
func handle(event: Request, context: Lambda.Context) -> EventLoopFuture<Response> {
71+
func handle(_ event: Request, context: Lambda.Context) -> EventLoopFuture<Response> {
7272
XCTAssertEqual(event, self.expected)
7373
return context.eventLoop.makeSucceededFuture(Response(requestId: event.requestId))
7474
}
@@ -77,7 +77,7 @@ class CodableLambdaTest: XCTestCase {
7777
let handler = Handler(expected: request)
7878

7979
XCTAssertNoThrow(inputBuffer = try JSONEncoder().encode(request, using: self.allocator))
80-
XCTAssertNoThrow(outputBuffer = try handler.handle(event: XCTUnwrap(inputBuffer), context: self.newContext()).wait())
80+
XCTAssertNoThrow(outputBuffer = try handler.handle(XCTUnwrap(inputBuffer), context: self.newContext()).wait())
8181
XCTAssertNoThrow(response = try JSONDecoder().decode(Response.self, from: XCTUnwrap(outputBuffer)))
8282
XCTAssertEqual(response?.requestId, request.requestId)
8383
}
@@ -93,7 +93,7 @@ class CodableLambdaTest: XCTestCase {
9393

9494
init(context: Lambda.InitializationContext) async throws {}
9595

96-
func handle(event: Request, context: Lambda.Context) async throws {
96+
func handle(_ event: Request, context: Lambda.Context) async throws {
9797
XCTAssertEqual(event, self.expected)
9898
}
9999
}
@@ -107,7 +107,7 @@ class CodableLambdaTest: XCTestCase {
107107
handler.expected = request
108108

109109
XCTAssertNoThrow(inputBuffer = try JSONEncoder().encode(request, using: self.allocator))
110-
XCTAssertNoThrow(outputBuffer = try handler.handle(event: XCTUnwrap(inputBuffer), context: self.newContext()).wait())
110+
XCTAssertNoThrow(outputBuffer = try handler.handle(XCTUnwrap(inputBuffer), context: self.newContext()).wait())
111111
XCTAssertNil(outputBuffer)
112112
}
113113
}
@@ -122,7 +122,7 @@ class CodableLambdaTest: XCTestCase {
122122

123123
init(context: Lambda.InitializationContext) async throws {}
124124

125-
func handle(event: Request, context: Lambda.Context) async throws -> Response {
125+
func handle(_ event: Request, context: Lambda.Context) async throws -> Response {
126126
XCTAssertEqual(event, self.expected)
127127
return Response(requestId: event.requestId)
128128
}
@@ -138,7 +138,7 @@ class CodableLambdaTest: XCTestCase {
138138
handler.expected = request
139139

140140
XCTAssertNoThrow(inputBuffer = try JSONEncoder().encode(request, using: self.allocator))
141-
XCTAssertNoThrow(outputBuffer = try handler.handle(event: XCTUnwrap(inputBuffer), context: self.newContext()).wait())
141+
XCTAssertNoThrow(outputBuffer = try handler.handle(XCTUnwrap(inputBuffer), context: self.newContext()).wait())
142142
XCTAssertNoThrow(response = try JSONDecoder().decode(Response.self, from: XCTUnwrap(outputBuffer)))
143143
XCTAssertEqual(response?.requestId, request.requestId)
144144
}

Tests/AWSLambdaTestingTests/Tests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class LambdaTestingTests: XCTestCase {
3535

3636
init(context: Lambda.InitializationContext) {}
3737

38-
func handle(event: Request, context: Lambda.Context) async throws -> Response {
38+
func handle(_ event: Request, context: Lambda.Context) async throws -> Response {
3939
Response(message: "echo" + event.name)
4040
}
4141
}
@@ -59,7 +59,7 @@ class LambdaTestingTests: XCTestCase {
5959

6060
init(context: Lambda.InitializationContext) {}
6161

62-
func handle(event: Request, context: Lambda.Context) async throws {
62+
func handle(_ event: Request, context: Lambda.Context) async throws {
6363
LambdaTestingTests.VoidLambdaHandlerInvokeCount += 1
6464
}
6565
}
@@ -79,7 +79,7 @@ class LambdaTestingTests: XCTestCase {
7979

8080
init(context: Lambda.InitializationContext) {}
8181

82-
func handle(event: String, context: Lambda.Context) async throws {
82+
func handle(_ event: String, context: Lambda.Context) async throws {
8383
throw MyError()
8484
}
8585
}
@@ -96,7 +96,7 @@ class LambdaTestingTests: XCTestCase {
9696

9797
init(context: Lambda.InitializationContext) {}
9898

99-
func handle(event: String, context: Lambda.Context) async throws -> String {
99+
func handle(_ event: String, context: Lambda.Context) async throws -> String {
100100
try await Task.sleep(nanoseconds: 500 * 1000 * 1000)
101101
return event
102102
}

0 commit comments

Comments
 (0)