Hi @willft,
thanks for your thoughtful feedback. Let me address your concerns:
We think it should look something like this (and we should likely make this explicit in the proposal):
// main.swift
import AWSLambdaRuntime
struct Hello: Decodable { var name: String }
struct Goodbye: Encodable { var name: String }
let runtime = LambdaRuntime { (event: Hello, context: LambdaContext) in
Goodbye(name: event.name)
}
try await runtime.run()
However this would not have any interruption handling (which is not needed when the Lambda runs at AWS anyway).
Do you think this would be easy enough?
I want to call out, that you don't have to use ServiceLifecycle with the LambdaRuntime. ServiceLifecycle makes sense for users that have dependencies that also need to be run or shutdown. But you can just call the required run() method from the Service protocol directly and everything will work fine (except for interruption handling in local debugging).
I'm not sure I agree here. See above. We need a run() method anyway. And we already have the implementation for it.
I think we should focus on integrating with the ecosystem here, why create a new spelling, if there already is a spelling that works and that the ecosystem has agreed on? Lambda should work in the same way Vapor and Hummingbird integrate with ServiceLifecycle instead of inventing its own approach.
This is an interesting view. One thing that I could see is something like this:
/// A protocol that vends a `main` function, that sets
/// up listening for interruptions and reports startup
/// errors if needed and then calls the provided run
/// method.
protocol LambdaRunner {
static func run() async throws
}
Potential usage:
@main
enum MyLambda: LambdaRunner {
struct Hello: Decodable { var name: String }
struct Goodbye: Encodable { var name: String }
// interruption handling and startup error reporting is automatically
// added for you in the enclosing main().
static func run() async throws {
let runtime = LambdaRuntime { (event: Hello, context: LambdaContext) in
Goodbye(name: event.name)
}
try await runtime.run()
}
}
@willft would this solve your concerns? Let us know what you think! Thanks!