You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: readme.md
+42-1Lines changed: 42 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -384,7 +384,48 @@ try await runtime.run()
384
384
385
385
### Integration with Swift Service LifeCycle
386
386
387
-
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
+
importAWSLambdaRuntime
393
+
importServiceLifecycle
394
+
importPostgresNIO
395
+
396
+
@main
397
+
structLambdaFunction {
398
+
privatefuncstart() asyncthrows {
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
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.
0 commit comments