Skip to content

Commit

Permalink
add rstudio.sh userdata script and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
leeper committed Jul 30, 2018
1 parent 7cc5286 commit e91a524
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 6 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: aws.ec2
Type: Package
Title: Amazon Web Services EC2 Client Package
Version: 0.1.16
Date: 2018-07-25
Version: 0.1.17
Date: 2018-07-27
Authors@R: c(person("Thomas J.", "Leeper", role = c("aut", "cre"),
email = "[email protected]",
comment = c(ORCID = "0000-0003-4097-6326")),
Expand All @@ -19,6 +19,7 @@ Imports:
Suggests:
testthat,
aws.ec2metadata,
aws.iam,
ssh
URL: https://github.com/cloudyr/aws.ec2
BugReports: https://github.com/cloudyr/aws.ec2/issues
Expand Down
43 changes: 41 additions & 2 deletions R/run_instances.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#' <http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_RunInstances.html>
#' @examples
#' \dontrun{
#' # RStudio AMIs from: http://www.louisaslett.com/RStudio_AMI/
#' describe_images("ami-7f9dc615")
#' # Rstudio instance for interactive use
#' ## RStudio AMIs from: http://www.louisaslett.com/RStudio_AMI/
#' s <- describe_subnets()
#' g <- create_sgroup("my_security_group", "a security group", vpc = s[[1]])
#' i <- run_instances(image = "ami-7f9dc615",
Expand All @@ -32,6 +32,45 @@
#'
#' stop_instances(i[[1]])
#' terminate_instances(i[[1]])
#'
#'
#' # Generic linux image
#' ## create an SSH keypair
#' my_keypair <- create_keypair("r-ec2-example")
#' pem_file <- tempfile(fileext = ".pem")
#' cat(my_keypair$keyMaterial, file = pem_file)
#'
#' ## script to install R, RStudio, and awspack
#' sh <- system.file("rstudio.sh", package = "aws.ec2")
#'
#' ## run instance
#' i <- run_instances(image = "ami-97785bed",
#' type = "t2.micro",
#' userdata = readBin(sh)
#' keypair = my_keypair)
#' )
#' try(authorize_ingress(my_sg))
#' instance_ip <- associate_ip(i, allocate_ip("vpc"))$publicIp
#'
#' # log in to instance
#' library("ssh")
#' session <- ssh::ssh_connect(paste0("ec2user@", instance_ip),
#' keyfile = pem_file, passwd = "ec2password")
#'
#' # write a quick little R script to execute
#' cat("'hello world!'\n", file = "helloworld.R")
#' # upload it to instance
#' invisible(ssh::scp_upload(session, "helloworld.R"))
#'
#' # execute script on instance
#' x <- ssh::ssh_exec_wait(session, "Rscript helloworld.R")
#'
#' ## disconnect from instance
#' ssh_disconnect(session)
#'
#' # kill instance
#' stop_instances(i[[1]])
#' terminate_instances(i[[1]])
#' }
#' @seealso [describe_instances()], [start_instances()], [terminate_instances()]
#' @keywords instances
Expand Down
17 changes: 17 additions & 0 deletions inst/rstudio.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# install R
yum install -y R

# install full awspack suite
R -e "install.packages('awspack', repos='https://cloud.r-project.org/')"

# install RStudio-Server (1.1.456)
# latest version number is in: https://download2.rstudio.org/current.ver
wget https://download2.rstudio.org/rstudio-server-rhel-1.1.456-x86_64.rpm
yum install -y --nogpgcheck rstudio-server-rhel-1.1.456-x86_64.rpm
rm rstudio-server-rhel-1.1.456-x86_64.rpm

# add user(s)
useradd ec2user
echo ec2user:ec2password | chpasswd
43 changes: 41 additions & 2 deletions man/run_instances.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e91a524

Please sign in to comment.