Announcing Swift AWS Lambda Runtime

This may not be an issue specific to this project, but I am seeing some odd behavior. I was just playing around with the square number example and I have this code that does not compile

Lambda.run { (context: Lambda.Context, input: Input, callback) in
    context.logger.info("input is \(input.number)")
    callback(.success(Output(result: input.number * input.number)))
}

with an error on the callback line of

Cannot convert value of type 'Output' to expected argument type 'Void'

however if I add a type hint, it works just fine

Lambda.run { (context: Lambda.Context, input: Input, callback: (Result<Output, Error>) -> Void) in
    context.logger.info("input is \(input.number)")
    callback(.success(Output(result: input.number * input.number)))
}

Is this just bad type inference on the swift compiler, or is there an issue with the library? I dug into the code and it seems like it's just swift choosing the Void callback vs the Out callback, but I can't see why it would make that choice. Also of note, the non type-hinted version works just fine without the logging line. (as below with the line commented out)

Lambda.run { (context: Lambda.Context, input: Input, callback) in
    //context.logger.info("input is \(input.number)")
    callback(.success(Output(result: input.number * input.number)))
}

Thanks for reporting @brendankirchner! There's a ticket about this you may want to follow here: Lambda.run cannot be used without explicit types ยท Issue #107 ยท swift-server/swift-aws-lambda-runtime ยท GitHub

1 Like

Hi Chris,

I just posted a couple of blog posts related to the swift aws lambda runtime. The second one details using it with AWS SDK Swift.

Messing with Swift AWS Lambda Runtime (Part 1) - Optical Aberration and Messing with Swift AWS Lambda Runtime (Part 2) - Optical Aberration

3 Likes

Awesome. Thank you Adam!

Great source of information. I need to try to port my examples written for the managed version of Apache OpenWhisk project with Swift that I described here in Serverless Swift book by Apress https://www.apress.com/us/book/9781484258354 . I will let you know about porting my examples to Swift Lambda :-9