SlideShare a Scribd company logo
1 of 24
Download to read offline
About
Numeract LLC
● Data Science and Economics / Finance consulting services,
open source projects
● Technology Stack: (Postgre)SQL, R, Python, Docker, AWS
Contributors
● Mike Badescu, PhD Economics, Lehigh University
● Ana Niculescu, Msc Statistics for Smart Data, ENSAI, Rennes
● Teodor Ciuraru
github.com/numeract/aws-lambda-r
Agenda
Motivation
APIs
AWS
Running R on Amazon Lambda
Conclusions
Motivation
Deploying R in production is not very easy but it is a
good problem to have.
There are diverse approaches towards creating deployment
packages for AWS Lambda and creating an API but which one is
the best fit for R? This presentation aims to compare currently
available approaches and to present a custom solution.
Overview
Motivation
● Shiny Dashboard for data visualisation and model
validation
● In the backend, the Shiny App was also:
○ reading the data
○ performing data cleaning
○ computing features
○ building prediction models
● Client also needed to access to only the calculation
process to use it outside (and independent from)
the Shiny App
Our use case
Motivation
● Rewriting the code in another programming
language is not efficient
● Certain algorithms may not be available in
other programming languages
● Even though certain algorithms may be available
in other programming languages, they may not
render the same results as in R
Why not rewrite the needed code?
The answer to our problem
● Modularize the application
● Programming language independent
● Common concept: programmers know how to
work with APIs
● Common "data language": JSON (but not the
only one)
APIs
Of R and APIs
● Not directly, as R is not a web server
● We need a wrapper / server that:
● receives requests and hands them to R
● passes any response from R to the client
Candidate approaches
● Web server: plumber and OpenCPU
● Serverless: running R on AWS Lambda -> wrap R
functions inside FasS
Can we serve API requests from R?
Wrapping up the requirements
Getting ready to roll our sleeves
The App task engine should:
● get a request id
● read data from DB
● process data for 5-20 seconds
● return the results
Our challenge: How to use this code in
production?
● needs to be triggered
● uncertain and irregular future demand
● R code still in development
● clicking through an interface to re-deploy
the code every time we needed it was not
an option
Amazon Web Services
Bref
AWS is a collection of pay-as-you-go cloud services.
The services we needed:
● IAM (Identity and Access Management) - for security
● VPC - a logically isolated virtual network
● EC2 - a virtual machine
● API Gateway
● S3 - storage
● Lambda - serverless application service
Amazon Web Services
Lambda: Function as a Service
AWS Lambda is a serverless compute service that
launches and executes code when it is explicitly triggered
by an event (API), and stays up ONLY as long as the code
runs.
● Helps you build apps while minimizing infrastructure
maintenance
● Keep the focus on what’s important: data
engineering/analysis, not DevOps
● Pay only for what you use: supports ad-hoc requests
● Horizontally scalable
Image source:
https://dwdraju.medium.com/python-function-on-aws-lambda-with-api
-gateway-endpoint-288eae7617cb
R on Lambda
How difficult can it be?
Turns out, it is not as intuitive to directly run R in AWS Lambda.
Since December 2018, Amazon introduced
custom runtimes for AWS Lambda. This allows
us to use almost any programming language,
including R.
R on Lambda
Solutions
Our new approach:
● Use a Base R custom runtime provided by Bakdata
● Copy the additional R packages we need inside the deployment
package provided to Lambda
Other approaches:
● Previously we used package rpy2 to run R code from Python)
● R package lambda.r: triggers a Lambda function from R
AWS-Lambda-R
The architecture
Looks simple, but you don’t want to click through all that
every time you want to re-deploy the code...especially
when you have multiple releases
AWS-Lambda-R
Let’s not forget about security
Image source: https://aws.amazon.com/security/
Automation
aws-lambda-r scripts
We needed a fast way to launch the infrastructure entirely.
Our approach: a series of shell scripts that launch the entire AWS
infrastructure needed to run R on AWS Lambda.
Top view:
Deploy R function on AWS Lambda
Configure access to AWS Lambda
Automation
aws-lambda-r implementation details
The scripts:
1. use your settings to create a VPC, S3, authorization
policies
2. install and compile R packages
3. create the zip file to load in AWS Lambda and save it to
S3
4. create Lambda function and deploy the zip file
5. configure AWS API Gateway to allow accessing the
code over the web
The scripts use AWS CLI through (Git)Bash => available on
all platforms
R example
A simple function that runs in Lambda
Command Line
Running the scripts...
Command Line
API requests
Pros
At the end of the setup, you will have the entire infrastructure to
run R on AWS Lambda, without worrying about EC2 instances or
scalability issues.
● use AWS Command Line Interface - no need for clicks anymore
● pay-as-you go
● fast deployment after each release
● easy to adapt to automatically deploy code written in Python or
JavaScript (if needed in the future)
Limitations
● Lambda function memory allocation: 128 MB to 10,240 MB
● Function timeout: 15 minutes
● Maximum zip file size: 250MB
● this is the most important limitation as it prevents using large R
packages
Finally
Where Data Science stops and Data
Engineering begins...
● Each project has unique requirements and constraints
● AWS was great for our needs, Lambda too, especially
since it became more flexible through custom
execution environments and layers
● Scripts still run in production, making the client happy
● It is worth automating something in order to be able
to focus in what’s more important
github.com/numeract/aws-lambda-r
anamaria.niculescu@numeract.com
linkedin.com/in/anamarianiculescu/
github.com/AnaNiculescu36
Thank you!

More Related Content

What's hot

A planificação didáctica nova apresentação
A planificação didáctica   nova apresentaçãoA planificação didáctica   nova apresentação
A planificação didáctica nova apresentação
Lourenço Neto
 
Python ders-notlari
Python ders-notlariPython ders-notlari
Python ders-notlari
sersld98
 
Curso de Introdução a Engenharia de Software - CJR/UnB - Aula 1
Curso de Introdução a Engenharia de Software - CJR/UnB - Aula 1Curso de Introdução a Engenharia de Software - CJR/UnB - Aula 1
Curso de Introdução a Engenharia de Software - CJR/UnB - Aula 1
Renato Leal
 
Técnicas úteis ao escrever uma síntese
Técnicas úteis ao escrever uma sínteseTécnicas úteis ao escrever uma síntese
Técnicas úteis ao escrever uma síntese
Mayjö .
 
Introducao eng software [modo de compatibilidade]
Introducao eng software [modo de compatibilidade]Introducao eng software [modo de compatibilidade]
Introducao eng software [modo de compatibilidade]
Fernanda Ramos
 
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(1)-アーキテクチャ、データソース
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(1)-アーキテクチャ、データソース2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(1)-アーキテクチャ、データソース
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(1)-アーキテクチャ、データソース
Enpel
 

What's hot (14)

A planificação didáctica nova apresentação
A planificação didáctica   nova apresentaçãoA planificação didáctica   nova apresentação
A planificação didáctica nova apresentação
 
Ontology Development Kit: Bio-Ontologies 2019
Ontology Development Kit: Bio-Ontologies 2019Ontology Development Kit: Bio-Ontologies 2019
Ontology Development Kit: Bio-Ontologies 2019
 
Análise de ferramentas para gestão de regras de negócio em sistemas de inform...
Análise de ferramentas para gestão de regras de negócio em sistemas de inform...Análise de ferramentas para gestão de regras de negócio em sistemas de inform...
Análise de ferramentas para gestão de regras de negócio em sistemas de inform...
 
Modelo incremental
Modelo incrementalModelo incremental
Modelo incremental
 
Python ders-notlari
Python ders-notlariPython ders-notlari
Python ders-notlari
 
API de segurança do Java EE 8
API de segurança do Java EE 8API de segurança do Java EE 8
API de segurança do Java EE 8
 
Curso de Introdução a Engenharia de Software - CJR/UnB - Aula 1
Curso de Introdução a Engenharia de Software - CJR/UnB - Aula 1Curso de Introdução a Engenharia de Software - CJR/UnB - Aula 1
Curso de Introdução a Engenharia de Software - CJR/UnB - Aula 1
 
Técnicas úteis ao escrever uma síntese
Técnicas úteis ao escrever uma sínteseTécnicas úteis ao escrever uma síntese
Técnicas úteis ao escrever uma síntese
 
Introducao eng software [modo de compatibilidade]
Introducao eng software [modo de compatibilidade]Introducao eng software [modo de compatibilidade]
Introducao eng software [modo de compatibilidade]
 
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(1)-アーキテクチャ、データソース
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(1)-アーキテクチャ、データソース2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(1)-アーキテクチャ、データソース
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(1)-アーキテクチャ、データソース
 
Spring data-rest-and-spring-cloud-contract
Spring data-rest-and-spring-cloud-contractSpring data-rest-and-spring-cloud-contract
Spring data-rest-and-spring-cloud-contract
 
Information Management with Redmine
Information Management with RedmineInformation Management with Redmine
Information Management with Redmine
 
DevOps Meetup ansible
DevOps Meetup   ansibleDevOps Meetup   ansible
DevOps Meetup ansible
 
[PHPConf Taiwan 2015] 跟著 Laravel 5.1 一起成為更好的 PHP 開發者
[PHPConf Taiwan 2015] 跟著 Laravel 5.1 一起成為更好的 PHP 開發者[PHPConf Taiwan 2015] 跟著 Laravel 5.1 一起成為更好的 PHP 開發者
[PHPConf Taiwan 2015] 跟著 Laravel 5.1 一起成為更好的 PHP 開發者
 

Similar to Running R on AWS Lambda by Ana-Maria Niculescu

AWS re:Invent 2020 Serverless Recap
AWS re:Invent 2020 Serverless RecapAWS re:Invent 2020 Serverless Recap
AWS re:Invent 2020 Serverless Recap
Daniel Zivkovic
 

Similar to Running R on AWS Lambda by Ana-Maria Niculescu (20)

Aws serverless architecture
Aws serverless architectureAws serverless architecture
Aws serverless architecture
 
PyConIT 2018 Writing and deploying serverless python applications
PyConIT 2018 Writing and deploying serverless python applicationsPyConIT 2018 Writing and deploying serverless python applications
PyConIT 2018 Writing and deploying serverless python applications
 
AWS Serverless with Lambda, ApiGateway
AWS Serverless with Lambda, ApiGatewayAWS Serverless with Lambda, ApiGateway
AWS Serverless with Lambda, ApiGateway
 
Building self service framework
Building self service frameworkBuilding self service framework
Building self service framework
 
State of serverless
State of serverlessState of serverless
State of serverless
 
Write less (code) and build more with serverless
Write less (code) and build more with serverlessWrite less (code) and build more with serverless
Write less (code) and build more with serverless
 
Skillenza Build with Serverless Challenge - Advanced Serverless Concepts
Skillenza Build with Serverless Challenge -  Advanced Serverless ConceptsSkillenza Build with Serverless Challenge -  Advanced Serverless Concepts
Skillenza Build with Serverless Challenge - Advanced Serverless Concepts
 
AWS re:Invent 2020 Serverless Recap
AWS re:Invent 2020 Serverless RecapAWS re:Invent 2020 Serverless Recap
AWS re:Invent 2020 Serverless Recap
 
API workshop by AWS and 3scale
API workshop by AWS and 3scaleAPI workshop by AWS and 3scale
API workshop by AWS and 3scale
 
Writing and deploying serverless python applications
Writing and deploying serverless python applicationsWriting and deploying serverless python applications
Writing and deploying serverless python applications
 
Go lambda-presentation
Go lambda-presentationGo lambda-presentation
Go lambda-presentation
 
PyConIE 2017 Writing and deploying serverless python applications
PyConIE 2017 Writing and deploying serverless python applicationsPyConIE 2017 Writing and deploying serverless python applications
PyConIE 2017 Writing and deploying serverless python applications
 
Introduction To AWS & AWS Lambda
Introduction To AWS & AWS LambdaIntroduction To AWS & AWS Lambda
Introduction To AWS & AWS Lambda
 
AWS Lambda Documentation
AWS Lambda DocumentationAWS Lambda Documentation
AWS Lambda Documentation
 
Getting Started with AWS Lambda and the Serverless Cloud
Getting Started with AWS Lambda and the Serverless CloudGetting Started with AWS Lambda and the Serverless Cloud
Getting Started with AWS Lambda and the Serverless Cloud
 
Building A Serverless Web Application With AWS Lambda: A Step-By-Step Guide
Building A Serverless Web Application With AWS Lambda: A Step-By-Step GuideBuilding A Serverless Web Application With AWS Lambda: A Step-By-Step Guide
Building A Serverless Web Application With AWS Lambda: A Step-By-Step Guide
 
Building Linked Data Platform with AWS
Building Linked Data Platform with AWSBuilding Linked Data Platform with AWS
Building Linked Data Platform with AWS
 
AWS Lambda and Serverless Cloud
AWS Lambda and Serverless CloudAWS Lambda and Serverless Cloud
AWS Lambda and Serverless Cloud
 
Migrating your .NET Applications to the AWS Serverless Platform
Migrating your .NET Applications to the AWS Serverless PlatformMigrating your .NET Applications to the AWS Serverless Platform
Migrating your .NET Applications to the AWS Serverless Platform
 
Serverless Computing, AWS Way by SourceFuse Technologies
Serverless Computing, AWS Way by SourceFuse Technologies Serverless Computing, AWS Way by SourceFuse Technologies
Serverless Computing, AWS Way by SourceFuse Technologies
 

More from Paris Women in Machine Learning and Data Science

More from Paris Women in Machine Learning and Data Science (20)

Sequential and reinforcement learning for demand side management by Margaux B...
Sequential and reinforcement learning for demand side management by Margaux B...Sequential and reinforcement learning for demand side management by Margaux B...
Sequential and reinforcement learning for demand side management by Margaux B...
 
How and why AI should fight cybersexism, by Chloe Daudier
How and why AI should fight cybersexism, by Chloe DaudierHow and why AI should fight cybersexism, by Chloe Daudier
How and why AI should fight cybersexism, by Chloe Daudier
 
Anomaly detection and data imputation within time series
Anomaly detection and data imputation within time seriesAnomaly detection and data imputation within time series
Anomaly detection and data imputation within time series
 
Managing international tech teams, by Natasha Dimban
Managing international tech teams, by Natasha DimbanManaging international tech teams, by Natasha Dimban
Managing international tech teams, by Natasha Dimban
 
Optimizing GenAI apps, by N. El Mawass and Maria Knorps
Optimizing GenAI apps, by N. El Mawass and Maria KnorpsOptimizing GenAI apps, by N. El Mawass and Maria Knorps
Optimizing GenAI apps, by N. El Mawass and Maria Knorps
 
Perspectives, by M. Pannegeon
Perspectives, by M. PannegeonPerspectives, by M. Pannegeon
Perspectives, by M. Pannegeon
 
Evaluation strategies for dealing with partially labelled or unlabelled data
Evaluation strategies for dealing with partially labelled or unlabelled dataEvaluation strategies for dealing with partially labelled or unlabelled data
Evaluation strategies for dealing with partially labelled or unlabelled data
 
Combinatorial Optimisation with Policy Adaptation using latent Space Search, ...
Combinatorial Optimisation with Policy Adaptation using latent Space Search, ...Combinatorial Optimisation with Policy Adaptation using latent Space Search, ...
Combinatorial Optimisation with Policy Adaptation using latent Space Search, ...
 
An age-old question, by Caroline Jean-Pierre
An age-old question, by Caroline Jean-PierreAn age-old question, by Caroline Jean-Pierre
An age-old question, by Caroline Jean-Pierre
 
Applying Churn Prediction Approaches to the Telecom Industry, by Joëlle Lautré
Applying Churn Prediction Approaches to the Telecom Industry, by Joëlle LautréApplying Churn Prediction Approaches to the Telecom Industry, by Joëlle Lautré
Applying Churn Prediction Approaches to the Telecom Industry, by Joëlle Lautré
 
How to supervise a thesis in NLP in the ChatGPT era? By Laure Soulier
How to supervise a thesis in NLP in the ChatGPT era? By Laure SoulierHow to supervise a thesis in NLP in the ChatGPT era? By Laure Soulier
How to supervise a thesis in NLP in the ChatGPT era? By Laure Soulier
 
Global Ambitions Local Realities, by Anna Abreu
Global Ambitions Local Realities, by Anna AbreuGlobal Ambitions Local Realities, by Anna Abreu
Global Ambitions Local Realities, by Anna Abreu
 
Plug-and-Play methods for inverse problems in imagine, by Julie Delon
Plug-and-Play methods for inverse problems in imagine, by Julie DelonPlug-and-Play methods for inverse problems in imagine, by Julie Delon
Plug-and-Play methods for inverse problems in imagine, by Julie Delon
 
Sales Forecasting as a Data Product by Francesca Iannuzzi
Sales Forecasting as a Data Product by Francesca IannuzziSales Forecasting as a Data Product by Francesca Iannuzzi
Sales Forecasting as a Data Product by Francesca Iannuzzi
 
Identifying and mitigating bias in machine learning, by Ruta Binkyte
Identifying and mitigating bias in machine learning, by Ruta BinkyteIdentifying and mitigating bias in machine learning, by Ruta Binkyte
Identifying and mitigating bias in machine learning, by Ruta Binkyte
 
“Turning your ML algorithms into full web apps in no time with Python" by Mar...
“Turning your ML algorithms into full web apps in no time with Python" by Mar...“Turning your ML algorithms into full web apps in no time with Python" by Mar...
“Turning your ML algorithms into full web apps in no time with Python" by Mar...
 
Nature Language Processing for proteins by Amélie Héliou, Software Engineer @...
Nature Language Processing for proteins by Amélie Héliou, Software Engineer @...Nature Language Processing for proteins by Amélie Héliou, Software Engineer @...
Nature Language Processing for proteins by Amélie Héliou, Software Engineer @...
 
Sandrine Henry presents the BechdelAI project
Sandrine Henry presents the BechdelAI projectSandrine Henry presents the BechdelAI project
Sandrine Henry presents the BechdelAI project
 
Anastasiia Tryputen_War in Ukraine or how extraordinary courage reshapes geop...
Anastasiia Tryputen_War in Ukraine or how extraordinary courage reshapes geop...Anastasiia Tryputen_War in Ukraine or how extraordinary courage reshapes geop...
Anastasiia Tryputen_War in Ukraine or how extraordinary courage reshapes geop...
 
Khrystyna Grynko WiMLDS - From marketing to Tech.pdf
Khrystyna Grynko WiMLDS - From marketing to Tech.pdfKhrystyna Grynko WiMLDS - From marketing to Tech.pdf
Khrystyna Grynko WiMLDS - From marketing to Tech.pdf
 

Recently uploaded

Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
gajnagarg
 
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi ArabiaIn Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
ahmedjiabur940
 
Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...
nirzagarg
 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
一比一原版(UCD毕业证书)加州大学戴维斯分校毕业证成绩单原件一模一样
一比一原版(UCD毕业证书)加州大学戴维斯分校毕业证成绩单原件一模一样一比一原版(UCD毕业证书)加州大学戴维斯分校毕业证成绩单原件一模一样
一比一原版(UCD毕业证书)加州大学戴维斯分校毕业证成绩单原件一模一样
wsppdmt
 
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制
vexqp
 
一比一原版(曼大毕业证书)曼尼托巴大学毕业证成绩单留信学历认证一手价格
一比一原版(曼大毕业证书)曼尼托巴大学毕业证成绩单留信学历认证一手价格一比一原版(曼大毕业证书)曼尼托巴大学毕业证成绩单留信学历认证一手价格
一比一原版(曼大毕业证书)曼尼托巴大学毕业证成绩单留信学历认证一手价格
q6pzkpark
 
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
wsppdmt
 
Lecture_2_Deep_Learning_Overview-newone1
Lecture_2_Deep_Learning_Overview-newone1Lecture_2_Deep_Learning_Overview-newone1
Lecture_2_Deep_Learning_Overview-newone1
ranjankumarbehera14
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
gajnagarg
 
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
nirzagarg
 

Recently uploaded (20)

Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book nowVadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
 
7. Epi of Chronic respiratory diseases.ppt
7. Epi of Chronic respiratory diseases.ppt7. Epi of Chronic respiratory diseases.ppt
7. Epi of Chronic respiratory diseases.ppt
 
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
 
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi ArabiaIn Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
 
Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Satna [ 7014168258 ] Call Me For Genuine Models We ...
 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
 
一比一原版(UCD毕业证书)加州大学戴维斯分校毕业证成绩单原件一模一样
一比一原版(UCD毕业证书)加州大学戴维斯分校毕业证成绩单原件一模一样一比一原版(UCD毕业证书)加州大学戴维斯分校毕业证成绩单原件一模一样
一比一原版(UCD毕业证书)加州大学戴维斯分校毕业证成绩单原件一模一样
 
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制
 
Harnessing the Power of GenAI for BI and Reporting.pptx
Harnessing the Power of GenAI for BI and Reporting.pptxHarnessing the Power of GenAI for BI and Reporting.pptx
Harnessing the Power of GenAI for BI and Reporting.pptx
 
Switzerland Constitution 2002.pdf.........
Switzerland Constitution 2002.pdf.........Switzerland Constitution 2002.pdf.........
Switzerland Constitution 2002.pdf.........
 
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
 
一比一原版(曼大毕业证书)曼尼托巴大学毕业证成绩单留信学历认证一手价格
一比一原版(曼大毕业证书)曼尼托巴大学毕业证成绩单留信学历认证一手价格一比一原版(曼大毕业证书)曼尼托巴大学毕业证成绩单留信学历认证一手价格
一比一原版(曼大毕业证书)曼尼托巴大学毕业证成绩单留信学历认证一手价格
 
Ranking and Scoring Exercises for Research
Ranking and Scoring Exercises for ResearchRanking and Scoring Exercises for Research
Ranking and Scoring Exercises for Research
 
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
 
Lecture_2_Deep_Learning_Overview-newone1
Lecture_2_Deep_Learning_Overview-newone1Lecture_2_Deep_Learning_Overview-newone1
Lecture_2_Deep_Learning_Overview-newone1
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
 
SR-101-01012024-EN.docx Federal Constitution of the Swiss Confederation
SR-101-01012024-EN.docx  Federal Constitution  of the Swiss ConfederationSR-101-01012024-EN.docx  Federal Constitution  of the Swiss Confederation
SR-101-01012024-EN.docx Federal Constitution of the Swiss Confederation
 
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 

Running R on AWS Lambda by Ana-Maria Niculescu

  • 1.
  • 2. About Numeract LLC ● Data Science and Economics / Finance consulting services, open source projects ● Technology Stack: (Postgre)SQL, R, Python, Docker, AWS Contributors ● Mike Badescu, PhD Economics, Lehigh University ● Ana Niculescu, Msc Statistics for Smart Data, ENSAI, Rennes ● Teodor Ciuraru github.com/numeract/aws-lambda-r
  • 3. Agenda Motivation APIs AWS Running R on Amazon Lambda Conclusions
  • 4. Motivation Deploying R in production is not very easy but it is a good problem to have. There are diverse approaches towards creating deployment packages for AWS Lambda and creating an API but which one is the best fit for R? This presentation aims to compare currently available approaches and to present a custom solution. Overview
  • 5. Motivation ● Shiny Dashboard for data visualisation and model validation ● In the backend, the Shiny App was also: ○ reading the data ○ performing data cleaning ○ computing features ○ building prediction models ● Client also needed to access to only the calculation process to use it outside (and independent from) the Shiny App Our use case
  • 6. Motivation ● Rewriting the code in another programming language is not efficient ● Certain algorithms may not be available in other programming languages ● Even though certain algorithms may be available in other programming languages, they may not render the same results as in R Why not rewrite the needed code?
  • 7. The answer to our problem ● Modularize the application ● Programming language independent ● Common concept: programmers know how to work with APIs ● Common "data language": JSON (but not the only one) APIs
  • 8. Of R and APIs ● Not directly, as R is not a web server ● We need a wrapper / server that: ● receives requests and hands them to R ● passes any response from R to the client Candidate approaches ● Web server: plumber and OpenCPU ● Serverless: running R on AWS Lambda -> wrap R functions inside FasS Can we serve API requests from R?
  • 9. Wrapping up the requirements Getting ready to roll our sleeves The App task engine should: ● get a request id ● read data from DB ● process data for 5-20 seconds ● return the results Our challenge: How to use this code in production? ● needs to be triggered ● uncertain and irregular future demand ● R code still in development ● clicking through an interface to re-deploy the code every time we needed it was not an option
  • 10. Amazon Web Services Bref AWS is a collection of pay-as-you-go cloud services. The services we needed: ● IAM (Identity and Access Management) - for security ● VPC - a logically isolated virtual network ● EC2 - a virtual machine ● API Gateway ● S3 - storage ● Lambda - serverless application service
  • 11. Amazon Web Services Lambda: Function as a Service AWS Lambda is a serverless compute service that launches and executes code when it is explicitly triggered by an event (API), and stays up ONLY as long as the code runs. ● Helps you build apps while minimizing infrastructure maintenance ● Keep the focus on what’s important: data engineering/analysis, not DevOps ● Pay only for what you use: supports ad-hoc requests ● Horizontally scalable Image source: https://dwdraju.medium.com/python-function-on-aws-lambda-with-api -gateway-endpoint-288eae7617cb
  • 12. R on Lambda How difficult can it be? Turns out, it is not as intuitive to directly run R in AWS Lambda. Since December 2018, Amazon introduced custom runtimes for AWS Lambda. This allows us to use almost any programming language, including R.
  • 13. R on Lambda Solutions Our new approach: ● Use a Base R custom runtime provided by Bakdata ● Copy the additional R packages we need inside the deployment package provided to Lambda Other approaches: ● Previously we used package rpy2 to run R code from Python) ● R package lambda.r: triggers a Lambda function from R
  • 14. AWS-Lambda-R The architecture Looks simple, but you don’t want to click through all that every time you want to re-deploy the code...especially when you have multiple releases
  • 15. AWS-Lambda-R Let’s not forget about security Image source: https://aws.amazon.com/security/
  • 16. Automation aws-lambda-r scripts We needed a fast way to launch the infrastructure entirely. Our approach: a series of shell scripts that launch the entire AWS infrastructure needed to run R on AWS Lambda. Top view: Deploy R function on AWS Lambda Configure access to AWS Lambda
  • 17. Automation aws-lambda-r implementation details The scripts: 1. use your settings to create a VPC, S3, authorization policies 2. install and compile R packages 3. create the zip file to load in AWS Lambda and save it to S3 4. create Lambda function and deploy the zip file 5. configure AWS API Gateway to allow accessing the code over the web The scripts use AWS CLI through (Git)Bash => available on all platforms
  • 18. R example A simple function that runs in Lambda
  • 21. Pros At the end of the setup, you will have the entire infrastructure to run R on AWS Lambda, without worrying about EC2 instances or scalability issues. ● use AWS Command Line Interface - no need for clicks anymore ● pay-as-you go ● fast deployment after each release ● easy to adapt to automatically deploy code written in Python or JavaScript (if needed in the future)
  • 22. Limitations ● Lambda function memory allocation: 128 MB to 10,240 MB ● Function timeout: 15 minutes ● Maximum zip file size: 250MB ● this is the most important limitation as it prevents using large R packages
  • 23. Finally Where Data Science stops and Data Engineering begins... ● Each project has unique requirements and constraints ● AWS was great for our needs, Lambda too, especially since it became more flexible through custom execution environments and layers ● Scripts still run in production, making the client happy ● It is worth automating something in order to be able to focus in what’s more important