Skip to content

Commit abef260

Browse files
authored
Merge branch 'main' into feature/packaging-plugin
2 parents ae938af + ac52960 commit abef260

File tree

9 files changed

+23
-55
lines changed

9 files changed

+23
-55
lines changed

.swiftformat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# file options
22

3-
--swiftversion 5.2
3+
--swiftversion 5.4
44
--exclude .build
55

66
# format options

Package.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ let package = Package(
3535
]),
3636
.plugin(
3737
name: "AWSLambdaPackager",
38-
capability: .command(intent: .custom(verb: "archive", description: "Archive the Lambda binary and prepare it for uploading to AWS. Requires docker on macOS."))
38+
capability: .command(
39+
intent: .custom(
40+
verb: "archive",
41+
description: "Archive the Lambda binary and prepare it for uploading to AWS. Requires docker on macOS."
42+
)
43+
)
3944
),
4045
.testTarget(name: "AWSLambdaRuntimeCoreTests", dependencies: [
4146
.byName(name: "AWSLambdaRuntimeCore"),

Sources/AWSLambdaRuntimeCore/LambdaContext.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public struct LambdaInitializationContext: _AWSLambdaSendable {
4343
/// `ByteBufferAllocator` to allocate `ByteBuffer`
4444
public let allocator: ByteBufferAllocator
4545

46-
/// `Terminator` to register shutdown operations
46+
/// ``LambdaTerminator`` to register shutdown operations
4747
public let terminator: LambdaTerminator
4848

4949
init(logger: Logger, eventLoop: EventLoop, allocator: ByteBufferAllocator, terminator: LambdaTerminator) {

Sources/AWSLambdaRuntimeCore/LambdaHandler.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public protocol EventLoopLambdaHandler: ByteBufferLambdaHandler {
119119
/// The `EventLoopFuture` should be completed with either a response of type `Output` or an `Error`
120120
func handle(_ event: Event, context: LambdaContext) -> EventLoopFuture<Output>
121121

122-
/// Encode a response of type `Output` to `ByteBuffer`
122+
/// Encode a response of type ``Output`` to `ByteBuffer`
123123
/// Concrete Lambda handlers implement this method to provide coding functionality.
124124
/// - parameters:
125125
/// - allocator: A `ByteBufferAllocator` to help allocate the `ByteBuffer`.
@@ -128,7 +128,7 @@ public protocol EventLoopLambdaHandler: ByteBufferLambdaHandler {
128128
/// - Returns: A `ByteBuffer` with the encoded version of the `value`.
129129
func encode(allocator: ByteBufferAllocator, value: Output) throws -> ByteBuffer?
130130

131-
/// Decode a`ByteBuffer` to a request or event of type `Event`
131+
/// Decode a `ByteBuffer` to a request or event of type ``Event``
132132
/// Concrete Lambda handlers implement this method to provide coding functionality.
133133
///
134134
/// - parameters:
@@ -139,7 +139,7 @@ public protocol EventLoopLambdaHandler: ByteBufferLambdaHandler {
139139
}
140140

141141
extension EventLoopLambdaHandler {
142-
/// Driver for `ByteBuffer` -> `Event` decoding and `Output` -> `ByteBuffer` encoding
142+
/// Driver for `ByteBuffer` -> ``Event`` decoding and ``Output`` -> `ByteBuffer` encoding
143143
@inlinable
144144
public func handle(_ event: ByteBuffer, context: LambdaContext) -> EventLoopFuture<ByteBuffer?> {
145145
let input: Event
@@ -169,7 +169,8 @@ extension EventLoopLambdaHandler where Output == Void {
169169

170170
// MARK: - ByteBufferLambdaHandler
171171

172-
/// An `EventLoopFuture` based processing protocol for a Lambda that takes a `ByteBuffer` and returns a `ByteBuffer?` asynchronously.
172+
/// An `EventLoopFuture` based processing protocol for a Lambda that takes a `ByteBuffer` and returns
173+
/// an optional `ByteBuffer` asynchronously.
173174
///
174175
/// - note: This is a low level protocol designed to power the higher level ``EventLoopLambdaHandler`` and
175176
/// ``LambdaHandler`` based APIs.

Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import NIOCore
1818

1919
/// `LambdaRuntime` manages the Lambda process lifecycle.
2020
///
21-
/// - note: It is intended to be used within a single `EventLoop`. For this reason this class is not thread safe.
21+
/// Use this API, if you build a higher level web framework which shall be able to run inside the Lambda environment.
2222
public final class LambdaRuntime<Handler: ByteBufferLambdaHandler> {
2323
private let eventLoop: EventLoop
2424
private let shutdownPromise: EventLoopPromise<Int>
@@ -35,9 +35,10 @@ public final class LambdaRuntime<Handler: ByteBufferLambdaHandler> {
3535
/// Create a new `LambdaRuntime`.
3636
///
3737
/// - parameters:
38+
/// - handlerType: The ``ByteBufferLambdaHandler`` type the `LambdaRuntime` shall create and manage
3839
/// - eventLoop: An `EventLoop` to run the Lambda on.
3940
/// - logger: A `Logger` to log the Lambda events.
40-
public convenience init(eventLoop: EventLoop, logger: Logger) {
41+
public convenience init(_ handlerType: Handler.Type, eventLoop: EventLoop, logger: Logger) {
4142
self.init(eventLoop: eventLoop, logger: logger, configuration: .init())
4243
}
4344

@@ -114,8 +115,7 @@ public final class LambdaRuntime<Handler: ByteBufferLambdaHandler> {
114115

115116
// MARK: - Private
116117

117-
#if DEBUG
118-
/// Begin the `LambdaRuntime` shutdown. Only needed for debugging purposes, hence behind a `DEBUG` flag.
118+
/// Begin the `LambdaRuntime` shutdown.
119119
public func shutdown() {
120120
// make this method thread safe by dispatching onto the eventloop
121121
self.eventLoop.execute {
@@ -126,7 +126,6 @@ public final class LambdaRuntime<Handler: ByteBufferLambdaHandler> {
126126
}
127127
}
128128
}
129-
#endif
130129

131130
private func markShutdown() {
132131
self.state = .shutdown

Tests/AWSLambdaRuntimeCoreTests/LambdaRuntimeTest.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class LambdaRuntimeTest: XCTestCase {
2929

3030
let eventLoop = eventLoopGroup.next()
3131
let logger = Logger(label: "TestLogger")
32-
let runtime = LambdaRuntime<StartupErrorHandler>(eventLoop: eventLoop, logger: logger)
32+
let runtime = LambdaRuntime(StartupErrorHandler.self, eventLoop: eventLoop, logger: logger)
3333

3434
// eventLoop.submit in this case returns an EventLoopFuture<EventLoopFuture<ByteBufferHandler>>
3535
// which is why we need `wait().wait()`
@@ -51,7 +51,7 @@ class LambdaRuntimeTest: XCTestCase {
5151

5252
let eventLoop = eventLoopGroup.next()
5353
let logger = Logger(label: "TestLogger")
54-
let runtime = LambdaRuntime<EchoHandler>(eventLoop: eventLoop, logger: logger)
54+
let runtime = LambdaRuntime(EchoHandler.self, eventLoop: eventLoop, logger: logger)
5555

5656
XCTAssertNoThrow(_ = try eventLoop.flatSubmit { runtime.start() }.wait())
5757
XCTAssertThrowsError(_ = try runtime.shutdownFuture.wait()) {
@@ -101,7 +101,7 @@ class LambdaRuntimeTest: XCTestCase {
101101

102102
let eventLoop = eventLoopGroup.next()
103103
let logger = Logger(label: "TestLogger")
104-
let runtime = LambdaRuntime<ShutdownErrorHandler>(eventLoop: eventLoop, logger: logger)
104+
let runtime = LambdaRuntime(ShutdownErrorHandler.self, eventLoop: eventLoop, logger: logger)
105105

106106
XCTAssertNoThrow(try eventLoop.flatSubmit { runtime.start() }.wait())
107107
XCTAssertThrowsError(try runtime.shutdownFuture.wait()) { error in

docker/Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
ARG swift_version=5.2
2-
# FIXME when 5.2 images are available
1+
ARG swift_version=5.4
32
ARG base_image=swift:$swift_version-amazonlinux2
43
FROM $base_image
54
# needed to do again after FROM due to docker limitation

docker/Dockerfile.ubuntu

Lines changed: 0 additions & 36 deletions
This file was deleted.

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ If you have never used AWS Lambda or Docker before, check out this [getting star
1717
First, create a SwiftPM project and pull Swift AWS Lambda Runtime as dependency into your project
1818

1919
```swift
20-
// swift-tools-version:5.2
20+
// swift-tools-version:5.6
2121

2222
import PackageDescription
2323

@@ -80,7 +80,7 @@ Next, create a `main.swift` and implement your Lambda.
8080
First, add a dependency on the event packages:
8181

8282
```swift
83-
// swift-tools-version:5.2
83+
// swift-tools-version:5.6
8484

8585
import PackageDescription
8686

0 commit comments

Comments
 (0)