swift-aws-lambda-runtime
                                
                                 swift-aws-lambda-runtime copied to clipboard
                                
                                    swift-aws-lambda-runtime copied to clipboard
                            
                            
                            
                        Use primary associated type to reduce boilerplate
After SE-0346 lands in Swift 5.7, it’s possible for us to mark Event and Output as primary associate types for LambdaHandler. This can simplify a demo handler from:
@main
struct MyLambda: LambdaHandler {
    typealias Event = String
    typealias Output = String
    init(context: LambdaInitializationContext) async throws {
        // setup your resources that you want to reuse for every invocation here.
    }
    func handle(_ input: String, context: LambdaContext) async throws -> String {
        // as an example, respond with the input's reversed
        String(input.reversed())
    }
}
into
@main
struct MyLambda: LambdaHandler<String, String> {
    init(context: LambdaInitializationContext) async throws {
        // setup your resources that you want to reuse for every invocation here.
    }
    func handle(_ input: String, context: LambdaContext) async throws -> String {
        // as an example, respond with the input's reversed
        String(input.reversed())
    }
}
Note that the demo doesn’t work at the moment because parameterized protocol support is not fully implemented yet. It is valid and hopefully we could use it starting from 5.7.