Skip to content

Commit 6351471

Browse files
authored
Merge branch 'main' into sebsto/backgroundtasks
2 parents c7ac7d2 + 9f8880b commit 6351471

File tree

4 files changed

+37
-33
lines changed

4 files changed

+37
-33
lines changed

.github/workflows/pull_request.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ jobs:
4747
# https://github.com/swiftlang/github-workflows/issues/34
4848
musl:
4949
runs-on: ubuntu-latest
50-
container: swift:6.0-noble
50+
container: swift:6.0.2-noble
5151
timeout-minutes: 30
5252
steps:
5353
- name: Check out code
5454
uses: actions/checkout@v4
5555
- name: Install SDK
56-
run: swift sdk install https://download.swift.org/swift-6.0.1-release/static-sdk/swift-6.0.1-RELEASE/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz --checksum d4f46ba40e11e697387468e18987ee622908bc350310d8af54eb5e17c2ff5481
56+
run: swift sdk install https://download.swift.org/swift-6.0.2-release/static-sdk/swift-6.0.2-RELEASE/swift-6.0.2-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz --checksum aa5515476a403797223fc2aad4ca0c3bf83995d5427fb297cab1d93c68cee075
5757
- name: Build
5858
run: swift build --swift-sdk x86_64-swift-linux-musl

Sources/AWSLambdaRuntime/Docs.docc/index.md

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Swift AWS Lambda Runtime was designed to make building Lambda functions in Swift
1616

1717
## Getting started
1818

19-
If you have never used AWS Lambda or Docker before, check out this [getting started guide](https://fabianfett.de/getting-started-with-swift-aws-lambda-runtime) which helps you with every step from zero to a running Lambda.
19+
If you have never used AWS Lambda or Docker before, check out this [getting started guide](https://swiftpackageindex.com/swift-server/swift-aws-lambda-runtime/1.0.0-alpha.3/tutorials/table-of-content) which helps you with every step from zero to a running Lambda.
2020

2121
First, create a SwiftPM project and pull Swift AWS Lambda Runtime as dependency into your project
2222

@@ -120,32 +120,6 @@ First, add a dependency on the event packages:
120120

121121
Modeling Lambda functions as Closures is both simple and safe. Swift AWS Lambda Runtime will ensure that the user-provided code is offloaded from the network processing thread such that even if the code becomes slow to respond or gets stuck, the underlying process can continue to function. This safety comes at a small performance penalty from context switching between threads. In many cases, the simplicity and safety of using the Closure based API is often preferred over the complexity of the performance-oriented API.
122122

123-
### Using EventLoopLambdaHandler
124-
125-
Performance sensitive Lambda functions may choose to use a more complex API which allows user code to run on the same thread as the networking handlers. Swift AWS Lambda Runtime uses [SwiftNIO](https://github.com/apple/swift-nio) as its underlying networking engine which means the APIs are based on [SwiftNIO](https://github.com/apple/swift-nio) concurrency primitives like the `EventLoop` and `EventLoopFuture`. For example:
126-
127-
```swift
128-
// Import the modules
129-
import AWSLambdaRuntime
130-
import AWSLambdaEvents
131-
import NIO
132-
133-
// Our Lambda handler, conforms to EventLoopLambdaHandler
134-
struct Handler: EventLoopLambdaHandler {
135-
typealias In = SNS.Message // Request type
136-
typealias Out = Void // Response type
137-
138-
// In this example we are receiving an SNS Message, with no response (Void).
139-
func handle(context: Lambda.Context, event: In) -> EventLoopFuture<Out> {
140-
...
141-
context.eventLoop.makeSucceededFuture(Void())
142-
}
143-
}
144-
145-
Lambda.run(Handler())
146-
```
147-
148-
Beyond the small cognitive complexity of using the `EventLoopFuture` based APIs, note these APIs should be used with extra care. An [`EventLoopLambdaHandler`][ellh] will execute the user code on the same `EventLoop` (thread) as the library, making processing faster but requiring the user code to never call blocking APIs as it might prevent the underlying process from functioning.
149123

150124
## Deploying to AWS Lambda
151125

Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ public final class LambdaRuntime<Handler>: @unchecked Sendable where Handler: St
3333
) {
3434
self.handlerMutex = NIOLockedValueBox(handler)
3535
self.eventLoop = eventLoop
36+
37+
// by setting the log level here, we understand it can not be changed dynamically at runtime
38+
// developers have to wait for AWS Lambda to dispose and recreate a runtime environment to pickup a change
39+
// this approach is less flexible but more performant than reading the value of the environment variable at each invocation
40+
var log = logger
41+
log.logLevel = Lambda.env("LOG_LEVEL").flatMap(Logger.Level.init) ?? .info
3642
self.logger = logger
3743
}
3844

readme.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ This should print
128128
"dlroW olleH"
129129
```
130130
131+
## Tutorial
132+
133+
[The Swift AWS Lambda Runtime docc tutorial](https://swiftpackageindex.com/swift-server/swift-aws-lambda-runtime/1.0.0-alpha.3/tutorials/table-of-content) provides developers with detailed step-by-step instructions to develop, build, and deploy a Lambda function.
134+
131135
## Swift AWS Lambda Runtime
132136
133137
Many modern systems have client components like iOS, macOS or watchOS applications as well as server components that those clients interact with. Serverless functions are often the easiest and most efficient way for client application developers to extend their applications into the cloud.
@@ -142,15 +146,35 @@ Swift AWS Lambda Runtime was designed to make building Lambda functions in Swift
142146
143147
## Design Principles
144148
145-
tbd + reference to the `v2-api.md` design doc.
149+
The [design document](Sources/AWSLambdaRuntimeCore/Documentation.docc/Proposals/0001-v2-api.md) details the v2 API proposal for the swift-aws-lambda-runtime library, which aims to enhance the developer experience for building serverless functions in Swift.
146150
147-
## Tutorial
151+
The proposal has been reviewed and [incorporated feedback from the community](https://forums.swift.org/t/aws-lambda-v2-api-proposal/73819). The full v2 API design document is available [in this repository](Sources/AWSLambdaRuntimeCore/Documentation.docc/Proposals/0001-v2-api.md).
152+
153+
### Key Design Principles
154+
155+
The v2 API prioritizes the following principles:
156+
157+
- Readability and Maintainability: Extensive use of `async`/`await` improves code clarity and simplifies maintenance.
158+
159+
- Developer Control: Developers own the `main()` function and have the flexibility to inject dependencies into the `LambdaRuntime`. This allows you to manage service lifecycles efficiently using [Swift Service Lifecycle](https://github.com/swift-server/swift-service-lifecycle) for structured concurrency.
148160
149-
link to [updated docc tutorial](https://swiftpackageindex.com/swift-server/swift-aws-lambda-runtime/1.0.0-alpha.3/tutorials/table-of-content)
161+
- Simplified Codable Support: The `LambdaCodableAdapter` struct eliminates the need for verbose boilerplate code when encoding and decoding events and responses.
162+
163+
### New Capabilities
164+
165+
The v2 API introduces two new features:
166+
167+
[Response Streaming](https://aws.amazon.com/blogs/compute/introducing-aws-lambda-response-streaming/]): This functionality is ideal for handling large responses that need to be sent incrementally.  
168+
169+
[Background Work](https://aws.amazon.com/blogs/compute/running-code-after-returning-a-response-from-an-aws-lambda-function/): Schedule tasks to run after returning a response to the AWS Lambda control plane.
170+
171+
These new capabilities provide greater flexibility and control when building serverless functions in Swift with the swift-aws-lambda-runtime library.
150172
151173
## AWSLambdaRuntime API
152174
153-
tbd
175+
### Receive and respond with JSON objects
176+
177+
tbd + link to docc
154178
155179
### Lambda Streaming Response
156180

0 commit comments

Comments
 (0)