All Projects → numeract → aws-lambda-r

numeract / aws-lambda-r

Licence: MIT license
Using R on AWS Lambda

Programming Languages

shell
77523 projects
javascript
184084 projects - #8 most used programming language
python
139335 projects - #7 most used programming language
r
7636 projects

Projects that are alternatives of or similar to aws-lambda-r

serverless
BlueNimble is a Hybrid Serverless Platform focusing on developer productivity and application portability. Create and run scalable APIs and applications without coding or by coding less. Focus on application business logic without any knowledge of the underlying microservices architecture.
Stars: ✭ 30 (-41.18%)
Mutual labels:  api-gateway, faas
Workshop Donkeytracker
Workshop to build a serverless tracking application for your mobile device with an AWS backend
Stars: ✭ 27 (-47.06%)
Mutual labels:  api-gateway, aws-cli
hyperform
⚡ Lightweight serverless framework for NodeJS
Stars: ✭ 156 (+205.88%)
Mutual labels:  api-gateway, faas
aws-sso-creds-helper
A command line util for using SSO credentials with AWS SDK on AWS CLI v2 until native support is released
Stars: ✭ 34 (-33.33%)
Mutual labels:  aws-cli
Hands-On-Serverless-Applications-with-Go
Hands-On Serverless Applications with Go, published by Packt.
Stars: ✭ 92 (+80.39%)
Mutual labels:  api-gateway
docker-dind-awscli
A Docker image for Docker-in-Docker (dind) with AWS CLI v2 awscli tool included
Stars: ✭ 36 (-29.41%)
Mutual labels:  aws-cli
xkcd-excuse-generator
Serverless image generator that uses XKCD comic as basis for _all_ excuses!
Stars: ✭ 63 (+23.53%)
Mutual labels:  faas
ngx-lua-zuul
基于Nginx&Lua 和Netflix Eureka的微服务网关。请看看:https://github.com/tietang/zebra
Stars: ✭ 94 (+84.31%)
Mutual labels:  api-gateway
gluu-gateway
Gluu API 🚀 and Web Gateway 🎯
Stars: ✭ 29 (-43.14%)
Mutual labels:  api-gateway
honeypie
A FaaS for converting your Google Forms into an API.
Stars: ✭ 17 (-66.67%)
Mutual labels:  faas
ambassador-docs
Official Ambassador API Gateway Documentation repository
Stars: ✭ 21 (-58.82%)
Mutual labels:  api-gateway
e-shop
Sample Spring Cloud microservices e-shop.
Stars: ✭ 48 (-5.88%)
Mutual labels:  api-gateway
dubbo-go-pixiu
Based on the proxy gateway service of dubbo-go, it solves the problem that the external protocol calls the internal Dubbo cluster. At present, it supports HTTP and gRPC[developing].
Stars: ✭ 385 (+654.9%)
Mutual labels:  api-gateway
awsprofile
Shell script to ease management of AWS profiles
Stars: ✭ 12 (-76.47%)
Mutual labels:  aws-cli
FaaSonK8s
A list of Functions as a Service (FaaS) serverless platforms that run on Kubernetes
Stars: ✭ 44 (-13.73%)
Mutual labels:  faas
sample-spring-cloud-gateway
sample spring cloud application with embedded api gateway on spring cloud gateway with or without service discovery with eureka
Stars: ✭ 25 (-50.98%)
Mutual labels:  api-gateway
kong-oidc-auth
OpenID Connect authentication with Kong gateway
Stars: ✭ 41 (-19.61%)
Mutual labels:  api-gateway
terraform-aws-api-gateway-enable-cors
Easily add an OPTIONS method to an API Gateway resource to enable CORS
Stars: ✭ 56 (+9.8%)
Mutual labels:  api-gateway
serverless-certificate-creator
serverless plugin to manage the certificate of your lambdas custom domain (API Gateway=
Stars: ✭ 33 (-35.29%)
Mutual labels:  api-gateway
gotway
☸️ Cloud native API Gateway powered with in-redis cache
Stars: ✭ 71 (+39.22%)
Mutual labels:  api-gateway

Using R on AWS Lambda

Summary

This repo contains several scripts that facilitate execution of R functions on AWS Lambda.

Currently (March 2018) it is not possible to run R code directly on AWS Lambda, thus we need to invoke it through Python.

The scripts:

  • use your settings to create an AWS EC2 instance,
  • install and compile R packages
  • create the zip file to load in AWS Lambda and save it to S3
  • create Lambda function and deploy the zip file
  • configure AWS API Gateway to allow accessing the code over the web

At the end of the setup, you will have a AWS Lambda function that can be invoked as many times as you wish trough AWS API Gateway, without worrying about EC2 instances or scalability issues.

Scope

The best use case of this setup is

  • almost unlimited scalability (1000 concurrent executions)
  • no idle server time
  • very low cost
  • R functions are small and execute fast
  • input and output through JSON strings

Limitations

AWS Lambda and API Gateway impose several limitations

  • maximum memory 3008MB
    • this should be sufficient to run most functions
  • maximum zip file size 250MB
    • this is the most important limitation as it prevents using large R packages
  • maximum execution time 30 seconds for API Gateway, 5 minutes for AWS Lambda
    • be sure to take allow 1-2 sec for start time

Description

The current setup assumes that the following directories and their content will be added to your R project directory.

  • lambda/ : a temporary directory with files to be uploaded
  • python/ : contains Python files, one for each AWS Lambda entry point, that will be used to invoke the R code
  • scripts/ : the scripts compiling R packages and deploying to AWS Lambda
  • settings/ : settings files used for deployment (e.g. where to find AWS settings)

Directory doc/ contains additional documentation about how to setup for your AWS account (although familiarity with AWS helps a lot) and how to delete the setup created by these scripts.

Installation and configuration

  1. Install AWS CLI on your local machine
    • Be sure that you stored your credentials in ~/.aws/ directory
    • Optionally, create a profile for AWS CLI with aws configure --profile
    • Check that you can connect to your AWS account using the desired profile
      • aws sts get-caller-identity --profile aws-lambda-r
  2. Prepare your project
    • Ideally, the project directory name should contain only letters, dashes, and digits, e.g. aws-lambda-r
    • Be sure that git is initialized in the project directory (without git it will be almost impossible to keep track of changes, especially in production)
      • git status
  3. Copy directories lambda/, python/, scripts/, settings/ to your project directory
  4. Copy and rename setup_auto_example.sh and setup_user_example.sh to setup_auto.sh and setup_user.sh
  5. Overwrite variables from secrets_default.sh and setup_default with personal secrets in setup_user.sh. Variables such as PRJ_NAME, PRJ_BRANCH, AWS_REGION and EC2_DEFAULT_AMI_ID from settings_default.sh should be overwritten accordingly in setup_user.sh.
  6. For automated AWS infrastructure setup run first 21_setup_vpc.sh, 22_setup_custom_ami.sh, 23_setup_s3.sh and 24_setup_lambda.sh, otherwise create the infrastructure manually, following the documentation.

macOS additional steps

Install the following packages, if not already installed:

  1. Homebrew

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

  1. Bash 4

$ brew update && brew install bash

  1. Add Bash 4 as the default shell:
$ sudo nano /etc/shells

# add to last line
/usr/local/bin/bash

# save and quit via ctrl + x
  1. md5sum:

$ brew install md5sha1sum

Load all the scripts via sudo bash ./scripts/<script_name>.sh instead of .scripts/<script_name>.sh.

References

TODO

  • use AWS Cloud​Formation to create a template for all AWS config
    • see "Running R on AWS"
  • script to check AWS CLI is properly installed
  • convert to an R package and execute the scripts from R
  • use /tmp folder on AWS Lambda to load large libraries (e.g., BH)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].