Skip to content

A R package to build lambda functions on custom R runtime image

License

Notifications You must be signed in to change notification settings

p2xcode/lambdar

Repository files navigation

r2lambda

R-CMD-check Codecov test coverage

The goal of {r2lambda} is to make it easier to go from an R script to a deployed AWS Lambda function.

Requirements

  • docker is required to build, tag, and push the image.

Installation

You can install the development version of {r2lambda} like so:

# install_packages("remotes")
remotes::install_github("discindo/r2lambda")

Setup

r2lambda assumes environmental variables for connecting to AWS services are available in the R session. This is typically done via an .Renviron file that should include:

ACCESS_KEY_ID = "YOUR AWS ACCESS KEY ID"
SECRET_ACCESS_KEY = "YOUR AWS SECRET ACCESS KEY"
PROFILE = "YOUR AWS PROFILE"
REGION = "YOUR AWS REGION"

Workflow

Build a docker image for the lambda function

runtime_function <- "parity"
runtime_path <- system.file("parity.R", package = "r2lambda")
dependencies <- NULL

# Might take a while, its building a docker image
build_lambda(
 tag = "parity1",
 runtime_function = runtime_function,
 runtime_path = runtime_path,
 dependencies = dependencies
 )

Test the lambda docker image locally

payload <- list(number = 2)
tag <- "parity1"
test_lambda(tag = "parity1", payload)

Deploy to AWS Lambda

# Might take a while, its pushing it to a remote repository
deploy_lambda(tag = "parity1")

Invoke deployed lambda

invoke_lambda(
  function_name = "parity1",
  invocation_type = "RequestResponse",
  payload = list(number = 2),
  include_logs = FALSE
)

#> Lambda response payload: 
#> {"parity":"even"}

Code of Conduct

Please note that the r2lambda project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

About

A R package to build lambda functions on custom R runtime image

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages