A recipe for setting up a simple Shiny app on ECS.
📢 If you want to simply use my Docker image for testing, then you can skip this section and go straight to deploying.
Since this is for illustration purposes, I’m going to keep the app itself super simple, just using a slightly modified version of the “Old Faithful Geyser Data” template app,
We need to wrap this up in a Docker image. Here’s the
FROM rocker/shiny:4.1.0 # Install R packages. # RUN install2.r -e dplyr # Remove boilerplate. # RUN rm -rf /srv/shiny-server/ # Copy app. # COPY faithful.R /srv/shiny-server/app.R
Just to be sure that this works, we’ll build and run it locally. First build the image, giving it the name
docker build -t faithful .
Now run it. You should be able to access the app on http://127.0.0.1:3838/.
docker run --rm --name faithful -p 3838:3838 faithful
Once you’ve established that this runs locally, we can move onto deploying on ECS. If it doesn’t work locally, then ECS is going to be a whole world of pain.
There’s one final step, which is putting the image into a registry accessible from ECS.
These are the high level steps involved in deploying a Shiny app on ECS. Click through to the additional resources to see the details. Once you’ve been through this process once it should become somewhat intuitive, but the first time around it can be mysterious and challenging.
- Create an ECS cluster. See this post.
- Define an ECS task. See this post. Some specifics:
- task name:
- container name:
datawookie/faithful:latest(📢 Feel free to use this for testing!)
- port mappings:
- task name:
- Run the ECS task. See this post. Some specifics:
- security group: inbound traffic on port 3838 (see this post)
It should take a short while for the task to start running.
Once th task is RUNNING, click on the task ID (in this case 4859f33811ed4f06b6f7944234b48a3c) to see the task details.
You’ll see that there’s a public IP address listed (in this case 188.8.131.52).
Open that IP address in your browser, specifying port 3838.
So that’s how you get a basic Shiny app up and running on ECS. It’s functional but it’s not the end of the road. Next steps:
- Set the task up to run as a persistent service.
- Add a load balancer.
- Add an SSL certificate so that the app is accessible via HTTPS.
If you get stuck, have questions or comments, ping me.