Skip to content

Commit 77ad9a5

Browse files
committed
Fix inaccuracies
1 parent ea76068 commit 77ad9a5

File tree

1 file changed

+23
-23
lines changed
  • Sources/AWSLambdaRuntimeCore/Documentation.docc/Proposals

1 file changed

+23
-23
lines changed

Sources/AWSLambdaRuntimeCore/Documentation.docc/Proposals/0001-v2-api.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ running blocking code on the same `EventLoop` the library uses. Developers also
1818
methods that are used to work with `EventLoop`s and `EventLoopFuture`s. This results in a lot of cognitive complexity
1919
and makes the code in the current API hard to reason about and maintain. For these reasons, the overarching trend in the
2020
Swift on Server ecosystem is to shift to newer, more readable, Swift concurrency constructs and de-couple from
21-
SwiftNIOs `EventLoop` interfaces.
21+
SwiftNIO's `EventLoop` interfaces.
2222

2323
#### No ownership of the main() function
2424

@@ -37,13 +37,13 @@ an implementation of the `handle` function where the business logic of the Lambd
3737
`SimpleLambdaHandler` is perfectly sufficient for small use-cases as the user does not need to spend much time looking
3838
into the library.
3939

40-
However, `SimpleLambdaHandler` cannot be used when services such as a database client need to be initalized before the
40+
However, `SimpleLambdaHandler` cannot be used when services such as a database client need to be initialized before the
4141
Lambda runtime starts and then also gracefully shutdown prior to the runtime terminating. This is because the only way
4242
to register termination logic is through the `LambdaInitializationContext` (containing a field
4343
`terminator: LambdaTerminator`) which is created and used _internally_ within `LambdaRuntime` and never exposed through
4444
`SimpleLambdaHandler`. For such use-cases, other handler protocols like `LambdaHandler` must be used. `LambdaHandler`
4545
exposes a `context` argument of type `LambdaInitializationContext` through its initializer. Within the initializer,
46-
required services can be initalized and their graceful shutdown logic can be registered with the
46+
required services can be initialized and their graceful shutdown logic can be registered with the
4747
`context.terminator.register` function.
4848

4949
Yet, `LambdaHandler` is quite cumbersome to use in such use-cases as users have to deviate from the established norms of
@@ -57,7 +57,7 @@ The Lambda runtime can only be started using the **internal** `Lambda.run()` fun
5757
`main()` function defined by the `LambdaHandler` protocol, preventing users from injecting initialized services into the
5858
runtime _prior_ to it starting. As shown below, this forces users to use an **unstructured concurrency** approach and
5959
manually initialize services, leading to the issue of the user then perhaps forgetting to gracefully shutdown the
60-
initalized services:
60+
initialized services:
6161

6262
```swift
6363
struct MyLambda: LambdaHandler {
@@ -88,7 +88,7 @@ struct MyLambda: LambdaHandler {
8888
}
8989

9090
func handle(_ event: Event, context: LambdaContext) async throws -> Output {
91-
/// Use the initalized service stored in `self.pgClient`
91+
/// Use the initialized service stored in `self.pgClient`
9292
try await self.pgClient.query(...)
9393
}
9494
}
@@ -131,7 +131,7 @@ of the `EventLoop` family of interfaces.
131131
same way the lifecycles of the required services are managed, e.g.
132132
`try await ServiceGroup(services: [postgresClient, ..., lambdaRuntime], ...).run()`.
133133
- Dependencies can now be injected into `LambdaRuntime``swift-service-lifecycle` guarantees that the services will be
134-
initialized _before_ the `LambdaRuntime`s `run()` function is called.
134+
initialized _before_ the `LambdaRuntime`'s `run()` function is called.
135135
- The required services can then be used within the handler in a structured concurrency manner.
136136
`swift-service-lifecycle` takes care of listening for termination signals and terminating the services as well as the
137137
`LambdaRuntime` in correct order.
@@ -162,7 +162,7 @@ try await serviceGroup.run()
162162

163163
### Simplifying Codable support
164164

165-
A detailed explanation is provided in the Codable Support section. In short, much of the boilerplate code defined for
165+
A detailed explanation is provided in the **Codable Support** section. In short, much of the boilerplate code defined for
166166
each handler protocol in `Lambda+Codable` and `Lambda+String` will be replaced with a single `LambdaCodableAdapter`
167167
class.
168168

@@ -181,7 +181,7 @@ Both will be explained in the **Detailed Solution** section.
181181

182182
## Detailed Solution
183183

184-
Below you’ll find explanation’s for all types that we want to use in AWS Lambda Runtime v2.
184+
Below are explanations for all types that we want to use in AWS Lambda Runtime v2.
185185

186186
### LambdaResponseWriter
187187

@@ -205,10 +205,10 @@ public protocol LambdaResponseWriter: ~Copyable {
205205
### LambdaContext
206206

207207
`LambdaContext` will be largely unchanged, but the `eventLoop` property as well as the `allocator` property (of type
208-
`ByteBuffer`) will be removed.
208+
`ByteBufferAllocator`) will be removed.
209209

210-
A new function `backgroundTask()` will also be added. This will allow tasks to be run in the background while and after
211-
the response is/has been sent. Please note that `LambdaContext` will not be Sendable anymore.
210+
A new function `addBackgroundTask(_:)` will also be added. This will allow tasks to be run in the background while and after
211+
the response is/has been sent. Please note that `LambdaContext` will not be `Sendable` anymore.
212212

213213
```swift
214214
/// A context object passed as part of an invocation in LambdaHandler handle functions.
@@ -247,10 +247,10 @@ public struct LambdaContext {
247247
### StreamingLambdaHandler
248248

249249
The new `StreamingLambdaHandler` protocol is the base protocol to implement a Lambda function. Most users will not use
250-
this protocol and instead use the `LambdaHandler` protocol defined in the `Codable` Support section.
250+
this protocol and instead use the `LambdaHandler` protocol defined in the **Codable Support** section.
251251

252252
```swift
253-
/// The base LambdaHandler protocol
253+
/// The base StreamingLambdaHandler protocol
254254
public protocol StreamingLambdaHandler: ~Copyable {
255255
/// The business logic of the Lambda function
256256
/// - Parameters:
@@ -354,7 +354,7 @@ enum Lambda {
354354
Since the library now provides ownership of the `main()` function and allows users to initialize services before the
355355
`LambdaRuntime` is initialized, the library cannot implicitly report
356356
[errors that occur during initialization to the dedicated endpoint AWS exposes](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-api.html#runtimes-api-initerror)
357-
like it currently does through the `initialize()` function of `LambdaRunner` which wraps the handlers `init(...)` and
357+
like it currently does through the `initialize()` function of `LambdaRunner` which wraps the handler's `init(...)` and
358358
handles any errors thrown by reporting it to the dedicated AWS endpoint.
359359

360360
To retain support for initialization error reporting, the `Lambda.reportStartupError(any Error)` function gives users
@@ -431,7 +431,7 @@ public protocol LambdaOutputEncoder {
431431
}
432432
```
433433

434-
We provide conformances for Foundations `JSONDecoder` to `LambdaEventDecoder` and `JSONEncoder` to
434+
We provide conformances for Foundation's `JSONDecoder` to `LambdaEventDecoder` and `JSONEncoder` to
435435
`LambdaOutputEncoder`.
436436

437437
3. Implements its `handle()` method by:
@@ -446,7 +446,7 @@ We provide conformances for Foundation’s `JSONDecoder` to `LambdaEventDecoder`
446446
the user.
447447

448448
```swift
449-
/// Wraps an underlying handler conforming to `CodableLambdaHandler`
449+
/// Wraps an underlying handler conforming to `LambdaHandler`
450450
/// with encoding/decoding logic
451451
public struct LambdaCodableAdapter<
452452
Handler: LambdaHandler,
@@ -486,16 +486,16 @@ To create a Lambda function using the current API, a user first has to create an
486486
handler protocols by implementing the initializer and the `handle(...)` function. Now that `LambdaRuntime` is public,
487487
this verbosity can very easily be simplified.
488488

489-
**ClosureHandler**
489+
#### ClosureHandler
490490

491491
This handler is generic over any `Event` type conforming to `Decodable` and any `Output` type conforming to `Encodable`
492492
or `Void`.
493493

494494
```swift
495495
public struct ClosureHandler<Event, Output>: LambdaHandler {
496-
/// Intialize with a closure handler over generic Input and Output types
496+
/// Initialize with a closure handler over generic Input and Output types
497497
public init(body: @escaping (Event, LambdaContext) async throws -> Output) where Output: Encoda
498-
/// Intialize with a closure handler over a generic Input type (Void Output).
498+
/// Initialize with a closure handler over a generic Input type (Void Output).
499499
public init(body: @escaping (Event, LambdaContext) async throws -> Void) where Output == Void
500500
/// The business logic of the Lambda function.
501501
public func handle(_ event: Event, context: LambdaContext) async throws -> Output
@@ -523,7 +523,7 @@ extension LambdaRuntime {
523523
}
524524
```
525525

526-
We can now significantly reduce the verbosity and leverage Swifts trailing closure syntax to cleanly create and run a
526+
We can now significantly reduce the verbosity and leverage Swift's trailing closure syntax to cleanly create and run a
527527
Lambda function, abstracting away the decoding and encoding logic from the user:
528528

529529
```swift
@@ -643,8 +643,8 @@ parameter has benefits as the lifetime of the handle function is tied to the inv
643643
returns a `LambdaResponse` splits the invocation into two separate function calls. First the handle method is invoked,
644644
second the `LambdaResponse` writer closure is invoked. This means that it is impossible to use Swift APIs that use
645645
`with` style lifecycle management patterns from before creating the response until sending the full response stream off.
646-
This means for example: That users instrumenting their lambdas with Swift tracing likely can not use the `withSpan` API
647-
for the full lifetime of the request, if they return a streamed response.
646+
For example, users instrumenting their lambdas with Swift tracing likely can not use the `withSpan` API for the full
647+
lifetime of the request, if they return a streamed response.
648648

649649
However, if it comes to consistency with the larger Swift on server ecosystem, the API that returns a `LambdaResponse`
650650
is likely the better choice. Hummingbird v2, OpenAPI and the new Swift gRPC v2 implementation all use this approach.
@@ -658,6 +658,6 @@ We welcome the discussion on this topic and are open to change our minds and API
658658
## A word about versioning
659659

660660
We are aware that AWS Lambda Runtime has not reached a proper 1.0. We intend to keep the current implementation around
661-
at 1.0-alpha. We dont want to change the current API without releasing a new major. We think there are lots of adopters
661+
at 1.0-alpha. We don't want to change the current API without releasing a new major. We think there are lots of adopters
662662
out there that depend on the API in v1. Because of this we intend to release the proposed API here as AWS Lambda Runtime
663663
v2.

0 commit comments

Comments
 (0)