Skip to content

Instantly share code, notes, and snippets.

@sofianhamiti
Last active January 19, 2021 15:50
Show Gist options
  • Save sofianhamiti/25787e290ace484831e88ad92bd9def3 to your computer and use it in GitHub Desktop.
Save sofianhamiti/25787e290ace484831e88ad92bd9def3 to your computer and use it in GitHub Desktop.
library(randomForest)
library(jsonlite)
# download model file from S3 into /tmp folder
system("aws s3 cp ${S3_MODEL_URI} /tmp/model.rds")
handler <- function(body, ...) {
data <- fromJSON(txt = body)
# load model
model <- readRDS("/tmp/model.rds")
# predict with loaded model
predictions <- predict(model, newdata = data)
# return response with predictions payload
return(
list(
statusCode = 200,
headers = list("Content-Type" = "application/json"),
body = toJSON(list(predictions = predictions))
)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment