mdneuzerling / lambdr

Run R containers on AWS Lambda
https://lambdr.mdneuzerling.com
Other
131 stars 12 forks source link

Error when run your example #14

Open manhcuogntin4 opened 2 years ago

manhcuogntin4 commented 2 years ago

Hi,

I want to use your Dockerfile to test a function in R in AWS but when I run your example, I got this error.

{"errorMessage":"functions.parity, as defined by the _HANDLER environment\nvariable, can't be found. Check that this exists in theenvironment passed to lambda_config (defaults to the parent\nframe)","errorType":"simpleError","stackTrace":[]}(base). Do you have any idea about this error. Thanks !

Here is the log of docker run: docker run -p 9000:8080 mdneuzerling/r-on-lambda "functions.parity" 17 Mar 2022 10:57:45,986 [INFO] (rapid) exec '/var/runtime/bootstrap' (cwd=/var/task, handler=) 17 Mar 2022 10:59:14,320 [INFO] (rapid) extensionsDisabledByLayer(/opt/disable-extensions-jwigqn8j) -> stat /opt/disable-extensions-jwigqn8j: no such file or directory 17 Mar 2022 10:59:14,320 [WARNING] (rapid) Cannot list external agents error=open /opt/extensions: no such file or directory START RequestId: 5cb0f711-ea7f-460d-84c7-76da1f95a945 Version: $LATEST INFO [2022-03-17 10:59:14] Using handler function ERROR [2022-03-17 10:59:14] functions.parity, as defined by the _HANDLER environment variable, can't be found. Check that this exists in theenvironment passed to lambda_config (defaults to the parent frame) Error in get_handler_function_from_env_var(environ = environ) : functions.parity, as defined by the _HANDLER environment variable, can't be found. Check that this exists in theenvironment passed to lambda_config (defaults to the parent frame) Calls: ... tryCatch -> tryCatchList -> tryCatchOne -> Execution halted 17 Mar 2022 10:59:14,572 [WARNING] (rapid) First fatal error stored in appctx: Runtime.ExitError 17 Mar 2022 10:59:14,572 [WARNING] (rapid) Process 16(bootstrap) exited: Runtime exited with error: exit status 1 17 Mar 2022 10:59:14,572 [ERROR] (rapid) Init failed error=Runtime exited with error: exit status 1 InvokeID= 17 Mar 2022 10:59:14,572 [WARNING] (rapid) Reset initiated: ReserveFail 17 Mar 2022 10:59:14,573 [WARNING] (rapid) Cannot list external agents error=open /opt/extensions: no such file or directory INFO [2022-03-17 10:59:14] Using handler function ERROR [2022-03-17 10:59:14] functions.parity, as defined by the _HANDLER environment variable, can't be found. Check that this exists in theenvironment passed to lambda_config (defaults to the parent frame) Error in get_handler_function_from_env_var(environ = environ) : functions.parity, as defined by the _HANDLER environment variable, can't be found. Check that this exists in theenvironment passed to lambda_config (defaults to the parent frame) Calls: ... tryCatch -> tryCatchList -> tryCatchOne -> Execution halted END RequestId: f01d2f2a-29f7-45ea-b730-1607fc191124 REPORT RequestId: f01d2f2a-29f7-45ea-b730-1607fc191124 Init Duration: 0.30 ms Duration: 509.73 ms Billed Duration: 510 ms Memory Size: 3008 MB Max Memory Used: 3008 MB
17 Mar 2022 10:59:14,830 [WARNING] (rapid) First fatal error stored in appctx: Runtime.ExitError 17 Mar 2022 10:59:14,830 [WARNING] (rapid) Process 42(bootstrap) exited: Runtime exited with error: exit status 1

mdneuzerling commented 2 years ago

Hi @manhcuogntin4. The handler should name the function that is going to be used. It's defined in one of two places:

It looks like you've set the handler to functions.parity. An old blog post of mine (the r-on-lambda post) used this structure, so it's possible that you're using an outdated example from before this package existed. If you've gotten this example code from something related to lambdr please let me know so I can delete it.

Try following the example in the vignette.

manhcuogntin4 commented 2 years ago

@mdneuzerling Thank for your help. I have other problem, I changed your code to load my dateset and my function. The lambda return error but It is not clear the clause. Can you see it for me. Thank.

proxies <- function(one_client) { chemin <- "/lambda/" source(paste0(chemin,"packages.R")) source(paste0(chemin,"fonctions.R")) load(paste0(chemin,"/Data/dataset")) targetvars <- c("a", "b", "c", "d")

list(proxies = targetvars) }

lambdr::start_lambda()

Here is the output of lambda. In the cloudwatch, There is any information about the error. The packages.R is the library we used and the fonctions.R is the functions. My program works well in local.

{ "StatusCode": 200, "FunctionError": "Unhandled", "ExecutedVersion": "$LATEST" }

Thank  

mdneuzerling commented 2 years ago

Hi @manhcuogntin4, sorry I missed your update. One thing I need to do here for this package is to add a vignette for trouble-shooting Lambdas. I think it would help in your case to better understand what is failing and where.

For this I would recommend putting some logging entries into your code. The lambdr package uses the logger package for logging. You can log entries like so:

logger::log_info("This is what's happening right now")

You can also enable lambdr's internal logging by setting the log threshold to DEBUG before running start_lambda:

logger::log_threshold(logger::DEBUG)

All log entries will show up in Cloudwatch automatically.