Skip to content

How to setup a Shiny Server on Amazon AWS

Knut Ole Sjøli edited this page Oct 24, 2018 · 25 revisions

Contents

  1. Create an EC2 instance on AWS
  2. Install dependencies
  3. Configure Auth0.com
  4. Install Shiny Server
  5. Start/stop
  6. Upload data with SFTP
  7. Troubleshooting

Create an EC2 instance on Amazon AWS

  1. Log in to your Amazon AWS console.
  2. Create an EC2 instance:
    • Instance type: t3.medium with 2 vCPUs and 4GB RAM. (This is sufficient for a medium-use Shiny Server)
    • OS: Ubuntu 18.04 LTS
    • EBS storage: 8-30GB
    • Open inbound ports: 80, 22, 2222, 443
    • Open outbound ports: All
  3. Create an Elastic IP and associate it with your newly created instance
  4. Log in to your instance with your SSH keys (keys created when instance was created)

Install dependencies on your EC2 instance

Run the following bash script to install dependences, including Docker, to your instance.

#!/bin/bash

# update package list
sudo apt-get update -y

# get dependencies
sudo apt-get install -y fish htop wget git nano \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

# get keys
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# add repo
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

# get latest package list
sudo apt-get update -y

# install docker
sudo apt-get install -y docker-ce

# ensure docker is installed
docker --version

# download docker compose
curl -L "https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

# make executable
sudo chmod +x /usr/local/bin/docker-compose

# ensure installed
docker-compose --version

# upgrade all upgradable packages
sudo apt-get upgrade -y

Then reboot with reboot 0, and log in again.

Configure your Auth0.com tenant

Tenant

  1. Go to Auth0.com and create an account.
  2. Create a "tenant", eg. my-shiny-staging

Application

  1. Create an Application (Regular Web App)
  2. Then in your App, set the following settings:
    • Token Endpoint Authentication Method: None
    • Allowed Callback URLs: mydomain.com/callback
    • Allowed Web Origins: mydomain.com, and the Domain listed on top of your App Settings.
    • Allowed Origins (CORS): same as previous
    • Allowed Logout URLs: mydomain.com or other domain you want to redirect to after logout
  3. The click SAVE CHANGES at the bottom of the page.

Connections

  1. Select Connections -> Social, and unselect Google.
  2. Select Connections -> Database, and Disable Signups.
  3. Go to Hosted Pages -> Customize Login Page, and add your logo in the JS if you like.

Create Users

  1. Go to Users -> and create your users manually.

All set!

  1. Your Auth0.com tenant is now ready. You'll paste info from this account into your Auth0 config further down in this manual.

Install mapic/shiny repository

Download with Git

cd /home/ubuntu/
git clone https://github.com/mapic/shiny.git
cd shiny

Configure

NginX

  1. Replace the server_name values with your domain in config/nginx.conf and config/nginx.certbot.conf.
  2. Replace the variables in the config/nginx.env file with your Let's Encrypt details.

Auth0

# copy the template 
cp config/auth0.env.default config/auth0.env

Then add your Auth0.com credentials to the config/auth0.env file. See the wiki for more information on Auth0 settings.

Shiny Server

  1. cp config/shiny.env.default config/shiny.env (Then add info if PRO only.)
  2. Optionally edit the config/shiny-server.conf. Defaults will work. See the offical documentation for details on configuration settings.

SFTP

# create config file with user/pass
echo "shiny:YOUR_PASSWORD_HERE:1001:100" > config/sftp.users.conf 

Docker

Create our named Docker network: docker network create shiny-network

Start/stop

Start Shiny Server

# start server
bash start-shiny.sh

Show logs

# show logs
docker-compose logs -f -t
# (use ctrl-c to exit logs and keep containers running)

Stop Shiny Server

# stop server
bash stop-shiny.sh

Upload data with SFTP

Use an SFTP program like Cyberduck, and connect with the following credentials:

Server: mydomain.com
Username: shiny
Password: my-password (from sftp.users.conf file above)
Port: 2222

Troubleshooting

Missing ENV files

Ensure the env_files listed in docker-compose.yml are actually available in the config/ folder.

ERROR: for sftp Cannot start service sftp: OCI runtime create failed

This is possibly due to missing config/sftp.users.conf file on first run, which caused the SFTP image to create wrong upload folder. If you get this on a fresh install and don't mind deleting containers, a quick fix is to simply delete all containers and volumes related to Shiny, then ensure the config file is present, and start the whole thing again.

Not allowed to write to /upload/ with SFTP

Possibly due to wrong owner of /upload/ folder. On a running Shiny Docker server, try:

docker exec -it shiny_shiny_1 chown 1001:www-data /srv/shiny-server/apps