mdneuzerling / lambdr

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

as_stringified_json #17

Closed dwbelliston closed 2 years ago

dwbelliston commented 2 years ago

Just testing trying to get this to work with API gateway, I see in the readme a reference to this function: as_stringified_json

So i have add it in to the runtime.R file

parity <- function(number) {
    print(">>> in parity1")

    result <- list(parity = if (as.integer(number) %% 2 == 0) "even" else "odd")

    print(">>> in parity2")

    as_stringified_json(
    list(
        isBase64Encoded = FALSE,
        statusCode = 200L,
        body = as_stringified_json(result)
    )
)

}

lambdr::start_lambda()

I receive an error in lambda logs:

ERROR [2022-05-28 15:56:22] could not find function "as_stringified_json"

How am I suppose to include this?

Thanks!

dwbelliston commented 2 years ago

Oh, new to R. Forgot the import library(lambdr)

New file is

library(lambdr)

parity <- function(number) {
    print(">>> in parity1")

    result <- list(parity = if (as.integer(number) %% 2 == 0) "even" else "odd")

    print(">>> in parity2")

    as_stringified_json(
    list(
        isBase64Encoded = FALSE,
        statusCode = 200L,
        body = as_stringified_json(result)
    )
)

}

lambdr::start_lambda()
mdneuzerling commented 2 years ago

Awesome! I'm glad you could get it working, and I hope that the package is useful.