{"id":14066899,"url":"https://github.com/lewinfox/lambdar","last_synced_at":"2026-01-17T13:04:20.709Z","repository":{"id":47712130,"uuid":"392570039","full_name":"lewinfox/lambdar","owner":"lewinfox","description":"Tools to help you run R on AWS Lambda.","archived":false,"fork":false,"pushed_at":"2021-08-29T10:23:59.000Z","size":800,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-04T06:36:55.857Z","etag":null,"topics":["aws","aws-lambda","lambda","r","serverless"],"latest_commit_sha":null,"homepage":"https://lewinfox.github.io/lambdar","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lewinfox.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-04T06:06:32.000Z","updated_at":"2024-09-26T02:52:46.000Z","dependencies_parsed_at":"2022-08-23T06:11:22.868Z","dependency_job_id":null,"html_url":"https://github.com/lewinfox/lambdar","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lewinfox/lambdar","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lewinfox%2Flambdar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lewinfox%2Flambdar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lewinfox%2Flambdar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lewinfox%2Flambdar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lewinfox","download_url":"https://codeload.github.com/lewinfox/lambdar/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lewinfox%2Flambdar/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267780047,"owners_count":24143201,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","aws-lambda","lambda","r","serverless"],"created_at":"2024-08-13T07:05:19.297Z","updated_at":"2026-01-17T13:04:20.663Z","avatar_url":"https://github.com/lewinfox.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"# lambdar \u003ca href='https://lewinfox.github.io/lambdar'\u003e\u003cimg src='man/figures/logo.png' align=\"right\" height=\"138\" /\u003e\u003c/a\u003e\n\n\u003c!-- badges: start --\u003e\n\u003c!-- badges: end --\u003e\n\nThe goal of lambdar is to make it easy to run R on AWS lambda. AWS doesn't provide support for R\nout of the box, but _does_ allow you to provide a custom runtime in the form of a container image or\nlambda layers. Lambdar provides:\n\n* An R runtime (thanks to [mdneuzerling/r-on-lambda](https://github.com/mdneuzerling/r-on-lambda))\n* Tools to build, test and deploy Docker containers containing your code\n\nThe process is simple. You write your code as normal, decorate your lambda function with a\nroxygen-style `@lambda` tag, and lambdar does the rest. It's designed to drop on top of your\nexisting work with almost no changes to your code.\n\n\n## Installation\n\nYou can install the development version from GitHub with\n\n``` r\ndevtools::install_github(\"lewinfox/lambdar\")\n```\n\n[Docker](https://docs.docker.com/get-docker/) and the [AWS cli](https://aws.amazon.com/cli/) are \nrecommended - without these lambdar can build Dockerfiles but can't create or deploy the actual \nimage.\n\n\n## Setup\n\nLambdar is designed to work in [R projects](https://r4ds.had.co.nz/workflow-projects.html). For this\nexample I've create a project in a directory called `lambdar-test`. The project contains one file,\n`main.R`, which contains one function, `hello_world()`.\n\n\n\n``` r\n# main.R\n\n#' @lambda\nhello_world \u003c- function(name = NULL) {\n  if (is.null(name)) {\n    name \u003c- \"World\"\n  }\n  paste0(\"Hello, \", name, \"!\")\n}\n```\n\n## Generate config file\n\nCall `lambdar::init()`. This will create the following in your project's root directory:\n\n1. A `_lambdar.yml` file. This will be pre-populated with some metadata about your app. For this\n   example you can leave it as-is.\n2. A `.lambdar/` directory containing a single file, `lambdar_runtime.R`. This is the custom runtime\n   that will be installed into the container to make everything work. Don't touch it!\n3. A `.dockerignore` file, which lists the files and folders that should _not_ be copied into the\n   final container image.\n   \nLambdar also scans all the R files in your project looking for:\n\n* Functions with `@lambda` tags (referred to as \"handler functions\")s\n* R package dependencies\n\nand writes this information int `_lambdar.yml`.\n\n``` r\nlambdar::init()\n#\u003e ✔ Setting active project to '/home/lewin/lambdar-test'\n#\u003e ✔ Creating .lambdar directory\n#\u003e ✔ Writing .lambdar/lambdar_runtime.R\n#\u003e ✔ Writing '.dockerignore'\n#\u003e ℹ Scanning project...\n#\u003e ✔ Found 1 handler function\n#\u003e ✔ Writing '_lambdar.yml'\n```\n\nIf you change your code (for example, adding new package dependencies or changing which function is\ntagged with `@lambda`), call `lambdar::build_config()` to re-scan your code and update \n`_lambdar.yml`.\n\n## Edit `_lambdar.yml`\n\nIf you have an AWS account, add your AWS account ID and region to `_lambdar.yml`.\n\n``` yaml\n# _lambdar.yml\n\n# Your 12-digit AWS ID\naws_account_id: \"123456789012\"\n\n# Your preferred AWS region e.g. \"ap-southeast-2\"\naws_region: \"ap-southeast-2\"\n```\n\nFor more information on the different configuration options see `vignette(\"configuration\")`.\n\n\n## Build the image\n\nFrom here you can call `lambdar::build_dockerfile()` or `lambdar::build_image()`. `build_image()` \nbuilds the Dockerfile as part of the process anyway, but if you want to review the Dockerfile before\nbuilding it, use `build_dockerfile()`. The Dockerfile will be created in your project's root \ndirectory.\n\n``` r\nlambdar::build_dockerfile()\n#\u003e ✔ Setting active project to '/home/lewin/lambdar-test'\n#\u003e ✔ Writing 'Dockerfile'\n#\u003e ℹ To build your container, run `docker build -t lambdar-test .` or `lambdar::build_image()`\n```\n\nOr\n\n``` r\nlambdar::build_image()\n#\u003e → `docker build -t lambdar-test .`\n#\u003e\n#\u003e ... [lots of Docker output] ...\n#\u003e\n#\u003e ✓ Docker build successful\n#\u003e ℹ To start your container run `docker run -p 9000:8080 lambdar-test main.hello_world`\n#\u003e ℹ Once running you can send test queries to `http://localhost:9000/2015-03-31/functions/function/invocations`\n```\n\n## Test locally\n\nThe built container is based on an image supplied by AWS that includes a copy of something called\nthe Runtime Interface Emulator (RIE) that simulates the environment your function will run in. This\nmeans you can work out the bugs in your function before deploying to AWS.\n\nTo start a container locally, use the Docker run command from the previous step.\n\n``` bash\ndocker run -p 9000:8080 lambdar-test main.hello_world\n```\n\nIn case you're not familiar with Docker syntax, this means \"run the `lambdar-test` container,\nredirecting traffic from local port 9000 to container port 8080\". `\"main.hello_world\"` is a required\nparameter that tells the Lambda runtime which handler we want this container to use. In this case\nwe're using the `hello_world()` function from the `main.R` file.\n\nYou can now query the demo endpoint using the tool of your choice to test your API.\n\n``` bash\n$ curl http://localhost:9000/2015-03-31/functions/function/invocations\n{\"result\": \"Hello, World!\", \"status\": \"success\"}\n```\n\nIf your function accepts arguments, you can pass in a JSON payload:\n\n``` bash\n$ curl http://localhost:9000/2015-03-31/functions/function/invocations -d '{\"name\": \"R\"}'\n{\"result\": \"Hello, R!\", \"status\": \"success\"}\n```\n\n**NOTE**: All parameters from the JSON payload are passed to your function as text. If your function\nexpects any other input it needs to perform the conversion itself. For example:\n\n``` R\n# main.R\n\n#' @lambda\nadd_one \u003c- function(x = 0) {\n  x \u003c- as.numeric(x) # You should also add some error handling in case this fails\n  x + 1\n} \n```\n\nTo stop your container use `docker stop`. If you have no other containers running you can use\n\n``` bash\ndocker stop $(docker ps -q)\n```\n\n## Upload to AWS\n\nOnce you've tested your function it's time to upload it to the AWS Elastic Container Registry. You \ncan do this by hand following\n[this guide](https://aws.amazon.com/blogs/aws/new-for-aws-lambda-container-image-support/), or you \ncan use `lambdar::upload_to_ecr()`.\n\n``` R\nlambdar::upload_to_ecr()\n#\u003e ✔ Setting active project to '/home/lewin/lambdar-test'\n#\u003e → `docker tag lambdar-test 123456789012.dkr.ecr.ap-southeast-2.amazonaws.com/lambdar-test:latest`\n#\u003e ✔ Suggessfully tagged `lambdar-test` as `123456789012.dkr.ecr.ap-southeast-2.amazonaws.com/lambdar-test:latest`\n#\u003e ℹ Creating the repository if it doesn't already exist\n#\u003e → `aws ecr create-repository --repository-name lambdar-test`\n#\u003e ℹ Authenticating Docker with AWS ECR\n#\u003e → `aws ecr get-login-password | docker login --username AWS --password-stdin 123456789012.dkr.ecr.ap-southeast-2.amazonaws.com`\n#\u003e ℹ Uploading container image\n#\u003e → `docker push 123456789012.dkr.ecr.ap-southeast-2.amazonaws.com/lambdar-test:latest`\n#\u003e\n#\u003e ... [lots of output] ...\n#\u003e\n#\u003e ✔ Successfully uploaded 123456789012.dkr.ecr.ap-southeast-2.amazonaws.com/lambdar-test:latest\n```\n\n\n## Create your lambda function\n\nCreate your lambda function from your newly-uploaded container image following the steps\n[here](https://aws.amazon.com/blogs/aws/new-for-aws-lambda-container-image-support/).\n\n\n## TODO - future work\n\n* Add a function to create the lambda for you.\n* Provide a GitHub Actions template so we can update on every push etc.\n* Duplicate the same functionality but using lambda layers (the other custom runtime option). See\n  [medium.com/bakdata/running-r-on-aws-lambda](https://medium.com/bakdata/running-r-on-aws-lambda-9d40643551a6).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flewinfox%2Flambdar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flewinfox%2Flambdar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flewinfox%2Flambdar/lists"}