Last active
January 19, 2021 15:50
-
-
Save sofianhamiti/25787e290ace484831e88ad92bd9def3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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