diff --git a/Sources/AWSLambdaRuntime/Lambda+Codable.swift b/Sources/AWSLambdaRuntime/Lambda+Codable.swift index 23743a98..f837c75b 100644 --- a/Sources/AWSLambdaRuntime/Lambda+Codable.swift +++ b/Sources/AWSLambdaRuntime/Lambda+Codable.swift @@ -57,8 +57,8 @@ internal struct CodableClosureWrapper: LambdaHand self.closure = closure } - func handle(context: Lambda.Context, payload: In, callback: @escaping (Result) -> Void) { - self.closure(context, payload, callback) + func handle(context: Lambda.Context, event: In, callback: @escaping (Result) -> Void) { + self.closure(context, event, callback) } } @@ -72,8 +72,8 @@ internal struct CodableVoidClosureWrapper: LambdaHandler { self.closure = closure } - func handle(context: Lambda.Context, payload: In, callback: @escaping (Result) -> Void) { - self.closure(context, payload, callback) + func handle(context: Lambda.Context, event: In, callback: @escaping (Result) -> Void) { + self.closure(context, event, callback) } } diff --git a/Sources/AWSLambdaRuntimeCore/Lambda+String.swift b/Sources/AWSLambdaRuntimeCore/Lambda+String.swift index b9858c50..27971db6 100644 --- a/Sources/AWSLambdaRuntimeCore/Lambda+String.swift +++ b/Sources/AWSLambdaRuntimeCore/Lambda+String.swift @@ -64,8 +64,8 @@ internal struct StringClosureWrapper: LambdaHandler { self.closure = closure } - func handle(context: Lambda.Context, payload: In, callback: @escaping (Result) -> Void) { - self.closure(context, payload, callback) + func handle(context: Lambda.Context, event: In, callback: @escaping (Result) -> Void) { + self.closure(context, event, callback) } } @@ -79,8 +79,8 @@ internal struct StringVoidClosureWrapper: LambdaHandler { self.closure = closure } - func handle(context: Lambda.Context, payload: In, callback: @escaping (Result) -> Void) { - self.closure(context, payload, callback) + func handle(context: Lambda.Context, event: In, callback: @escaping (Result) -> Void) { + self.closure(context, event, callback) } } diff --git a/Sources/AWSLambdaRuntimeCore/LambdaHandler.swift b/Sources/AWSLambdaRuntimeCore/LambdaHandler.swift index 8e44792d..f14fb787 100644 --- a/Sources/AWSLambdaRuntimeCore/LambdaHandler.swift +++ b/Sources/AWSLambdaRuntimeCore/LambdaHandler.swift @@ -33,10 +33,10 @@ public protocol LambdaHandler: EventLoopLambdaHandler { /// /// - parameters: /// - context: Runtime `Context`. - /// - payload: Payload of type `In` representing the event or request. + /// - event: Event of type `In` representing the event or request. /// - callback: Completion handler to report the result of the Lambda back to the runtime engine. /// The completion handler expects a `Result` with either a response of type `Out` or an `Error` - func handle(context: Lambda.Context, payload: In, callback: @escaping (Result) -> Void) + func handle(context: Lambda.Context, event: In, callback: @escaping (Result) -> Void) } internal extension Lambda { @@ -52,11 +52,11 @@ public extension LambdaHandler { /// `LambdaHandler` is offloading the processing to a `DispatchQueue` /// This is slower but safer, in case the implementation blocks the `EventLoop` /// Performance sensitive Lambdas should be based on `EventLoopLambdaHandler` which does not offload. - func handle(context: Lambda.Context, payload: In) -> EventLoopFuture { + func handle(context: Lambda.Context, event: In) -> EventLoopFuture { let promise = context.eventLoop.makePromise(of: Out.self) // FIXME: reusable DispatchQueue self.offloadQueue.async { - self.handle(context: context, payload: payload, callback: promise.completeWith) + self.handle(context: context, event: event, callback: promise.completeWith) } return promise.futureResult } @@ -80,11 +80,11 @@ public protocol EventLoopLambdaHandler: ByteBufferLambdaHandler { /// /// - parameters: /// - context: Runtime `Context`. - /// - payload: Payload of type `In` representing the event or request. + /// - event: Event of type `In` representing the event or request. /// /// - Returns: An `EventLoopFuture` to report the result of the Lambda back to the runtime engine. /// The `EventLoopFuture` should be completed with either a response of type `Out` or an `Error` - func handle(context: Lambda.Context, payload: In) -> EventLoopFuture + func handle(context: Lambda.Context, event: In) -> EventLoopFuture /// Encode a response of type `Out` to `ByteBuffer` /// Concrete Lambda handlers implement this method to provide coding functionality. @@ -107,12 +107,12 @@ public protocol EventLoopLambdaHandler: ByteBufferLambdaHandler { public extension EventLoopLambdaHandler { /// Driver for `ByteBuffer` -> `In` decoding and `Out` -> `ByteBuffer` encoding - func handle(context: Lambda.Context, payload: ByteBuffer) -> EventLoopFuture { - switch self.decodeIn(buffer: payload) { + func handle(context: Lambda.Context, event: ByteBuffer) -> EventLoopFuture { + switch self.decodeIn(buffer: event) { case .failure(let error): return context.eventLoop.makeFailedFuture(CodecError.requestDecoding(error)) case .success(let `in`): - return self.handle(context: context, payload: `in`).flatMapThrowing { out in + return self.handle(context: context, event: `in`).flatMapThrowing { out in switch self.encodeOut(allocator: context.allocator, value: out) { case .failure(let error): throw CodecError.responseEncoding(error) @@ -159,11 +159,11 @@ public protocol ByteBufferLambdaHandler { /// /// - parameters: /// - context: Runtime `Context`. - /// - payload: The event or request payload encoded as `ByteBuffer`. + /// - event: The event or input payload encoded as `ByteBuffer`. /// /// - Returns: An `EventLoopFuture` to report the result of the Lambda back to the runtime engine. /// The `EventLoopFuture` should be completed with either a response encoded as `ByteBuffer` or an `Error` - func handle(context: Lambda.Context, payload: ByteBuffer) -> EventLoopFuture + func handle(context: Lambda.Context, event: ByteBuffer) -> EventLoopFuture } private enum CodecError: Error { diff --git a/Sources/AWSLambdaRuntimeCore/LambdaRunner.swift b/Sources/AWSLambdaRuntimeCore/LambdaRunner.swift index f2d13421..87a6ca6e 100644 --- a/Sources/AWSLambdaRuntimeCore/LambdaRunner.swift +++ b/Sources/AWSLambdaRuntimeCore/LambdaRunner.swift @@ -56,7 +56,7 @@ extension Lambda { self.isGettingNextInvocation = false let context = Context(logger: logger, eventLoop: self.eventLoop, invocation: invocation) logger.debug("sending invocation to lambda handler \(handler)") - return handler.handle(context: context, payload: payload) + return handler.handle(context: context, event: payload) .mapResult { result in if case .failure(let error) = result { logger.warning("lambda handler returned an error: \(error)") diff --git a/Sources/AWSLambdaTesting/Lambda+Testing.swift b/Sources/AWSLambdaTesting/Lambda+Testing.swift index ce64c67f..bb29aa67 100644 --- a/Sources/AWSLambdaTesting/Lambda+Testing.swift +++ b/Sources/AWSLambdaTesting/Lambda+Testing.swift @@ -88,7 +88,7 @@ extension Lambda { public static func test( _ handler: Handler, - with payload: In, + with event: In, using config: TestConfig = .init() ) throws -> Out where Handler.In == In, Handler.Out == Out { let logger = Logger(label: "test") @@ -105,7 +105,7 @@ extension Lambda { eventLoop: eventLoop) return try eventLoop.flatSubmit { - handler.handle(context: context, payload: payload) + handler.handle(context: context, event: event) }.wait() } } diff --git a/Sources/CodableSample/main.swift b/Sources/CodableSample/main.swift index 34e845b1..c1ea9b28 100644 --- a/Sources/CodableSample/main.swift +++ b/Sources/CodableSample/main.swift @@ -29,9 +29,9 @@ struct Handler: EventLoopLambdaHandler { typealias In = Request typealias Out = Response - func handle(context: Lambda.Context, payload: Request) -> EventLoopFuture { + func handle(context: Lambda.Context, event: Request) -> EventLoopFuture { // as an example, respond with the reverse the input payload - context.eventLoop.makeSucceededFuture(Response(body: String(payload.body.reversed()))) + context.eventLoop.makeSucceededFuture(Response(body: String(event.body.reversed()))) } } diff --git a/Sources/StringSample/main.swift b/Sources/StringSample/main.swift index c7d0434a..37584b48 100644 --- a/Sources/StringSample/main.swift +++ b/Sources/StringSample/main.swift @@ -20,9 +20,9 @@ struct Handler: EventLoopLambdaHandler { typealias In = String typealias Out = String - func handle(context: Lambda.Context, payload: String) -> EventLoopFuture { + func handle(context: Lambda.Context, event: String) -> EventLoopFuture { // as an example, respond with the reverse the input payload - context.eventLoop.makeSucceededFuture(String(payload.reversed())) + context.eventLoop.makeSucceededFuture(String(event.reversed())) } } diff --git a/Tests/AWSLambdaRuntimeCoreTests/Lambda+StringTest.swift b/Tests/AWSLambdaRuntimeCoreTests/Lambda+StringTest.swift index a0be16d6..4bbb4caa 100644 --- a/Tests/AWSLambdaRuntimeCoreTests/Lambda+StringTest.swift +++ b/Tests/AWSLambdaRuntimeCoreTests/Lambda+StringTest.swift @@ -26,8 +26,8 @@ class StringLambdaTest: XCTestCase { typealias In = String typealias Out = String - func handle(context: Lambda.Context, payload: String, callback: (Result) -> Void) { - callback(.success(payload)) + func handle(context: Lambda.Context, event: String, callback: (Result) -> Void) { + callback(.success(event)) } } @@ -46,7 +46,7 @@ class StringLambdaTest: XCTestCase { typealias In = String typealias Out = Void - func handle(context: Lambda.Context, payload: String, callback: (Result) -> Void) { + func handle(context: Lambda.Context, event: String, callback: (Result) -> Void) { callback(.success(())) } } @@ -66,7 +66,7 @@ class StringLambdaTest: XCTestCase { typealias In = String typealias Out = String - func handle(context: Lambda.Context, payload: String, callback: (Result) -> Void) { + func handle(context: Lambda.Context, event: String, callback: (Result) -> Void) { callback(.failure(TestError("boom"))) } } @@ -86,8 +86,8 @@ class StringLambdaTest: XCTestCase { typealias In = String typealias Out = String - func handle(context: Lambda.Context, payload: String) -> EventLoopFuture { - context.eventLoop.makeSucceededFuture(payload) + func handle(context: Lambda.Context, event: String) -> EventLoopFuture { + context.eventLoop.makeSucceededFuture(event) } } @@ -106,7 +106,7 @@ class StringLambdaTest: XCTestCase { typealias In = String typealias Out = Void - func handle(context: Lambda.Context, payload: String) -> EventLoopFuture { + func handle(context: Lambda.Context, event: String) -> EventLoopFuture { context.eventLoop.makeSucceededFuture(()) } } @@ -126,7 +126,7 @@ class StringLambdaTest: XCTestCase { typealias In = String typealias Out = String - func handle(context: Lambda.Context, payload: String) -> EventLoopFuture { + func handle(context: Lambda.Context, event: String) -> EventLoopFuture { context.eventLoop.makeFailedFuture(TestError("boom")) } } @@ -189,7 +189,7 @@ class StringLambdaTest: XCTestCase { throw TestError("kaboom") } - func handle(context: Lambda.Context, payload: String, callback: (Result) -> Void) { + func handle(context: Lambda.Context, event: String, callback: (Result) -> Void) { callback(.failure(TestError("should not be called"))) } } diff --git a/Tests/AWSLambdaRuntimeCoreTests/LambdaTest.swift b/Tests/AWSLambdaRuntimeCoreTests/LambdaTest.swift index 97caa4a9..557821bf 100644 --- a/Tests/AWSLambdaRuntimeCoreTests/LambdaTest.swift +++ b/Tests/AWSLambdaRuntimeCoreTests/LambdaTest.swift @@ -56,8 +56,8 @@ class LambdaTest: XCTestCase { self.initialized = true } - func handle(context: Lambda.Context, payload: String, callback: (Result) -> Void) { - callback(.success(payload)) + func handle(context: Lambda.Context, event: String, callback: (Result) -> Void) { + callback(.success(event)) } } @@ -89,7 +89,7 @@ class LambdaTest: XCTestCase { throw TestError("kaboom") } - func handle(context: Lambda.Context, payload: String, callback: (Result) -> Void) { + func handle(context: Lambda.Context, event: String, callback: (Result) -> Void) { callback(.failure(TestError("should not be called"))) } } diff --git a/Tests/AWSLambdaRuntimeCoreTests/Utils.swift b/Tests/AWSLambdaRuntimeCoreTests/Utils.swift index 11e6004e..409461f5 100644 --- a/Tests/AWSLambdaRuntimeCoreTests/Utils.swift +++ b/Tests/AWSLambdaRuntimeCoreTests/Utils.swift @@ -38,8 +38,8 @@ struct EchoHandler: LambdaHandler { typealias In = String typealias Out = String - func handle(context: Lambda.Context, payload: String, callback: (Result) -> Void) { - callback(.success(payload)) + func handle(context: Lambda.Context, event: String, callback: (Result) -> Void) { + callback(.success(event)) } } @@ -53,7 +53,7 @@ struct FailedHandler: LambdaHandler { self.reason = reason } - func handle(context: Lambda.Context, payload: String, callback: (Result) -> Void) { + func handle(context: Lambda.Context, event: String, callback: (Result) -> Void) { callback(.failure(TestError(self.reason))) } } diff --git a/Tests/AWSLambdaRuntimeTests/Lambda+CodeableTest.swift b/Tests/AWSLambdaRuntimeTests/Lambda+CodeableTest.swift index 8ecb17bb..5a99dc42 100644 --- a/Tests/AWSLambdaRuntimeTests/Lambda+CodeableTest.swift +++ b/Tests/AWSLambdaRuntimeTests/Lambda+CodeableTest.swift @@ -42,7 +42,7 @@ class CodableLambdaTest: XCTestCase { } XCTAssertNoThrow(inputBuffer = try JSONEncoder().encode(request, using: self.allocator)) - XCTAssertNoThrow(outputBuffer = try closureWrapper.handle(context: self.newContext(), payload: XCTUnwrap(inputBuffer)).wait()) + XCTAssertNoThrow(outputBuffer = try closureWrapper.handle(context: self.newContext(), event: XCTUnwrap(inputBuffer)).wait()) XCTAssertNil(outputBuffer) } @@ -58,7 +58,7 @@ class CodableLambdaTest: XCTestCase { } XCTAssertNoThrow(inputBuffer = try JSONEncoder().encode(request, using: self.allocator)) - XCTAssertNoThrow(outputBuffer = try closureWrapper.handle(context: self.newContext(), payload: XCTUnwrap(inputBuffer)).wait()) + XCTAssertNoThrow(outputBuffer = try closureWrapper.handle(context: self.newContext(), event: XCTUnwrap(inputBuffer)).wait()) XCTAssertNoThrow(response = try JSONDecoder().decode(Response.self, from: XCTUnwrap(outputBuffer))) XCTAssertEqual(response?.requestId, request.requestId) } diff --git a/Tests/AWSLambdaTestingTests/Tests.swift b/Tests/AWSLambdaTestingTests/Tests.swift index 9236a630..cd1aa328 100644 --- a/Tests/AWSLambdaTestingTests/Tests.swift +++ b/Tests/AWSLambdaTestingTests/Tests.swift @@ -63,9 +63,9 @@ class LambdaTestingTests: XCTestCase { typealias In = Request typealias Out = Response - func handle(context: Lambda.Context, payload: In, callback: @escaping (Result) -> Void) { + func handle(context: Lambda.Context, event: In, callback: @escaping (Result) -> Void) { XCTAssertFalse(context.eventLoop.inEventLoop) - callback(.success(Response(message: "echo" + payload.name))) + callback(.success(Response(message: "echo" + event.name))) } } @@ -80,9 +80,9 @@ class LambdaTestingTests: XCTestCase { typealias In = String typealias Out = String - func handle(context: Lambda.Context, payload: String) -> EventLoopFuture { + func handle(context: Lambda.Context, event: String) -> EventLoopFuture { XCTAssertTrue(context.eventLoop.inEventLoop) - return context.eventLoop.makeSucceededFuture("echo" + payload) + return context.eventLoop.makeSucceededFuture("echo" + event) } } @@ -99,7 +99,7 @@ class LambdaTestingTests: XCTestCase { typealias In = String typealias Out = Void - func handle(context: Lambda.Context, payload: In, callback: @escaping (Result) -> Void) { + func handle(context: Lambda.Context, event: In, callback: @escaping (Result) -> Void) { callback(.failure(MyError())) } }