This article was originally published by Greg Fousas and Michelle Tanco on Medium and reviewed by Martin Turoci (unusualcode)
This guide will demonstrate how to deploy a WAVE app on an AWS EC2 instance. WAVE can run on many different OSs (macOS, Linux, Windows) and architectures (Mac, PC). In this document, Ubuntu Linux will be used.
This post uses several open-source WAVE apps, which can be found in the relevant links. The purpose of these apps is to help the user understand and learn WAVE (especially the learn/h2o_wave_university app/capability; see below)
The below instructions will create an EC2 server by using the default settings wherever possible. Different settings might be needed depending on the nature of the WAVE app.
In AWS console, select EC2 orsearch and select it from the search field.
Click Launch instance
On the next page:
This section walks the reader through connecting to the instance created above, installing the WAVE server, and testing accessing it.
# Be sure that you are in the directory where my_WAVE_app_server_key.pem is
# The below has to be run just the first time the key is used to change its permission
$ chmod 600 my_WAVE_app_server_key.pem
# Connect to the instance
$ ssh -i my_WAVE_app_server_key.pem ubuntu@18.206.192.13
# Update ubuntu packages list
$ sudo apt-get update
# Install python2-venv, alternatively conda could be used, see the above link for more details
$ sudo apt-get install python3-venv
# Create the python virtual environment
$ python3 -m venv venv
# Activate the environment
$ source venv/bin/activate
# Install WAVE in the python virtual environment
$ pip install h2o-wave
# Install h2o wave university
$ pip install h2o_wave_university
# Run wave university
$ wave learn
$ wave learn
2023/02/13 16:04:54 #
2023/02/13 16:04:54 # ┌────────────────┐ H2O Wave
2023/02/13 16:04:54 # │ ┐┌┐┐┌─┐┌ ┌┌─┐ │ 0.24.2 20221209122225
2023/02/13 16:04:54 # │ └┘└┘└─└└─┘└── │ © 2021 H2O.ai, Inc.
2023/02/13 16:04:54 # └────────────────┘
2023/02/13 16:04:54 # ┌──────────────────────────────────────┐
2023/02/13 16:04:54 # │ Running at http://localhost:10101/ │
2023/02/13 16:04:54 # └──────────────────────────────────────┘
2023/02/13 16:04:54 # {"address":"assets/","source":"./h2o_wave_university/static/","t":"public_dir"}
2023/02/13 16:04:54 # {"address":":10101","base-url":"/","t":"listen","web-dir":"/home/ubuntu/venv/www"}
INFO: Started server process [2081]
INFO: Waiting for application startup.
2023/02/13 16:04:55 # {"host":"http://127.0.0.1:8000","route":"/","t":"app_add"}
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
This section will walk the reader through various ways of creating a WAVE app, running it, and testing it is working.
wave init command picks predefined app templates that will bootstrap your first app and give you a head start when building your Wave apps.
# Connect to the instance
$ ssh -i my_WAVE_app_server_key.pem ubuntu@18.206.192.13
# If a virtual environment exists then just activate it
$ source venv/bin/activate
# Otherwise create a new one, activate it and install h2o-wave
$ python3 -m venv venv
$ source venv/bin/activate
$ pip install h2o-wave
To demonstrate this capability, the https://github.com/vopani/waveton repo will be used. This repo showcases 100 Wave applications on various data science and machine learning workstreams for beginners, intermediates as well as experts.
In particular, the https://github.com/vopani/waveton/tree/main/apps/skeleton_apps/basic_template will be used. The instructions given in the app’s link will be followed below.
# Connect to the instance
$ ssh -i my_WAVE_app_server_key.pem ubuntu@18.206.192.13
# Clone the repo
$ git clone https://github.com/vopani/waveton
# enter the app's directory
$ cd waveton/apps/skeleton_apps/basic_template
# Create a virtual environment and activate it
$ python3 -m venv venv
$ source venv/bin/activate
# Update pip and install packages from the requirements file
$ python3 -m pip install -U pip
$ python3 -m pip install -r requirements.txt
# Run the app
$ wave run --no-reload app
NOTE: the –-no-reload parameter is used to run the app without reloading to bring CPU utilization down.
# To run the WAVE app on port 80, sudo has to be used and the PATH and the env has to be passed.
# The port of the WAVE app is set by using the H2O_WAVE_LISTEN and the H2O_WAVE_ADDRESS parameters
$ sudo env "PATH=$PATH" H2O_WAVE_LISTEN=":80" H2O_WAVE_ADDRESS='http://127.0.0.1:80' wave run --no-reload app
NOTE: to run the app on port 80 remember to open the port the same way it is done in the Create an EC2 instance section
As an example app the code that is provided in WAVE’s documentation will be used. In particular, here: https://wave.h2o.ai/docs/tutorial-todo#step-8-add-to-do-and-return
# Connect to the instance
$ ssh -i my_WAVE_app_server_key.pem ubuntu@18.206.192.13
# Create a folder
$ mkdir my_app
# Enter the new directory
$ cd my_app/
# Create the python virtual environment
$ python3 -m venv venv
# Activate the environment
$ source venv/bin/activate
# Install WAVE in the python virtual environment
$ pip install h2o-wave
# Create the python script which will contain the WAVE app code. Create is with nano and then paste the code taken from the WAVE documentation page
$ nano todo.py
# Run the wave app
$ wave run --no-reload todo
NOTE: the –no-reload parameter is used to run the app without reloading to bring CPU
# To run the WAVE app on port 80, sudo has to be used and the PATH and the env has to be passed.
# The port of the WAVE app is set by using the H2O_WAVE_LISTEN and the H2O_WAVE_ADDRESS parameters
sudo env "PATH=$PATH" H2O_WAVE_LISTEN=":80" H2O_WAVE_ADDRESS='http://127.0.0.1:80' wave run --no-reload todo
NOTE: to run the app on port 80 remember to open the port the same way it is done in the Create an EC2 instance section
Other capabilities