Skip to content

Commit 19b8ff1

Browse files
author
Sebastien Stormacq
committed
Merge branch 'main' into sebsto/new-plugins
2 parents 728150c + 1b3c81c commit 19b8ff1

File tree

1 file changed

+50
-7
lines changed

1 file changed

+50
-7
lines changed

readme.md

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ You can read [the Swift AWS Lambda Runtime documentation](https://swiftpackagein
66
This guide contains the following sections:
77

88
- [The Swift AWS Lambda Runtime](#the-swift-aws-lambda-runtime)
9-
- [Pre-requisites](#pre-requisites)
9+
- [Prerequisites](#prerequisites)
1010
- [Getting started](#getting-started)
1111
- [Developing your Swift Lambda functions](#developing-your-swift-lambda-functions)
1212
- [Testing Locally](#testing-locally)
1313
- [Deploying your Swift Lambda functions](#deploying-your-swift-lambda-functions)
1414
- [Swift AWS Lambda Runtime - Design Principles](#swift-aws-lambda-runtime---design-principles)
1515

16-
The Swift runtime client is an experimental package. It is subject to change and intended only for evaluation purposes.
16+
The Swift runtime client is [incubating as part of the Swift Server Workgroup incubation process](https://www.swift.org/sswg/incubated-packages.html). It is an experimental package, subject to change, and intended only for evaluation purposes.
17+
18+
Open [issues on GitHub for support requests](https://github.com/awslabs/swift-aws-lambda-runtime/issues).
1719

1820
## The Swift AWS Lambda Runtime
1921

@@ -27,7 +29,7 @@ Combine this with Swift's developer friendliness, expressiveness, and emphasis o
2729

2830
Swift AWS Lambda Runtime was designed to make building Lambda functions in Swift simple and safe. The library is an implementation of the [AWS Lambda Runtime API](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html) and uses an embedded asynchronous HTTP Client based on [SwiftNIO](http://github.com/apple/swift-nio) that is fine-tuned for performance in the AWS Runtime context. The library provides a multi-tier API that allows building a range of Lambda functions: From quick and simple closures to complex, performance-sensitive event handlers.
2931

30-
## Pre-requisites
32+
## Prerequisites
3133

3234
- Ensure you have the Swift 6.x toolchain installed. You can [install Swift toolchains](https://www.swift.org/install/macos/) from Swift.org
3335

@@ -378,11 +380,52 @@ let runtime = LambdaRuntime {
378380
try await runtime.run()
379381
```
380382

381-
You can learn how to deploy and invoke this function in [the API Gateway example README file](Examples/APIGateway/README.md).
383+
You can learn how to deploy and invoke this function in [the API Gateway example README file](Examples/APIGatewayV2/README.md).
382384

383385
### Integration with Swift Service LifeCycle
384386

385-
Support for [Swift Service Lifecycle](https://github.com/swift-server/swift-service-lifecycle) is currently being implemented. You can follow https://github.com/awslabs/swift-aws-lambda-runtime/issues/374 for more details and the current status. Your contributions are welcome.
387+
The Swift AWS Lambda Runtime provides built-in support for [Swift Service Lifecycle](https://github.com/swift-server/swift-service-lifecycle), allowing you to manage the lifecycle of your Lambda runtime alongside other services like database clients, HTTP clients, or any other resources that need proper initialization and cleanup.
388+
389+
Here's how to integrate your Lambda function with ServiceLifecycle to manage multiple services:
390+
391+
```swift
392+
import AWSLambdaRuntime
393+
import ServiceLifecycle
394+
import PostgresNIO
395+
396+
@main
397+
struct LambdaFunction {
398+
private func start() async throws {
399+
// Create a database client
400+
let pgClient = PostgresClient(configuration: /* your config */)
401+
402+
// Create the Lambda runtime
403+
let lambdaRuntime = LambdaRuntime(body: self.handler)
404+
405+
// Use ServiceLifecycle to manage both the database client and Lambda runtime
406+
let serviceGroup = ServiceGroup(
407+
services: [pgClient, lambdaRuntime],
408+
gracefulShutdownSignals: [.sigterm],
409+
cancellationSignals: [.sigint],
410+
logger: self.logger
411+
)
412+
413+
// Start all services - this will handle initialization and cleanup
414+
try await serviceGroup.run()
415+
}
416+
417+
private func handler(event: String, context: LambdaContext) async throws -> String {
418+
// Your Lambda function logic here
419+
return "Hello, World!"
420+
}
421+
422+
static func main() async throws {
423+
try await LambdaFunction().start()
424+
}
425+
}
426+
```
427+
428+
You can see a complete working example in the [ServiceLifecycle+Postgres example](Examples/ServiceLifecycle+Postgres/README.md), which demonstrates how to manage a PostgreSQL client alongside the Lambda runtime using ServiceLifecycle.
386429

387430
### Use Lambda Background Tasks
388431

@@ -530,9 +573,9 @@ Please refer to [the full deployment guide available in the documentation](https
530573

531574
## Swift AWS Lambda Runtime - Design Principles
532575

533-
The [design document](Sources/AWSLambdaRuntime/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.
576+
The [design document](Sources/AWSLambdaRuntime/Docs.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.
534577

535-
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/AWSLambdaRuntime/Documentation.docc/Proposals/0001-v2-api.md).
578+
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/AWSLambdaRuntime/Docs.docc/Proposals/0001-v2-api.md).
536579

537580
### Key Design Principles
538581

0 commit comments

Comments
 (0)