Skip to content

Commit 0008e59

Browse files
authored
Rename payload to event (#115)
1 parent 71587ea commit 0008e59

29 files changed

+145
-145
lines changed

Examples/LambdaFunctions/Sources/APIGateway/main.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct APIGatewayProxyLambda: EventLoopLambdaHandler {
2727
public typealias In = APIGateway.V2.Request
2828
public typealias Out = APIGateway.V2.Response
2929

30-
public func handle(context: Lambda.Context, payload: APIGateway.V2.Request) -> EventLoopFuture<APIGateway.V2.Response> {
30+
public func handle(context: Lambda.Context, event: APIGateway.V2.Request) -> EventLoopFuture<APIGateway.V2.Response> {
3131
context.logger.debug("hello, api gateway!")
3232
return context.eventLoop.makeSucceededFuture(APIGateway.V2.Response(statusCode: .ok, body: "hello, world!"))
3333
}

Examples/LambdaFunctions/Sources/Benchmark/main.swift

+1-1
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(context: Lambda.Context, payload: String) -> EventLoopFuture<String> {
28+
func handle(context: Lambda.Context, event: String) -> EventLoopFuture<String> {
2929
context.eventLoop.makeSucceededFuture("hello, world!")
3030
}
3131
}

Examples/LocalDebugging/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ Start with running the `MyLambda` target.
2323
* Set the `LOCAL_LAMBDA_SERVER_ENABLED` environment variable to `true` by editing the `MyLambda` scheme under `Run`.
2424
* Hit `Run`
2525
* Once it is up you should see a log message in the Xcode console saying
26-
`LocalLambdaServer started and listening on 127.0.0.1:7000, receiving payloads on /invoke`
27-
which means the local emulator is up and receiving traffic on port `7000` and expecting payloads on the `/invoke` endpoint.
26+
`LocalLambdaServer started and listening on 127.0.0.1:7000, receiving events on /invoke`
27+
which means the local emulator is up and receiving traffic on port `7000` and expecting events on the `/invoke` endpoint.
2828

2929
Continue to run the `MyApp` target
3030
* Switch to the `MyApp` scheme and select a simulator destination.

Sources/AWSLambdaEvents/Cloudwatch.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import struct Foundation.Date
1616

17-
/// EventBridge has the same payloads/notification types as CloudWatch
17+
/// EventBridge has the same events/notification types as CloudWatch
1818
typealias EventBridge = Cloudwatch
1919

2020
public protocol CloudwatchDetail: Decodable {
@@ -66,7 +66,7 @@ public enum Cloudwatch {
6666

6767
let detailType = try container.decode(String.self, forKey: .detailType)
6868
guard detailType.lowercased() == Detail.name.lowercased() else {
69-
throw PayloadTypeMismatch(name: detailType, type: Detail.self)
69+
throw DetailTypeMismatch(name: detailType, type: Detail.self)
7070
}
7171

7272
self.detail = try container.decode(Detail.self, forKey: .detail)
@@ -122,7 +122,7 @@ public enum Cloudwatch {
122122
}
123123
}
124124

125-
struct PayloadTypeMismatch: Error {
125+
struct DetailTypeMismatch: Error {
126126
let name: String
127127
let type: Any
128128
}

Sources/AWSLambdaRuntime/Lambda+Codable.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import class Foundation.JSONEncoder
1818
import NIO
1919
import NIOFoundationCompat
2020

21-
/// Extension to the `Lambda` companion to enable execution of Lambdas that take and return `Codable` payloads.
21+
/// Extension to the `Lambda` companion to enable execution of Lambdas that take and return `Codable` events.
2222
extension Lambda {
2323
/// An asynchronous Lambda Closure that takes a `In: Decodable` and returns a `Result<Out: Encodable, Error>` via a completion handler.
2424
public typealias CodableClosure<In: Decodable, Out: Encodable> = (Lambda.Context, In, @escaping (Result<Out, Error>) -> Void) -> Void
@@ -57,8 +57,8 @@ internal struct CodableClosureWrapper<In: Decodable, Out: Encodable>: LambdaHand
5757
self.closure = closure
5858
}
5959

60-
func handle(context: Lambda.Context, payload: In, callback: @escaping (Result<Out, Error>) -> Void) {
61-
self.closure(context, payload, callback)
60+
func handle(context: Lambda.Context, event: In, callback: @escaping (Result<Out, Error>) -> Void) {
61+
self.closure(context, event, callback)
6262
}
6363
}
6464

@@ -72,8 +72,8 @@ internal struct CodableVoidClosureWrapper<In: Decodable>: LambdaHandler {
7272
self.closure = closure
7373
}
7474

75-
func handle(context: Lambda.Context, payload: In, callback: @escaping (Result<Out, Error>) -> Void) {
76-
self.closure(context, payload, callback)
75+
func handle(context: Lambda.Context, event: In, callback: @escaping (Result<Out, Error>) -> Void) {
76+
self.closure(context, event, callback)
7777
}
7878
}
7979

Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ import NIOHTTP1
2323
// For example:
2424
//
2525
// try Lambda.withLocalServer {
26-
// Lambda.run { (context: Lambda.Context, payload: String, callback: @escaping (Result<String, Error>) -> Void) in
27-
// callback(.success("Hello, \(payload)!"))
26+
// Lambda.run { (context: Lambda.Context, event: String, callback: @escaping (Result<String, Error>) -> Void) in
27+
// callback(.success("Hello, \(event)!"))
2828
// }
2929
// }
3030
extension Lambda {
3131
/// Execute code in the context of a mock Lambda server.
3232
///
3333
/// - parameters:
34-
/// - invocationEndpoint: The endpoint to post payloads to.
34+
/// - invocationEndpoint: The endpoint to post events to.
3535
/// - body: Code to run within the context of the mock server. Typically this would be a Lambda.run function call.
3636
///
3737
/// - note: This API is designed stricly for local testing and is behind a DEBUG flag
@@ -77,7 +77,7 @@ private enum LocalLambda {
7777
guard channel.localAddress != nil else {
7878
return channel.eventLoop.makeFailedFuture(ServerError.cantBind)
7979
}
80-
self.logger.info("LocalLambdaServer started and listening on \(self.host):\(self.port), receiving payloads on \(self.invocationEndpoint)")
80+
self.logger.info("LocalLambdaServer started and listening on \(self.host):\(self.port), receiving events on \(self.invocationEndpoint)")
8181
return channel.eventLoop.makeSucceededFuture(())
8282
}
8383
}

Sources/AWSLambdaRuntimeCore/Lambda+String.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//===----------------------------------------------------------------------===//
1414
import NIO
1515

16-
/// Extension to the `Lambda` companion to enable execution of Lambdas that take and return `String` payloads.
16+
/// Extension to the `Lambda` companion to enable execution of Lambdas that take and return `String` events.
1717
extension Lambda {
1818
/// An asynchronous Lambda Closure that takes a `String` and returns a `Result<String, Error>` via a completion handler.
1919
public typealias StringClosure = (Lambda.Context, String, @escaping (Result<String, Error>) -> Void) -> Void
@@ -64,8 +64,8 @@ internal struct StringClosureWrapper: LambdaHandler {
6464
self.closure = closure
6565
}
6666

67-
func handle(context: Lambda.Context, payload: In, callback: @escaping (Result<Out, Error>) -> Void) {
68-
self.closure(context, payload, callback)
67+
func handle(context: Lambda.Context, event: In, callback: @escaping (Result<Out, Error>) -> Void) {
68+
self.closure(context, event, callback)
6969
}
7070
}
7171

@@ -79,8 +79,8 @@ internal struct StringVoidClosureWrapper: LambdaHandler {
7979
self.closure = closure
8080
}
8181

82-
func handle(context: Lambda.Context, payload: In, callback: @escaping (Result<Out, Error>) -> Void) {
83-
self.closure(context, payload, callback)
82+
func handle(context: Lambda.Context, event: In, callback: @escaping (Result<Out, Error>) -> Void) {
83+
self.closure(context, event, callback)
8484
}
8585
}
8686

Sources/AWSLambdaRuntimeCore/LambdaHandler.swift

+11-11
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ public protocol LambdaHandler: EventLoopLambdaHandler {
3333
///
3434
/// - parameters:
3535
/// - context: Runtime `Context`.
36-
/// - payload: Payload of type `In` representing the event or request.
36+
/// - event: Event of type `In` representing the event or request.
3737
/// - callback: Completion handler to report the result of the Lambda back to the runtime engine.
3838
/// The completion handler expects a `Result` with either a response of type `Out` or an `Error`
39-
func handle(context: Lambda.Context, payload: In, callback: @escaping (Result<Out, Error>) -> Void)
39+
func handle(context: Lambda.Context, event: In, callback: @escaping (Result<Out, Error>) -> Void)
4040
}
4141

4242
internal extension Lambda {
@@ -52,11 +52,11 @@ public extension LambdaHandler {
5252
/// `LambdaHandler` is offloading the processing to a `DispatchQueue`
5353
/// This is slower but safer, in case the implementation blocks the `EventLoop`
5454
/// Performance sensitive Lambdas should be based on `EventLoopLambdaHandler` which does not offload.
55-
func handle(context: Lambda.Context, payload: In) -> EventLoopFuture<Out> {
55+
func handle(context: Lambda.Context, event: In) -> EventLoopFuture<Out> {
5656
let promise = context.eventLoop.makePromise(of: Out.self)
5757
// FIXME: reusable DispatchQueue
5858
self.offloadQueue.async {
59-
self.handle(context: context, payload: payload, callback: promise.completeWith)
59+
self.handle(context: context, event: event, callback: promise.completeWith)
6060
}
6161
return promise.futureResult
6262
}
@@ -80,11 +80,11 @@ public protocol EventLoopLambdaHandler: ByteBufferLambdaHandler {
8080
///
8181
/// - parameters:
8282
/// - context: Runtime `Context`.
83-
/// - payload: Payload of type `In` representing the event or request.
83+
/// - event: Event of type `In` representing the event or request.
8484
///
8585
/// - Returns: An `EventLoopFuture` to report the result of the Lambda back to the runtime engine.
8686
/// The `EventLoopFuture` should be completed with either a response of type `Out` or an `Error`
87-
func handle(context: Lambda.Context, payload: In) -> EventLoopFuture<Out>
87+
func handle(context: Lambda.Context, event: In) -> EventLoopFuture<Out>
8888

8989
/// Encode a response of type `Out` to `ByteBuffer`
9090
/// Concrete Lambda handlers implement this method to provide coding functionality.
@@ -107,12 +107,12 @@ public protocol EventLoopLambdaHandler: ByteBufferLambdaHandler {
107107

108108
public extension EventLoopLambdaHandler {
109109
/// Driver for `ByteBuffer` -> `In` decoding and `Out` -> `ByteBuffer` encoding
110-
func handle(context: Lambda.Context, payload: ByteBuffer) -> EventLoopFuture<ByteBuffer?> {
111-
switch self.decodeIn(buffer: payload) {
110+
func handle(context: Lambda.Context, event: ByteBuffer) -> EventLoopFuture<ByteBuffer?> {
111+
switch self.decodeIn(buffer: event) {
112112
case .failure(let error):
113113
return context.eventLoop.makeFailedFuture(CodecError.requestDecoding(error))
114114
case .success(let `in`):
115-
return self.handle(context: context, payload: `in`).flatMapThrowing { out in
115+
return self.handle(context: context, event: `in`).flatMapThrowing { out in
116116
switch self.encodeOut(allocator: context.allocator, value: out) {
117117
case .failure(let error):
118118
throw CodecError.responseEncoding(error)
@@ -159,11 +159,11 @@ public protocol ByteBufferLambdaHandler {
159159
///
160160
/// - parameters:
161161
/// - context: Runtime `Context`.
162-
/// - payload: The event or request payload encoded as `ByteBuffer`.
162+
/// - event: The event or input payload encoded as `ByteBuffer`.
163163
///
164164
/// - Returns: An `EventLoopFuture` to report the result of the Lambda back to the runtime engine.
165165
/// The `EventLoopFuture` should be completed with either a response encoded as `ByteBuffer` or an `Error`
166-
func handle(context: Lambda.Context, payload: ByteBuffer) -> EventLoopFuture<ByteBuffer?>
166+
func handle(context: Lambda.Context, event: ByteBuffer) -> EventLoopFuture<ByteBuffer?>
167167
}
168168

169169
private enum CodecError: Error {

Sources/AWSLambdaRuntimeCore/LambdaRunner.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ extension Lambda {
5151
self.isGettingNextInvocation = true
5252
return self.runtimeClient.getNextInvocation(logger: logger).peekError { error in
5353
logger.error("could not fetch work from lambda runtime engine: \(error)")
54-
}.flatMap { invocation, payload in
54+
}.flatMap { invocation, event in
5555
// 2. send invocation to handler
5656
self.isGettingNextInvocation = false
5757
let context = Context(logger: logger, eventLoop: self.eventLoop, invocation: invocation)
5858
logger.debug("sending invocation to lambda handler \(handler)")
59-
return handler.handle(context: context, payload: payload)
59+
return handler.handle(context: context, event: event)
6060
.mapResult { result in
6161
if case .failure(let error) = result {
6262
logger.warning("lambda handler returned an error: \(error)")

Sources/AWSLambdaRuntimeCore/LambdaRuntimeClient.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ extension Lambda {
4141
throw RuntimeError.badStatusCode(response.status)
4242
}
4343
let invocation = try Invocation(headers: response.headers)
44-
guard let payload = response.body else {
44+
guard let event = response.body else {
4545
throw RuntimeError.noBody
4646
}
47-
return (invocation, payload)
47+
return (invocation, event)
4848
}.flatMapErrorThrowing { error in
4949
switch error {
5050
case HTTPClient.Errors.timeout:

Sources/AWSLambdaTesting/Lambda+Testing.swift

+12-12
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
// typealias In = String
2323
// typealias Out = String
2424
//
25-
// func handle(context: Lambda.Context, payload: String) -> EventLoopFuture<String> {
26-
// return context.eventLoop.makeSucceededFuture("echo" + payload)
25+
// func handle(context: Lambda.Context, event: String) -> EventLoopFuture<String> {
26+
// return context.eventLoop.makeSucceededFuture("echo" + event)
2727
// }
2828
// }
2929
//
@@ -59,36 +59,36 @@ extension Lambda {
5959
}
6060

6161
public static func test(_ closure: @escaping Lambda.StringClosure,
62-
with payload: String,
62+
with event: String,
6363
using config: TestConfig = .init()) throws -> String {
64-
try Self.test(StringClosureWrapper(closure), with: payload, using: config)
64+
try Self.test(StringClosureWrapper(closure), with: event, using: config)
6565
}
6666

6767
public static func test(_ closure: @escaping Lambda.StringVoidClosure,
68-
with payload: String,
68+
with event: String,
6969
using config: TestConfig = .init()) throws {
70-
_ = try Self.test(StringVoidClosureWrapper(closure), with: payload, using: config)
70+
_ = try Self.test(StringVoidClosureWrapper(closure), with: event, using: config)
7171
}
7272

7373
public static func test<In: Decodable, Out: Encodable>(
7474
_ closure: @escaping Lambda.CodableClosure<In, Out>,
75-
with payload: In,
75+
with event: In,
7676
using config: TestConfig = .init()
7777
) throws -> Out {
78-
try Self.test(CodableClosureWrapper(closure), with: payload, using: config)
78+
try Self.test(CodableClosureWrapper(closure), with: event, using: config)
7979
}
8080

8181
public static func test<In: Decodable>(
8282
_ closure: @escaping Lambda.CodableVoidClosure<In>,
83-
with payload: In,
83+
with event: In,
8484
using config: TestConfig = .init()
8585
) throws {
86-
_ = try Self.test(CodableVoidClosureWrapper(closure), with: payload, using: config)
86+
_ = try Self.test(CodableVoidClosureWrapper(closure), with: event, using: config)
8787
}
8888

8989
public static func test<In, Out, Handler: EventLoopLambdaHandler>(
9090
_ handler: Handler,
91-
with payload: In,
91+
with event: In,
9292
using config: TestConfig = .init()
9393
) throws -> Out where Handler.In == In, Handler.Out == Out {
9494
let logger = Logger(label: "test")
@@ -105,7 +105,7 @@ extension Lambda {
105105
eventLoop: eventLoop)
106106

107107
return try eventLoop.flatSubmit {
108-
handler.handle(context: context, payload: payload)
108+
handler.handle(context: context, event: event)
109109
}.wait()
110110
}
111111
}

Sources/CodableSample/main.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ struct Handler: EventLoopLambdaHandler {
2929
typealias In = Request
3030
typealias Out = Response
3131

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

Sources/StringSample/main.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ struct Handler: EventLoopLambdaHandler {
2020
typealias In = String
2121
typealias Out = String
2222

23-
func handle(context: Lambda.Context, payload: String) -> EventLoopFuture<String> {
24-
// as an example, respond with the reverse the input payload
25-
context.eventLoop.makeSucceededFuture(String(payload.reversed()))
23+
func handle(context: Lambda.Context, event: String) -> EventLoopFuture<String> {
24+
// as an example, respond with the event's reversed body
25+
context.eventLoop.makeSucceededFuture(String(event.reversed()))
2626
}
2727
}
2828

@@ -31,7 +31,7 @@ Lambda.run(Handler())
3131
// MARK: - this can also be expressed as a closure:
3232

3333
/*
34-
Lambda.run { (_, payload: String, callback) in
35-
callback(.success(String(payload.reversed())))
34+
Lambda.run { (_, event: String, callback) in
35+
callback(.success(String(event.reversed())))
3636
}
3737
*/

Tests/AWSLambdaEventsTests/ALBTests.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import XCTest
1717

1818
class ALBTests: XCTestCase {
19-
static let exampleSingleValueHeadersPayload = """
19+
static let exampleSingleValueHeadersEventBody = """
2020
{
2121
"requestContext":{
2222
"elb":{
@@ -44,8 +44,8 @@ class ALBTests: XCTestCase {
4444
}
4545
"""
4646

47-
func testRequestWithSingleValueHeadersPayload() {
48-
let data = ALBTests.exampleSingleValueHeadersPayload.data(using: .utf8)!
47+
func testRequestWithSingleValueHeadersEvent() {
48+
let data = ALBTests.exampleSingleValueHeadersEventBody.data(using: .utf8)!
4949
do {
5050
let decoder = JSONDecoder()
5151

Tests/AWSLambdaEventsTests/APIGateway+V2Tests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import XCTest
1717

1818
class APIGatewayV2Tests: XCTestCase {
19-
static let exampleGetPayload = """
19+
static let exampleGetEventBody = """
2020
{
2121
"routeKey":"GET /hello",
2222
"version":"2.0",
@@ -77,7 +77,7 @@ class APIGatewayV2Tests: XCTestCase {
7777
// MARK: Decoding
7878

7979
func testRequestDecodingExampleGetRequest() {
80-
let data = APIGatewayV2Tests.exampleGetPayload.data(using: .utf8)!
80+
let data = APIGatewayV2Tests.exampleGetEventBody.data(using: .utf8)!
8181
var req: APIGateway.V2.Request?
8282
XCTAssertNoThrow(req = try JSONDecoder().decode(APIGateway.V2.Request.self, from: data))
8383

0 commit comments

Comments
 (0)