Deploying a plumber API on AWS EC2 instance

Danny Morris


  1. Launch an EC2 instance using this AMI

  2. Connect to RStudio Sever on AWS EC2 Instance. See this post

  3. In RStudio Server, create a folder called plumber-apis (or something similar)

  4. Create two .R files sample-plumber.R and launch-sample-plumber.R


# plumber.R

#* Echo back the input
#* @param msg The message to echo
#* @get /echo
  list(msg = paste0("The message is: '", msg, "'"))

#* Plot a histogram
#* @png
#* @get /plot
  rand <- rnorm(100)

#* Return the sum of two numbers
#* @param a The first number to add
#* @param b The second number to add
#* @post /sum
function(a, b){
  as.numeric(a) + as.numeric(b)


  1. SSH into the EC2 instance using Git Bash and install the plumber package. See this post
# launch R session
R -

# install plumber
  1. Exit R and cd into RStudio Server home
cd /home/rstudio/plumber-apps/

# In RStudio Server, run getwd() to find the home directory
  1. Run the launch-sample-plumber.R script to expose the API
R CMD BATCH launch-sample-plumber.R
  1. Invoke the API’s POST method

request <- POST("http://ec2-<ip-address>")

content(request, "parsed")