Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Runtime exited without providing a reason #27

Open
mihirpmehta opened this issue Nov 27, 2019 · 6 comments
Open

Runtime exited without providing a reason #27

mihirpmehta opened this issue Nov 27, 2019 · 6 comments
Labels
documentation Improvements or additions to documentation

Comments

@mihirpmehta
Copy link

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
@Andrea-Scuderi
Copy link
Member

Andrea-Scuderi commented Nov 27, 2019

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
Copy link
Member

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
Copy link
Author

mihirpmehta commented Nov 28, 2019

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
Copy link
Author

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
Copy link
Member

@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
Copy link
Author

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

@Andrea-Scuderi Andrea-Scuderi added the documentation Improvements or additions to documentation label Dec 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants