swift-serverless / aws-lambda-swift-sprinter

AWS Lambda Custom Runtime for Swift with swift-nio 2.0 support
Apache License 2.0
69 stars 6 forks source link

Runtime exited without providing a reason #27

Open mihirpmehta opened 4 years ago

mihirpmehta commented 4 years ago

Describe the bug While sample code of syncLambda runs properly. Sample code for asyncLambda: AsyncCodableLambda throws following error

aws lambda invoke --function-name HelloWorld --profile default --payload "fileb://Examples/HelloWorld/event.json" ./.build/tmp/outfile && echo "\nResult:" && cat ./.build/tmp/outfile && echo "\n" { "FunctionError": "Unhandled", "ExecutedVersion": "$LATEST", "StatusCode": 200 }

Result: {"errorType":"Runtime.ExitError","errorMessage":"RequestId: 3278a4df-68cb-45d0-afe9-8870a675dae5 Error: Runtime exited without providing a reason"}

To Reproduce Steps to reproduce the behavior: Clone this repository and change following line

//    sprinter.register(handler: "helloWorld", lambda: syncLambda)
//    sprinter.register(handler: "helloWorld2", lambda: syncDictLambda)
//    sprinter.register(handler: "helloWorld3", lambda: asyncLambda)
    sprinter.register(handler: "helloWorld4", lambda: asyncDictLambda)

Inside Example/HelloWorld/Sources/HelloWorld/Main.swift

Follow all the steps to make docker build, layer, lambda from terminal Run make invoke_lambda Expected behavior Sample code given in asyncDictLambda: AsyncDictionaryLambda or asyncLambda: AsyncCodableLambda should run without any error

Desktop (please complete the following information):

Andrea-Scuderi commented 4 years ago

To troubleshoot your code I suggest to use the function log() as implemented in HelloWorld.

Unhandled - The runtime didn't handle the error. For example, the function ran out of memory or timed out.

Andrea-Scuderi commented 4 years ago

For AsyncCodableLambda you need to call the completion handler. Can you provide the code?

Are you sure the db is reachable from the AWS Lambda? You need to be sure that the Postgres library you are using is based on SwiftNIO 2.0.

mihirpmehta commented 4 years ago

Hi,

I am using HellowWorld Example's sample code only for AsyncLambda ... Just one line of change in main.swift

sprinter.register(handler: "helloWorld4", lambda: asyncDictLambda) uncommented above line and commented syncLambda line

And yes it calls completionHandler inside it.

This is the code

let asyncLambda: AsyncCodableLambda<Event, Response> = { event, _, completion in
    let message = "Hello World! Hello \(event.name)!"
    return completion(.success(Response(message: message)))
}
let asyncDictLambda: AsyncDictionaryLambda = { dictionary, _, completion in
    var result = [String: Any]()
    if let name = dictionary["name"] as? String {
        let message = "Hello World! Hello \(name)!"
        result["message"] = message
    } else {
        completion(.failure(MyLambdaError.invalidEvent))
    }
    completion(.success(result))
}

returns exact same error message

Thanks

mihirpmehta commented 4 years ago

just to clarify any confusion. It has nothing to do with Database connection or anything. It's the default code that is given in the main.swift file for asyncLambda i am referring to.

Thanks

Andrea-Scuderi commented 4 years ago

@mihirpmehta Have you registered the Handler HelloWorld.helloWorld4 ? If not you can just reuse the one you have registered: sprinter.register(handler: "helloWorld", lambda: asyncDictLambda)

mihirpmehta commented 4 years ago

Oh. I miss it. I didn't change it in makefile. Thanks a ton