Skip to contents

Purpose and motivation

The purpose of this document is to present functionality that allows to set EC2 instance without logging to Amazon Web Service portal. This process requires manual work, and could be automated. Thanks to the automation we are also able to clone the g6t/g6tr GitHub repository to the very same instance, so machine is ready to work. The Docker engine is used to pull gradient’s Docker container that launches RStudio Server in the g6t/g6tr directory. S3 bucket is mounted to provide cached library with R packages so the installation procedure is reduced to minimum.

With one function you get pointed to the browser in which RStudio is running, with all needed R packages and with the g6t/g6tr GitHub repo already be cloned there.

Setup

To connect few systems, you will need to store credentials to all of them in .Renviron file.

AWS_ACCESS_KEY_ID = your_aws_access_key_id
AWS_DEFAULT_REGION = us-east-1
AWS_PEM = path_to_your_pem_file
AWS_SECRET_ACCESS_KEY = your_aws_secret_key
DOCKER_PASSWORD = random_username
DOCKER_USERNAME = random_password
GITHUB_PASSWORD = some_other_password
GITHUB_USERNAME = some_other_username

GitHub and Docker are easy, you just need to paste your user names and passwords. For AWS you would need to log into the console, in the upper right corner hit your provile and then My Security Credentials, and lastly Create access key.

g6tr

Setup

To get the functionality you would need to have g6tr package, at least in version 0.3.14, so that after loading the library with

To install g6tr.ec2 you would need to

  • clone the current version of the g6tr repository
  • click packages/g6tr.ec2/g6tr.ec2.Rproj file to open a directory within the software package
  • and then hit Install&Restart in the Build panel, that should be next to Environment and Git panels

g6tr_ec2_launch()

We provided g6tr_ec2_launch() function that, when .Renviron is filled and loaded (readRenviron('.Renviron')), allows to start a machine on AWS EC2.

Minimal example to run the instance with default setup is below. All the parameters have default values. However it’s good to use your own image_name or rserver_password.

g6tr_ec2_launch(
  image_keypair = '20170822',
  image_name = 'Made From R',
  rserver_username = 'gradient',
  rserver_password = 'marcin',
  pemfile_path    = Sys.getenv('AWS_PEM') # path to image_keypair.pem
)

The example of the full execution is below

g6tr_ec2_launch(
  image_id = 'ami-08932e4b8e3890138',
  image_type = c('t2.large', 't2.xlarge', 't2.2xlarge'),
  image_security_group = 'sg-cb0bf4b8',
  image_keypair = '20170822',
  image_name = 'Made From R',
  rserver_username = 'gradient',
  rserver_password = 'marcin',
  docker_tag = c('minimal-3.6', 'minimal-3.5', 'rest', 'minimal'),
  docker_username = Sys.getenv('DOCKER_USERNAME'),
  docker_password = Sys.getenv('DOCKER_PASSWORD'),
  github_username = Sys.getenv('GITHUB_USERNAME'),
  github_password = Sys.getenv('GITHUB_PASSWORD'),
  github_email    = Sys.getenv('GITHUB_EMAIL'),
  amazon_key_id     = Sys.getenv('AWS_ACCESS_KEY_ID'),
  amazon_secret_key = Sys.getenv('AWS_SECRET_ACCESS_KEY'),
  pemfile_path      = Sys.getenv('AWS_PEM')
)

where

  • image_id the id of an AMI from this section to be used as a source machine
  • image_type the size of the machine
  • image_security_group the name of the security group to be used to set the access (use the defualt one)
  • image_keypair the name of the keypair that matches PEM file for ssh authentication
  • image_name custom name to be set for the machine
  • rsever_username the username for RStudio Server
  • rsever_password the authentication password for RStudio Server
  • docker_username the username to hub.docker.com portal, so that gradientmetrics/g6tr_github:docker_tag can be pulled
  • docker_password the password to hub.docker.com portal, so that gradientmetrics/g6tr_github:docker_tag can be pulled
  • docker_tag the docker tag name to be used to launch docker container, one of minimal-3.5, minimal-3.6 or rest
  • github_username the username to github.com portal, so that g6t/g6tr can be cloned
  • github_password the password to github.com portal, so that g6t/g6tr can be cloned
  • github_email the email used on github.com portal
  • amazon_key_id the access key ID from aws.amazon.com, so that s3 bucket can be mounted
  • amazon_secret_key the secret access key from aws.amazon.com, so that s3 bucket can be mounted
  • pemfile_path local path to the image_keypair file