-
Notifications
You must be signed in to change notification settings - Fork 114
[example] Add example for Swift Service Lifecycle #522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…-lambda-runtime into sebsto/servicelifecycle
2432ed3
to
018d9ce
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a comprehensive example demonstrating Swift Service Lifecycle integration with AWS Lambda and PostgreSQL RDS, along with minor fixes to Docker command references and local server implementation.
- Adds a complete ServiceLifecycle+Postgres example with AWS infrastructure setup
- Fixes Docker command references in format checking scripts
- Updates local server implementation to handle return values properly
Reviewed Changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
scripts/check-format-linux.sh | Fixed Docker command references from 'container' to 'docker' |
Sources/AWSLambdaRuntime/Lambda+LocalServer.swift | Updated return type handling and error management in local server |
Examples/Streaming/samconfig.toml | Added SAM configuration for streaming example |
Examples/ServiceLifecycle+Postgres/* | Complete new example with PostgreSQL integration, infrastructure templates, and documentation |
.licenseignore | Added .toml files to license ignore list |
.github/workflows/pull_request.yml | Added new example to CI workflow |
@@ -106,7 +106,7 @@ internal struct LambdaHTTPServer { | |||
eventLoopGroup: MultiThreadedEventLoopGroup = .singleton, | |||
logger: Logger, | |||
_ closure: sending @escaping () async throws -> Result | |||
) async throws -> Result { | |||
) async throws -> Swift.Result<Result, any Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return type change from Result
to Swift.Result<Result, any Error>
appears to be a breaking change that could affect API consumers. This should be carefully considered for backward compatibility.
) async throws -> Swift.Result<Result, any Error> { | |
) async throws -> Result { |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So when does this function throw an error and when does it return the error as a Result?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of interest what was causing the shutdown error, that you are ignoring now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So when does this function throw an error and when does it return the error as a Result?
when the user types CTRL-C to stop the server and the server is part of a service lifecycle group
Out of interest what was causing the shutdown error, that you are ignoring now
The reported error is Channel I/O
by an attempt to read/write on a closed channel.
I don't know the root cause.
Because this happens on the local server, just used for testing, and at the time of shutdown. I think it's sfe to ignore the error and let the app terminate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it not be better to make it clear what the issue is. Instead of returning a Result. Wrap the whole function in a
do {
contents of LambdaHTTPServer.withLocalServer
} catch is ChannelIOError /* whatever the error is */ {
// comment detailing issue, so it can be looked into later
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, done
@adam-fowler This is a new example. The rest is "just" a PostgreSQL + service lifecycle example. I provide a SAM template to setup the database in a secure way (private network, restrictive security groups, password stored in secret manager) |
@@ -106,7 +106,7 @@ internal struct LambdaHTTPServer { | |||
eventLoopGroup: MultiThreadedEventLoopGroup = .singleton, | |||
logger: Logger, | |||
_ closure: sending @escaping () async throws -> Result | |||
) async throws -> Result { | |||
) async throws -> Swift.Result<Result, any Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So when does this function throw an error and when does it return the error as a Result?
@@ -106,7 +106,7 @@ internal struct LambdaHTTPServer { | |||
eventLoopGroup: MultiThreadedEventLoopGroup = .singleton, | |||
logger: Logger, | |||
_ closure: sending @escaping () async throws -> Result | |||
) async throws -> Result { | |||
) async throws -> Swift.Result<Result, any Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of interest what was causing the shutdown error, that you are ignoring now
@adam-fowler Thank you for the initial review. I added |
Now that task cancellation works, re publishing this PR with a new example for Swift Service Lifecycle