Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
Package: r2lambda
Type: Package
Title: Deploy R Scripts as AWS Lambda Functions
Title: Deploy 'R' Scripts as 'AWS Lambda' Functions
Version: 0.1.0
Authors@R: c(
person("Teofil", "Nakov", , "teofiln@gmail.com", role = "aut",
comment = c(ORCID = "0009-0000-9589-5748")),
person("Novica", "Nakov", , "nnovica@gmail.com", role = c("aut", "cre"),
comment = c(ORCID = "0009-0005-7773-7718"))
comment = c(ORCID = "0009-0005-7773-7718")),
person("Discindo", role = "cph")
)
Description: Build, test and deploy R scripts as 'AWS Lambda' functions
packaged in 'Docker' container images. Wraps functionality from the
'paws' and 'lambdr' packages.
Description: Build, test and deploy 'R' scripts as Amazon Web Services
('AWS') 'Lambda' functions packaged in 'Docker' container images.
Images are built and tested locally, pushed to the 'AWS' Elastic
Container Registry, and deployed with an execution role; deployed
functions can be invoked, scheduled and deleted from 'R'. Wraps
functionality from the 'paws' and 'lambdr' packages.
License: GPL (>= 3)
Encoding: UTF-8
Imports:
Expand Down
29 changes: 27 additions & 2 deletions R/lambda-deploy.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
#' packages, not both. By default, both are `NULL`, so the Docker image will
#' have no additional packages installed.
#'
#' @return None, called for its side effect of building a local Docker image.
#'
#' @examples
#' \dontrun{
#' build_lambda(
#' tag = "parity1",
#' runtime_function = "parity",
#' runtime_path = system.file("parity.R", package = "r2lambda")
#' )
#' }
#' @importFrom glue glue glue_collapse single_quote double_quote
#' @export
build_lambda <- function(
Expand Down Expand Up @@ -92,6 +102,7 @@ build_lambda <- function(
)

logger::log_success("[build_lambda] Done.")
invisible(NULL)
}

#' test a lambda locally
Expand All @@ -100,6 +111,10 @@ build_lambda <- function(
#' (see `build_lambda`)
#' @param payload Named list. Arguments to lambda function.
#'
#' @return Invisibly, the result of [sys::exec_internal()] for the `curl` call
#' to the local container: a list with `status`, and `stdout` and `stderr` as
#' raw vectors. The response is also printed.
#'
#' @examples
#' \dontrun{
#' payload <- list(number = 2)
Expand Down Expand Up @@ -171,6 +186,9 @@ test_lambda <- function(tag, payload) {
#' example `Timeout`, `MemorySize` or `Environment`. `Architectures` is set
#' from the image's architecture.
#'
#' @return Invisibly, a list with `ECR_image_uri`, `IAM_lambda_role_arn` and
#' `Lambda_function_arn`.
#'
#' @examples
#' \dontrun{
#'
Expand Down Expand Up @@ -315,6 +333,9 @@ deploy_lambda <-
#' or ‘Event’ see `?paws.compute::lambda_invoke`
#' @param payload A named list internally converted to json
#' @param include_logs logical, whether to show the lambda logs (default: FALSE)
#' @return Invisibly, the response of `paws::lambda()$invoke()`, a list with
#' elements such as `StatusCode` and `Payload` (a raw vector). The payload is
#' also printed.
#' @examples
#' \dontrun{
#' invoke_lambda(
Expand Down Expand Up @@ -377,10 +398,13 @@ invoke_lambda <-
#' `rate` or `cron` specification. For details see the official documentation:
#' https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-rule-schedule.html
#'
#' @return None, called for its side effect of creating the schedule.
#'
#' @examples
#' \dontrun{
#' # Make Tidytuesday lambda fetch the Tidytuesday dataset every wednesday
#' at 8 am schedule_lambda("Tidytuesday3", "cron(0 8 * * Wed)")
#' # Make Tidytuesday lambda fetch the Tidytuesday dataset every Wednesday
#' # at 8 am
#' schedule_lambda("Tidytuesday3", "cron(0 8 * * Wed)")
#' }
#'
#' @export
Expand Down Expand Up @@ -465,6 +489,7 @@ schedule_lambda <- function(lambda_function, execution_rate) {
)

logger::log_info("[schedule_lambda] Done.")
invisible(NULL)
}

#' Delete a Lambda function and the AWS resources created for it
Expand Down
2 changes: 2 additions & 0 deletions R/lambda-util.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ check_system_dependencies <- function() {
#' connect to an aws service
#' @param service character, the name of a service, e.g., "lambda" or "iam".
#' Should be a function exported by `paws` (see `getNamespaceExports("paws")`)
#' @return A `paws` client for the service: a list of functions, one per
#' service operation.
#' @examples
#' \dontrun{
#' aws_connect("lambda")
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ to a deployed `AWS Lambda` function.

## Installation

You can install the development version of `{r2lambda}` like so:
You can install the released version of `{r2lambda}` from CRAN with:

``` r
install.packages("r2lambda")
```

You can install the development version of `{r2lambda}` from GitHub with:

``` r
# install.packages("remotes")
Expand Down
5 changes: 5 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## R CMD check results

0 errors | 0 warnings | 1 note

* This is a new release.
4 changes: 4 additions & 0 deletions man/aws_connect.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions man/build_lambda.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/deploy_lambda.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions man/invoke_lambda.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions man/schedule_lambda.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions man/test_lambda.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion tests/testthat.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@
library(testthat)
library(r2lambda)

test_check("r2lambda")
# tests/testthat/setup.R uses withr to keep tests away from real AWS
# credentials, so the suite can't run without it.
if (requireNamespace("withr", quietly = TRUE)) {
test_check("r2lambda")
}
Loading