This repository contains source code and supporting files demonstrating how to run R on AWS Lambda functions using two approaches:
This repository uses the Serverless Application Model (SAM) to define the necessary infrastructure. It includes the following files and folders:
lambdr/
: Code for thelambdr
implementation.rpy2/
: Code for therpy2
implementation.template.yaml
: A template that defines the application's AWS resources.
├── lambdr
│ ├── Dockerfile
│ ├── app.R
│ └── requirements.txt
├── rpy2
│ ├── Dockerfile
│ ├── app.py
│ ├── requirements.txt
│ └── utils.R
└── template.yaml
To build and deploy this application, you will need to install the SAM CLI and Docker.
To deploy this application for the first time, run the following:
sam build
sam deploy --guided
The first command will build a Docker image from a Dockerfile and then copy the source of the application inside the Docker image. The second command will package and deploy the application to AWS, with a series of prompts.
See the AWS SAM developer guide for an introduction to SAM specification, the SAM CLI, and serverless application concepts.
To invoke the functions, run the following:
aws lambda invoke \
--function-name r-lambda-demo-rpy2 \
--cli-binary-format raw-in-base64-out \
--payload '{"number": "24"}' \
response.json
aws lambda invoke \
--function-name r-lambda-demo-lambdr \
--cli-binary-format raw-in-base64-out \
--payload '{"number": "24"}' \
response.json