diff --git a/Examples/LambdaFunctions/Sources/APIGateway/main.swift b/Examples/LambdaFunctions/Sources/APIGateway/main.swift index 9df57d43..abe0f5a5 100644 --- a/Examples/LambdaFunctions/Sources/APIGateway/main.swift +++ b/Examples/LambdaFunctions/Sources/APIGateway/main.swift @@ -27,7 +27,7 @@ struct APIGatewayProxyLambda: EventLoopLambdaHandler { public typealias In = APIGateway.V2.Request public typealias Out = APIGateway.V2.Response - public func handle(context: Lambda.Context, payload: APIGateway.V2.Request) -> EventLoopFuture { + public func handle(context: Lambda.Context, event: APIGateway.V2.Request) -> EventLoopFuture { context.logger.debug("hello, api gateway!") return context.eventLoop.makeSucceededFuture(APIGateway.V2.Response(statusCode: .ok, body: "hello, world!")) } diff --git a/Examples/LambdaFunctions/Sources/Benchmark/main.swift b/Examples/LambdaFunctions/Sources/Benchmark/main.swift index d0b7daaa..6e902a56 100644 --- a/Examples/LambdaFunctions/Sources/Benchmark/main.swift +++ b/Examples/LambdaFunctions/Sources/Benchmark/main.swift @@ -25,7 +25,7 @@ struct BenchmarkHandler: EventLoopLambdaHandler { typealias In = String typealias Out = String - func handle(context: Lambda.Context, payload: String) -> EventLoopFuture { + func handle(context: Lambda.Context, event: String) -> EventLoopFuture { context.eventLoop.makeSucceededFuture("hello, world!") } } diff --git a/Examples/LocalDebugging/README.md b/Examples/LocalDebugging/README.md index 2b5b4fe4..efc3fbf1 100644 --- a/Examples/LocalDebugging/README.md +++ b/Examples/LocalDebugging/README.md @@ -23,8 +23,8 @@ Start with running the `MyLambda` target. * Set the `LOCAL_LAMBDA_SERVER_ENABLED` environment variable to `true` by editing the `MyLambda` scheme under `Run`. * Hit `Run` * Once it is up you should see a log message in the Xcode console saying -`LocalLambdaServer started and listening on 127.0.0.1:7000, receiving payloads on /invoke` -which means the local emulator is up and receiving traffic on port `7000` and expecting payloads on the `/invoke` endpoint. +`LocalLambdaServer started and listening on 127.0.0.1:7000, receiving events on /invoke` +which means the local emulator is up and receiving traffic on port `7000` and expecting events on the `/invoke` endpoint. Continue to run the `MyApp` target * Switch to the `MyApp` scheme and select a simulator destination. diff --git a/Sources/AWSLambdaEvents/Cloudwatch.swift b/Sources/AWSLambdaEvents/Cloudwatch.swift index f07ddfb5..3ef3eb9e 100644 --- a/Sources/AWSLambdaEvents/Cloudwatch.swift +++ b/Sources/AWSLambdaEvents/Cloudwatch.swift @@ -14,7 +14,7 @@ import struct Foundation.Date -/// EventBridge has the same payloads/notification types as CloudWatch +/// EventBridge has the same events/notification types as CloudWatch typealias EventBridge = Cloudwatch public protocol CloudwatchDetail: Decodable { @@ -66,7 +66,7 @@ public enum Cloudwatch { let detailType = try container.decode(String.self, forKey: .detailType) guard detailType.lowercased() == Detail.name.lowercased() else { - throw PayloadTypeMismatch(name: detailType, type: Detail.self) + throw DetailTypeMismatch(name: detailType, type: Detail.self) } self.detail = try container.decode(Detail.self, forKey: .detail) @@ -122,7 +122,7 @@ public enum Cloudwatch { } } - struct PayloadTypeMismatch: Error { + struct DetailTypeMismatch: Error { let name: String let type: Any } diff --git a/Sources/AWSLambdaRuntime/Lambda+Codable.swift b/Sources/AWSLambdaRuntime/Lambda+Codable.swift index 23743a98..6173b0d2 100644 --- a/Sources/AWSLambdaRuntime/Lambda+Codable.swift +++ b/Sources/AWSLambdaRuntime/Lambda+Codable.swift @@ -18,7 +18,7 @@ import class Foundation.JSONEncoder import NIO import NIOFoundationCompat -/// Extension to the `Lambda` companion to enable execution of Lambdas that take and return `Codable` payloads. +/// Extension to the `Lambda` companion to enable execution of Lambdas that take and return `Codable` events. extension Lambda { /// An asynchronous Lambda Closure that takes a `In: Decodable` and returns a `Result` via a completion handler. public typealias CodableClosure = (Lambda.Context, In, @escaping (Result) -> Void) -> Void @@ -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+LocalServer.swift b/Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift index ffc9ff52..0d6a285b 100644 --- a/Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift +++ b/Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift @@ -23,15 +23,15 @@ import NIOHTTP1 // For example: // // try Lambda.withLocalServer { -// Lambda.run { (context: Lambda.Context, payload: String, callback: @escaping (Result) -> Void) in -// callback(.success("Hello, \(payload)!")) +// Lambda.run { (context: Lambda.Context, event: String, callback: @escaping (Result) -> Void) in +// callback(.success("Hello, \(event)!")) // } // } extension Lambda { /// Execute code in the context of a mock Lambda server. /// /// - parameters: - /// - invocationEndpoint: The endpoint to post payloads to. + /// - invocationEndpoint: The endpoint to post events to. /// - body: Code to run within the context of the mock server. Typically this would be a Lambda.run function call. /// /// - note: This API is designed stricly for local testing and is behind a DEBUG flag @@ -77,7 +77,7 @@ private enum LocalLambda { guard channel.localAddress != nil else { return channel.eventLoop.makeFailedFuture(ServerError.cantBind) } - self.logger.info("LocalLambdaServer started and listening on \(self.host):\(self.port), receiving payloads on \(self.invocationEndpoint)") + self.logger.info("LocalLambdaServer started and listening on \(self.host):\(self.port), receiving events on \(self.invocationEndpoint)") return channel.eventLoop.makeSucceededFuture(()) } } diff --git a/Sources/AWSLambdaRuntimeCore/Lambda+String.swift b/Sources/AWSLambdaRuntimeCore/Lambda+String.swift index b9858c50..bc186da6 100644 --- a/Sources/AWSLambdaRuntimeCore/Lambda+String.swift +++ b/Sources/AWSLambdaRuntimeCore/Lambda+String.swift @@ -13,7 +13,7 @@ //===----------------------------------------------------------------------===// import NIO -/// Extension to the `Lambda` companion to enable execution of Lambdas that take and return `String` payloads. +/// Extension to the `Lambda` companion to enable execution of Lambdas that take and return `String` events. extension Lambda { /// An asynchronous Lambda Closure that takes a `String` and returns a `Result` via a completion handler. public typealias StringClosure = (Lambda.Context, String, @escaping (Result) -> Void) -> Void @@ -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..f42ec229 100644 --- a/Sources/AWSLambdaRuntimeCore/LambdaRunner.swift +++ b/Sources/AWSLambdaRuntimeCore/LambdaRunner.swift @@ -51,12 +51,12 @@ extension Lambda { self.isGettingNextInvocation = true return self.runtimeClient.getNextInvocation(logger: logger).peekError { error in logger.error("could not fetch work from lambda runtime engine: \(error)") - }.flatMap { invocation, payload in + }.flatMap { invocation, event in // 2. send invocation to handler 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: event) .mapResult { result in if case .failure(let error) = result { logger.warning("lambda handler returned an error: \(error)") diff --git a/Sources/AWSLambdaRuntimeCore/LambdaRuntimeClient.swift b/Sources/AWSLambdaRuntimeCore/LambdaRuntimeClient.swift index b873d08b..2976a8c2 100644 --- a/Sources/AWSLambdaRuntimeCore/LambdaRuntimeClient.swift +++ b/Sources/AWSLambdaRuntimeCore/LambdaRuntimeClient.swift @@ -41,10 +41,10 @@ extension Lambda { throw RuntimeError.badStatusCode(response.status) } let invocation = try Invocation(headers: response.headers) - guard let payload = response.body else { + guard let event = response.body else { throw RuntimeError.noBody } - return (invocation, payload) + return (invocation, event) }.flatMapErrorThrowing { error in switch error { case HTTPClient.Errors.timeout: diff --git a/Sources/AWSLambdaTesting/Lambda+Testing.swift b/Sources/AWSLambdaTesting/Lambda+Testing.swift index ce64c67f..961ce681 100644 --- a/Sources/AWSLambdaTesting/Lambda+Testing.swift +++ b/Sources/AWSLambdaTesting/Lambda+Testing.swift @@ -22,8 +22,8 @@ // typealias In = String // typealias Out = String // -// func handle(context: Lambda.Context, payload: String) -> EventLoopFuture { -// return context.eventLoop.makeSucceededFuture("echo" + payload) +// func handle(context: Lambda.Context, event: String) -> EventLoopFuture { +// return context.eventLoop.makeSucceededFuture("echo" + event) // } // } // @@ -59,36 +59,36 @@ extension Lambda { } public static func test(_ closure: @escaping Lambda.StringClosure, - with payload: String, + with event: String, using config: TestConfig = .init()) throws -> String { - try Self.test(StringClosureWrapper(closure), with: payload, using: config) + try Self.test(StringClosureWrapper(closure), with: event, using: config) } public static func test(_ closure: @escaping Lambda.StringVoidClosure, - with payload: String, + with event: String, using config: TestConfig = .init()) throws { - _ = try Self.test(StringVoidClosureWrapper(closure), with: payload, using: config) + _ = try Self.test(StringVoidClosureWrapper(closure), with: event, using: config) } public static func test( _ closure: @escaping Lambda.CodableClosure, - with payload: In, + with event: In, using config: TestConfig = .init() ) throws -> Out { - try Self.test(CodableClosureWrapper(closure), with: payload, using: config) + try Self.test(CodableClosureWrapper(closure), with: event, using: config) } public static func test( _ closure: @escaping Lambda.CodableVoidClosure, - with payload: In, + with event: In, using config: TestConfig = .init() ) throws { - _ = try Self.test(CodableVoidClosureWrapper(closure), with: payload, using: config) + _ = try Self.test(CodableVoidClosureWrapper(closure), with: event, using: config) } 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..59cc8dee 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 { - // as an example, respond with the reverse the input payload - context.eventLoop.makeSucceededFuture(Response(body: String(payload.body.reversed()))) + func handle(context: Lambda.Context, event: Request) -> EventLoopFuture { + // as an example, respond with the input event's reversed body + context.eventLoop.makeSucceededFuture(Response(body: String(event.body.reversed()))) } } diff --git a/Sources/StringSample/main.swift b/Sources/StringSample/main.swift index c7d0434a..452160f9 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 { - // as an example, respond with the reverse the input payload - context.eventLoop.makeSucceededFuture(String(payload.reversed())) + func handle(context: Lambda.Context, event: String) -> EventLoopFuture { + // as an example, respond with the event's reversed body + context.eventLoop.makeSucceededFuture(String(event.reversed())) } } @@ -31,7 +31,7 @@ Lambda.run(Handler()) // MARK: - this can also be expressed as a closure: /* - Lambda.run { (_, payload: String, callback) in - callback(.success(String(payload.reversed()))) + Lambda.run { (_, event: String, callback) in + callback(.success(String(event.reversed()))) } */ diff --git a/Tests/AWSLambdaEventsTests/ALBTests.swift b/Tests/AWSLambdaEventsTests/ALBTests.swift index 398e32ed..b24684c9 100644 --- a/Tests/AWSLambdaEventsTests/ALBTests.swift +++ b/Tests/AWSLambdaEventsTests/ALBTests.swift @@ -16,7 +16,7 @@ import XCTest class ALBTests: XCTestCase { - static let exampleSingleValueHeadersPayload = """ + static let exampleSingleValueHeadersEventBody = """ { "requestContext":{ "elb":{ @@ -44,8 +44,8 @@ class ALBTests: XCTestCase { } """ - func testRequestWithSingleValueHeadersPayload() { - let data = ALBTests.exampleSingleValueHeadersPayload.data(using: .utf8)! + func testRequestWithSingleValueHeadersEvent() { + let data = ALBTests.exampleSingleValueHeadersEventBody.data(using: .utf8)! do { let decoder = JSONDecoder() diff --git a/Tests/AWSLambdaEventsTests/APIGateway+V2Tests.swift b/Tests/AWSLambdaEventsTests/APIGateway+V2Tests.swift index c48d9dc0..9d682c94 100644 --- a/Tests/AWSLambdaEventsTests/APIGateway+V2Tests.swift +++ b/Tests/AWSLambdaEventsTests/APIGateway+V2Tests.swift @@ -16,7 +16,7 @@ import XCTest class APIGatewayV2Tests: XCTestCase { - static let exampleGetPayload = """ + static let exampleGetEventBody = """ { "routeKey":"GET /hello", "version":"2.0", @@ -77,7 +77,7 @@ class APIGatewayV2Tests: XCTestCase { // MARK: Decoding func testRequestDecodingExampleGetRequest() { - let data = APIGatewayV2Tests.exampleGetPayload.data(using: .utf8)! + let data = APIGatewayV2Tests.exampleGetEventBody.data(using: .utf8)! var req: APIGateway.V2.Request? XCTAssertNoThrow(req = try JSONDecoder().decode(APIGateway.V2.Request.self, from: data)) diff --git a/Tests/AWSLambdaEventsTests/APIGatewayTests.swift b/Tests/AWSLambdaEventsTests/APIGatewayTests.swift index 7a1a7d9e..37cba98a 100644 --- a/Tests/AWSLambdaEventsTests/APIGatewayTests.swift +++ b/Tests/AWSLambdaEventsTests/APIGatewayTests.swift @@ -16,11 +16,11 @@ import XCTest class APIGatewayTests: XCTestCase { - static let exampleGetPayload = """ + static let exampleGetEventBody = """ {"httpMethod": "GET", "body": null, "resource": "/test", "requestContext": {"resourceId": "123456", "apiId": "1234567890", "resourcePath": "/test", "httpMethod": "GET", "requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef", "accountId": "123456789012", "stage": "Prod", "identity": {"apiKey": null, "userArn": null, "cognitoAuthenticationType": null, "caller": null, "userAgent": "Custom User Agent String", "user": null, "cognitoIdentityPoolId": null, "cognitoAuthenticationProvider": null, "sourceIp": "127.0.0.1", "accountId": null}, "extendedRequestId": null, "path": "/test"}, "queryStringParameters": null, "multiValueQueryStringParameters": null, "headers": {"Host": "127.0.0.1:3000", "Connection": "keep-alive", "Cache-Control": "max-age=0", "Dnt": "1", "Upgrade-Insecure-Requests": "1", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.36 Edg/78.0.276.24", "Sec-Fetch-User": "?1", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3", "Sec-Fetch-Site": "none", "Sec-Fetch-Mode": "navigate", "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "en-US,en;q=0.9", "X-Forwarded-Proto": "http", "X-Forwarded-Port": "3000"}, "multiValueHeaders": {"Host": ["127.0.0.1:3000"], "Connection": ["keep-alive"], "Cache-Control": ["max-age=0"], "Dnt": ["1"], "Upgrade-Insecure-Requests": ["1"], "User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.36 Edg/78.0.276.24"], "Sec-Fetch-User": ["?1"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3"], "Sec-Fetch-Site": ["none"], "Sec-Fetch-Mode": ["navigate"], "Accept-Encoding": ["gzip, deflate, br"], "Accept-Language": ["en-US,en;q=0.9"], "X-Forwarded-Proto": ["http"], "X-Forwarded-Port": ["3000"]}, "pathParameters": null, "stageVariables": null, "path": "/test", "isBase64Encoded": false} """ - static let todoPostPayload = """ + static let todoPostEventBody = """ {"httpMethod": "POST", "body": "{\\"title\\":\\"a todo\\"}", "resource": "/todos", "requestContext": {"resourceId": "123456", "apiId": "1234567890", "resourcePath": "/todos", "httpMethod": "POST", "requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef", "accountId": "123456789012", "stage": "test", "identity": {"apiKey": null, "userArn": null, "cognitoAuthenticationType": null, "caller": null, "userAgent": "Custom User Agent String", "user": null, "cognitoIdentityPoolId": null, "cognitoAuthenticationProvider": null, "sourceIp": "127.0.0.1", "accountId": null}, "extendedRequestId": null, "path": "/todos"}, "queryStringParameters": null, "multiValueQueryStringParameters": null, "headers": {"Host": "127.0.0.1:3000", "Connection": "keep-alive", "Content-Length": "18", "Pragma": "no-cache", "Cache-Control": "no-cache", "Accept": "text/plain, */*; q=0.01", "Origin": "http://todobackend.com", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.36 Safari/537.36 Edg/79.0.309.25", "Dnt": "1", "Content-Type": "application/json", "Sec-Fetch-Site": "cross-site", "Sec-Fetch-Mode": "cors", "Referer": "http://todobackend.com/specs/index.html?http://127.0.0.1:3000/todos", "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "en-US,en;q=0.9", "X-Forwarded-Proto": "http", "X-Forwarded-Port": "3000"}, "multiValueHeaders": {"Host": ["127.0.0.1:3000"], "Connection": ["keep-alive"], "Content-Length": ["18"], "Pragma": ["no-cache"], "Cache-Control": ["no-cache"], "Accept": ["text/plain, */*; q=0.01"], "Origin": ["http://todobackend.com"], "User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.36 Safari/537.36 Edg/79.0.309.25"], "Dnt": ["1"], "Content-Type": ["application/json"], "Sec-Fetch-Site": ["cross-site"], "Sec-Fetch-Mode": ["cors"], "Referer": ["http://todobackend.com/specs/index.html?http://127.0.0.1:3000/todos"], "Accept-Encoding": ["gzip, deflate, br"], "Accept-Language": ["en-US,en;q=0.9"], "X-Forwarded-Proto": ["http"], "X-Forwarded-Port": ["3000"]}, "pathParameters": null, "stageVariables": null, "path": "/todos", "isBase64Encoded": false} """ @@ -29,7 +29,7 @@ class APIGatewayTests: XCTestCase { // MARK: Decoding func testRequestDecodingExampleGetRequest() { - let data = APIGatewayTests.exampleGetPayload.data(using: .utf8)! + let data = APIGatewayTests.exampleGetEventBody.data(using: .utf8)! var req: APIGateway.Request? XCTAssertNoThrow(req = try JSONDecoder().decode(APIGateway.Request.self, from: data)) @@ -38,7 +38,7 @@ class APIGatewayTests: XCTestCase { } func testRequestDecodingTodoPostRequest() { - let data = APIGatewayTests.todoPostPayload.data(using: .utf8)! + let data = APIGatewayTests.todoPostEventBody.data(using: .utf8)! var req: APIGateway.Request? XCTAssertNoThrow(req = try JSONDecoder().decode(APIGateway.Request.self, from: data)) diff --git a/Tests/AWSLambdaEventsTests/CloudwatchTests.swift b/Tests/AWSLambdaEventsTests/CloudwatchTests.swift index 93a677c5..b931e020 100644 --- a/Tests/AWSLambdaEventsTests/CloudwatchTests.swift +++ b/Tests/AWSLambdaEventsTests/CloudwatchTests.swift @@ -16,7 +16,7 @@ import XCTest class CloudwatchTests: XCTestCase { - static func eventPayload(type: String, details: String) -> String { + static func eventBody(type: String, details: String) -> String { """ { "id": "cdc73f9d-aea9-11e3-9d5a-835b769c0d9c", @@ -34,8 +34,8 @@ class CloudwatchTests: XCTestCase { } func testScheduledEventFromJSON() { - let payload = CloudwatchTests.eventPayload(type: Cloudwatch.Scheduled.name, details: "{}") - let data = payload.data(using: .utf8)! + let eventBody = CloudwatchTests.eventBody(type: Cloudwatch.Scheduled.name, details: "{}") + let data = eventBody.data(using: .utf8)! var maybeEvent: Cloudwatch.ScheduledEvent? XCTAssertNoThrow(maybeEvent = try JSONDecoder().decode(Cloudwatch.ScheduledEvent.self, from: data)) @@ -52,9 +52,9 @@ class CloudwatchTests: XCTestCase { } func testEC2InstanceStateChangeNotificationEventFromJSON() { - let payload = CloudwatchTests.eventPayload(type: Cloudwatch.EC2.InstanceStateChangeNotification.name, - details: "{ \"instance-id\": \"0\", \"state\": \"stopping\" }") - let data = payload.data(using: .utf8)! + let eventBody = CloudwatchTests.eventBody(type: Cloudwatch.EC2.InstanceStateChangeNotification.name, + details: "{ \"instance-id\": \"0\", \"state\": \"stopping\" }") + let data = eventBody.data(using: .utf8)! var maybeEvent: Cloudwatch.EC2.InstanceStateChangeNotificationEvent? XCTAssertNoThrow(maybeEvent = try JSONDecoder().decode(Cloudwatch.EC2.InstanceStateChangeNotificationEvent.self, from: data)) @@ -73,9 +73,9 @@ class CloudwatchTests: XCTestCase { } func testEC2SpotInstanceInterruptionNoticeEventFromJSON() { - let payload = CloudwatchTests.eventPayload(type: Cloudwatch.EC2.SpotInstanceInterruptionNotice.name, - details: "{ \"instance-id\": \"0\", \"instance-action\": \"terminate\" }") - let data = payload.data(using: .utf8)! + let eventBody = CloudwatchTests.eventBody(type: Cloudwatch.EC2.SpotInstanceInterruptionNotice.name, + details: "{ \"instance-id\": \"0\", \"instance-action\": \"terminate\" }") + let data = eventBody.data(using: .utf8)! var maybeEvent: Cloudwatch.EC2.SpotInstanceInterruptionNoticeEvent? XCTAssertNoThrow(maybeEvent = try JSONDecoder().decode(Cloudwatch.EC2.SpotInstanceInterruptionNoticeEvent.self, from: data)) @@ -100,8 +100,8 @@ class CloudwatchTests: XCTestCase { let name: String } - let payload = CloudwatchTests.eventPayload(type: Custom.name, details: "{ \"name\": \"foo\" }") - let data = payload.data(using: .utf8)! + let eventBody = CloudwatchTests.eventBody(type: Custom.name, details: "{ \"name\": \"foo\" }") + let data = eventBody.data(using: .utf8)! var maybeEvent: Cloudwatch.Event? XCTAssertNoThrow(maybeEvent = try JSONDecoder().decode(Cloudwatch.Event.self, from: data)) @@ -119,19 +119,19 @@ class CloudwatchTests: XCTestCase { } func testUnregistredType() { - let payload = CloudwatchTests.eventPayload(type: UUID().uuidString, details: "{}") - let data = payload.data(using: .utf8)! + let eventBody = CloudwatchTests.eventBody(type: UUID().uuidString, details: "{}") + let data = eventBody.data(using: .utf8)! XCTAssertThrowsError(try JSONDecoder().decode(Cloudwatch.ScheduledEvent.self, from: data)) { error in - XCTAssert(error is Cloudwatch.PayloadTypeMismatch, "expected PayloadTypeMismatch but received \(error)") + XCTAssert(error is Cloudwatch.DetailTypeMismatch, "expected DetailTypeMismatch but received \(error)") } } func testTypeMismatch() { - let payload = CloudwatchTests.eventPayload(type: Cloudwatch.EC2.InstanceStateChangeNotification.name, - details: "{ \"instance-id\": \"0\", \"state\": \"stopping\" }") - let data = payload.data(using: .utf8)! + let eventBody = CloudwatchTests.eventBody(type: Cloudwatch.EC2.InstanceStateChangeNotification.name, + details: "{ \"instance-id\": \"0\", \"state\": \"stopping\" }") + let data = eventBody.data(using: .utf8)! XCTAssertThrowsError(try JSONDecoder().decode(Cloudwatch.ScheduledEvent.self, from: data)) { error in - XCTAssert(error is Cloudwatch.PayloadTypeMismatch, "expected PayloadTypeMismatch but received \(error)") + XCTAssert(error is Cloudwatch.DetailTypeMismatch, "expected DetailTypeMismatch but received \(error)") } } } diff --git a/Tests/AWSLambdaEventsTests/DynamoDBTests.swift b/Tests/AWSLambdaEventsTests/DynamoDBTests.swift index ca391da8..91745ff6 100644 --- a/Tests/AWSLambdaEventsTests/DynamoDBTests.swift +++ b/Tests/AWSLambdaEventsTests/DynamoDBTests.swift @@ -16,7 +16,7 @@ import XCTest class DynamoDBTests: XCTestCase { - static let streamEventPayload = """ + static let streamEventBody = """ { "Records": [ { @@ -113,7 +113,7 @@ class DynamoDBTests: XCTestCase { """ func testEventFromJSON() { - let data = DynamoDBTests.streamEventPayload.data(using: .utf8)! + let data = DynamoDBTests.streamEventBody.data(using: .utf8)! var event: DynamoDB.Event? XCTAssertNoThrow(event = try JSONDecoder().decode(DynamoDB.Event.self, from: data)) diff --git a/Tests/AWSLambdaEventsTests/S3Tests.swift b/Tests/AWSLambdaEventsTests/S3Tests.swift index 19baa31e..f1655208 100644 --- a/Tests/AWSLambdaEventsTests/S3Tests.swift +++ b/Tests/AWSLambdaEventsTests/S3Tests.swift @@ -16,7 +16,7 @@ import XCTest class S3Tests: XCTestCase { - static let eventPayload = """ + static let eventBody = """ { "Records": [ { @@ -58,7 +58,7 @@ class S3Tests: XCTestCase { """ func testSimpleEventFromJSON() { - let data = S3Tests.eventPayload.data(using: .utf8)! + let data = S3Tests.eventBody.data(using: .utf8)! var event: S3.Event? XCTAssertNoThrow(event = try JSONDecoder().decode(S3.Event.self, from: data)) diff --git a/Tests/AWSLambdaEventsTests/SNSTests.swift b/Tests/AWSLambdaEventsTests/SNSTests.swift index ea7cc047..3830baed 100644 --- a/Tests/AWSLambdaEventsTests/SNSTests.swift +++ b/Tests/AWSLambdaEventsTests/SNSTests.swift @@ -16,7 +16,7 @@ import XCTest class SNSTests: XCTestCase { - static let eventPayload = """ + static let eventBody = """ { "Records": [ { @@ -51,7 +51,7 @@ class SNSTests: XCTestCase { """ func testSimpleEventFromJSON() { - let data = SNSTests.eventPayload.data(using: .utf8)! + let data = SNSTests.eventBody.data(using: .utf8)! var event: SNS.Event? XCTAssertNoThrow(event = try JSONDecoder().decode(SNS.Event.self, from: data)) diff --git a/Tests/AWSLambdaEventsTests/SQSTests.swift b/Tests/AWSLambdaEventsTests/SQSTests.swift index f337f075..ca8e3c70 100644 --- a/Tests/AWSLambdaEventsTests/SQSTests.swift +++ b/Tests/AWSLambdaEventsTests/SQSTests.swift @@ -16,7 +16,7 @@ import XCTest class SQSTests: XCTestCase { - static let testPayload = """ + static let eventBody = """ { "Records": [ { @@ -60,7 +60,7 @@ class SQSTests: XCTestCase { """ func testSimpleEventFromJSON() { - let data = SQSTests.testPayload.data(using: .utf8)! + let data = SQSTests.eventBody.data(using: .utf8)! var event: SQS.Event? XCTAssertNoThrow(event = try JSONDecoder().decode(SQS.Event.self, from: data)) diff --git a/Tests/AWSLambdaRuntimeCoreTests/Lambda+StringTest.swift b/Tests/AWSLambdaRuntimeCoreTests/Lambda+StringTest.swift index a0be16d6..9d54e277 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")) } } @@ -144,8 +144,8 @@ class StringLambdaTest: XCTestCase { let maxTimes = Int.random(in: 1 ... 10) let configuration = Lambda.Configuration(lifecycle: .init(maxTimes: maxTimes)) - let result = Lambda.run(configuration: configuration) { (_, payload: String, callback) in - callback(.success(payload)) + let result = Lambda.run(configuration: configuration) { (_, event: String, callback) in + callback(.success(event)) } assertLambdaLifecycleResult(result, shoudHaveRun: maxTimes) } @@ -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"))) } } @@ -201,17 +201,17 @@ class StringLambdaTest: XCTestCase { private struct Behavior: LambdaServerBehavior { let requestId: String - let payload: String + let event: String let result: Result - init(requestId: String = UUID().uuidString, payload: String = "hello", result: Result = .success("hello")) { + init(requestId: String = UUID().uuidString, event: String = "hello", result: Result = .success("hello")) { self.requestId = requestId - self.payload = payload + self.event = event self.result = result } func getInvocation() -> GetInvocationResult { - .success((requestId: self.requestId, payload: self.payload)) + .success((requestId: self.requestId, event: self.event)) } func processResponse(requestId: String, response: String?) -> Result { diff --git a/Tests/AWSLambdaRuntimeCoreTests/LambdaRunnerTest.swift b/Tests/AWSLambdaRuntimeCoreTests/LambdaRunnerTest.swift index f91bde4a..dd87eb61 100644 --- a/Tests/AWSLambdaRuntimeCoreTests/LambdaRunnerTest.swift +++ b/Tests/AWSLambdaRuntimeCoreTests/LambdaRunnerTest.swift @@ -19,14 +19,14 @@ class LambdaRunnerTest: XCTestCase { func testSuccess() { struct Behavior: LambdaServerBehavior { let requestId = UUID().uuidString - let payload = "hello" + let event = "hello" func getInvocation() -> GetInvocationResult { - .success((self.requestId, self.payload)) + .success((self.requestId, self.event)) } func processResponse(requestId: String, response: String?) -> Result { XCTAssertEqual(self.requestId, requestId, "expecting requestId to match") - XCTAssertEqual(self.payload, response, "expecting response to match") + XCTAssertEqual(self.event, response, "expecting response to match") return .success(()) } @@ -48,7 +48,7 @@ class LambdaRunnerTest: XCTestCase { static let error = "boom" let requestId = UUID().uuidString func getInvocation() -> GetInvocationResult { - .success((requestId: self.requestId, payload: "hello")) + .success((requestId: self.requestId, event: "hello")) } func processResponse(requestId: String, response: String?) -> Result { diff --git a/Tests/AWSLambdaRuntimeCoreTests/LambdaRuntimeClientTest.swift b/Tests/AWSLambdaRuntimeCoreTests/LambdaRuntimeClientTest.swift index ea3e279d..2f2529c4 100644 --- a/Tests/AWSLambdaRuntimeCoreTests/LambdaRuntimeClientTest.swift +++ b/Tests/AWSLambdaRuntimeCoreTests/LambdaRuntimeClientTest.swift @@ -118,7 +118,7 @@ class LambdaRuntimeClientTest: XCTestCase { func testProcessResponseInternalServerError() { struct Behavior: LambdaServerBehavior { func getInvocation() -> GetInvocationResult { - .success((requestId: "1", payload: "payload")) + .success((requestId: "1", event: "event")) } func processResponse(requestId: String, response: String?) -> Result { @@ -143,7 +143,7 @@ class LambdaRuntimeClientTest: XCTestCase { func testProcessErrorInternalServerError() { struct Behavior: LambdaServerBehavior { func getInvocation() -> GetInvocationResult { - .success((requestId: "1", payload: "payload")) + .success((requestId: "1", event: "event")) } func processResponse(requestId: String, response: String?) -> Result { diff --git a/Tests/AWSLambdaRuntimeCoreTests/LambdaTest.swift b/Tests/AWSLambdaRuntimeCoreTests/LambdaTest.swift index 97caa4a9..536beaa2 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"))) } } @@ -156,7 +156,7 @@ class LambdaTest: XCTestCase { func testTimeout() { let timeout: Int64 = 100 - let server = MockLambdaServer(behavior: Behavior(requestId: "timeout", payload: "\(timeout * 2)")) + let server = MockLambdaServer(behavior: Behavior(requestId: "timeout", event: "\(timeout * 2)")) XCTAssertNoThrow(try server.start().wait()) defer { XCTAssertNoThrow(try server.stop().wait()) } @@ -176,9 +176,9 @@ class LambdaTest: XCTestCase { assertLambdaLifecycleResult(result, shouldFailWithError: Lambda.RuntimeError.upstreamError("connectionResetByPeer")) } - func testBigPayload() { - let payload = String(repeating: "*", count: 104_448) - let server = MockLambdaServer(behavior: Behavior(payload: payload, result: .success(payload))) + func testBigEvent() { + let event = String(repeating: "*", count: 104_448) + let server = MockLambdaServer(behavior: Behavior(event: event, result: .success(event))) XCTAssertNoThrow(try server.start().wait()) defer { XCTAssertNoThrow(try server.stop().wait()) } @@ -293,17 +293,17 @@ class LambdaTest: XCTestCase { private struct Behavior: LambdaServerBehavior { let requestId: String - let payload: String + let event: String let result: Result - init(requestId: String = UUID().uuidString, payload: String = "hello", result: Result = .success("hello")) { + init(requestId: String = UUID().uuidString, event: String = "hello", result: Result = .success("hello")) { self.requestId = requestId - self.payload = payload + self.event = event self.result = result } func getInvocation() -> GetInvocationResult { - .success((requestId: self.requestId, payload: self.payload)) + .success((requestId: self.requestId, event: self.event)) } func processResponse(requestId: String, response: String?) -> Result { 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())) } } diff --git a/readme.md b/readme.md index 5bdca879..dc4756b2 100644 --- a/readme.md +++ b/readme.md @@ -59,12 +59,12 @@ Next, create a `main.swift` and implement your Lambda. import AWSLambdaRuntime // in this example we are receiving and responding with strings - Lambda.run { (context, payload: String, callback) in - callback(.success("Hello, \(payload)")) + Lambda.run { (context, event: String, callback) in + callback(.success("Hello, \(event)")) } ``` - More commonly, the payload would be a JSON, which is modeled using `Codable`, for example: + More commonly, the event would be a JSON, which is modeled using `Codable`, for example: ```swift // Import the module @@ -118,7 +118,7 @@ Next, create a `main.swift` and implement your Lambda. typealias Out = Void // Response type // In this example we are receiving an SNS Message, with no response (Void). - func handle(context: Lambda.Context, payload: In) -> EventLoopFuture { + func handle(context: Lambda.Context, event: In) -> EventLoopFuture { ... context.eventLoop.makeSucceededFuture(Void()) } @@ -156,11 +156,11 @@ public protocol ByteBufferLambdaHandler { /// /// - parameters: /// - context: Runtime `Context`. - /// - payload: The event or request payload encoded as `ByteBuffer`. + /// - event: The event or request 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 } ``` @@ -182,11 +182,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. @@ -226,10 +226,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) } ``` @@ -247,7 +247,7 @@ public typealias CodableClosure = (Lambda.Context public typealias StringClosure = (Lambda.Context, String, @escaping (Result) -> Void) -> Void ``` -This design allows for addition payload types as well, and such Lambda implementation can extend one of the above protocols and provided their own `ByteBuffer` -> `In` decoding and `Out` -> `ByteBuffer` encoding. +This design allows for additional event types as well, and such Lambda implementation can extend one of the above protocols and provided their own `ByteBuffer` -> `In` decoding and `Out` -> `ByteBuffer` encoding. ### Context @@ -314,7 +314,7 @@ A single Lambda execution workflow is made of the following steps: 1. The library calls AWS Lambda Runtime Engine `/next` endpoint to retrieve the next invocation request. 2. The library parses the response HTTP headers and populate the Context object. 3. The library reads the `/next` response body and attempt to decode it. Typically it decodes to user provided `In` type which extends `Decodable`, but users may choose to write Lambda functions that receive the input as String or `ByteBuffer` which require less, or no decoding. -4. The library hands off the `Context` and `In` payload to the user provided handler. In the case of `LambdaHandler` based handler this is done on a dedicated `DispatchQueue`, providing isolation between user's and the library's code. +4. The library hands off the `Context` and `In` event to the user provided handler. In the case of `LambdaHandler` based handler this is done on a dedicated `DispatchQueue`, providing isolation between user's and the library's code. 5. User provided handler processes the request asynchronously, invoking a callback or returning a future upon completion, which returns a Result type with the Out or Error populated. 6. In case of error, the library posts to AWS Lambda Runtime Engine `/error` endpoint to provide the error details, which will show up on AWS Lambda logs. 7. In case of success, the library will attempt to encode the response. Typically it encodes from user provided `Out` type which extends `Encodable`, but users may choose to write Lambda functions that return a String or `ByteBuffer`, which require less, or no encoding. The library then posts the response to AWS Lambda Runtime Engine `/response` endpoint to provide the response to the callee.