aws-lambda-swift-sprinter icon indicating copy to clipboard operation
aws-lambda-swift-sprinter copied to clipboard

Runtime exited without providing a reason

Open mihirpmehta opened this issue 5 years ago • 6 comments

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):

  • OS: MacOS 10.14.4

mihirpmehta avatar Nov 27 '19 10:11 mihirpmehta

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 avatar Nov 27 '19 23:11 Andrea-Scuderi

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.

Andrea-Scuderi avatar Nov 27 '19 23:11 Andrea-Scuderi

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 avatar Nov 28 '19 05:11 mihirpmehta

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

mihirpmehta avatar Nov 28 '19 06:11 mihirpmehta

@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)

Andrea-Scuderi avatar Nov 28 '19 19:11 Andrea-Scuderi

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

mihirpmehta avatar Dec 02 '19 04:12 mihirpmehta