March 10th, 2023

Deploy a WAVE app on an AWS EC2 instance

RSS icon RSS Category: H2O Wave, Make with H2O.ai

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.

Create an EC2 instance.

  • Choose the name of the server
  • Choose the OS of the server. Ubuntu 22.04 LTS is selected in this guide.
  • Choose the Instance type of the server. This decision should be based on the resources (e.g. CPUs and RAM) the WAVE app is going to need. A good practice is to start small and then increase this based on resource utilisation. t2.micro is going to be used in this guide.
  • Choose the Key pair if you want to use an existing one or create a new one. In this guide, we create and download a new one. This will make the ssh connection to the server possible and secure.
  • Leave the Network settings as they are. In a next step, the ports that are required will be opened.
  • Add more storage if required by the WAVE app. Similarly to the instance type, a good practice is to start small and then increase the storage capacity based on the app’s needs.
  • Do not change any of the Advanced details and click Launch instance again.

Connect to the EC2 instance and install WAVE

  • Find the Public IPv4 address or the Public IPv4 DNS in the Details section of the EC2 instance.
  • ssh to the instance; you can do that by using using a terminal in Linux, MacOS or Putty in Windows.
# 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
  • To check that wave has been installed successfully we will continue by installing and running the h2o wave university capability.
# Install h2o wave university
$ pip install h2o_wave_university
# Run wave university
$ wave learn
  • The expected output is:
$ 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)
  • The next step is to open the relative port (WAVE’s default port is 10101) of the EC2 instance. On the page of the EC2 service under Security, click the Security group.
  • On the next page, select Edit inbound rules
  • Click Add rule
  • Select Type:Custom TCP, Port range10101, Source:Anywhere-IPv4, and Save rules
  • Now WAVE can be accessed on <Public IPv4 DNS>:10101, in the above example, this is: ec2–18–206–192–13.compute-1.amazonaws.com:10101
  • The app can be stopped by pressing ctrl+c in the terminal

Run a WAVE app

Run a WAVE app with a head start by using the wave init capability

  • Connect to the EC2 instance
# Connect to the instance
$ ssh -i my_WAVE_app_server_key.pem ubuntu@18.206.192.13
  • Create a new virtual environment or use an existing one (a virtual environment will probably already exists from the previous chapter when it was tested that WAVE was running).
# 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
  • Start wave init and select one of the available apps.
  • Access the app on <Public IPv4 DNS>: 10101, in the above example, this is: ec2–18–206–192–13.compute-1.amazonaws.com:10101
  • The code of the app created automatically by the wave init command is saved in a file called app.py.

Run a WAVE app from a GitHub repo

  • Connect to the ec2 instance and clone the repo
# 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 and create a virtual environment
# 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
  • Install necessary packages and run the app
# 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
  • Access the app on <Public IPv4 DNS>: 10101, in the above example, this is: ec2–18–206–192–13.compute-1.amazonaws.com:10101
  • The app can be configured to run on port 80 (default port used for HTTP) to omit the port in the URL
# 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
  • Access the app on <Public IPv4 DNS>, in the above example, this is: ec2–18–206–192–13.compute-1.amazonaws.com
  • Expected output:

Run a WAVE app with a custom code

  • Connect to the ec2 instance
# Connect to the instance
$ ssh -i my_WAVE_app_server_key.pem ubuntu@18.206.192.13
  • Create a directory where all the app-related files will be saved (in this example, it will just be the python script). Then enter the directory, create a new virtual environment, activate it and install h2o-wave
# 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 a python script containing the WAVE app’s code and save it
# 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
  • This is the expected output:
  • Save the code by pressing ctrl+x, then and enter.
  • Finally, the app is ready to be run.
# Run the wave app
$ wave run --no-reload todo
  • Access the app on <Public IPv4 DNS>: 10101/todo, in the above example, this is: ec2–18–206–192–13.compute-1.amazonaws.com:10101/todo
  • The app can be configured to run on port 80 (default port used for HTTP) to omit the port in the URL
# 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
  • Access the app on <Public IPv4 DNS>/todo, in the above example, this is: ec2–18–206–192–13.compute-1.amazonaws.com/todo
  • Expected output:

Other capabilities

About the Authors

Michelle Tanco

Michelle is a Product Manager at H2O focusing on the end-to-end experience of data becoming AI models and apps which drive business decisions. She's passionate about solving problems and helping to deliver the best solutions to customers and the open source community.

Greg Fousas

Greg is a data scientist with work experience that spans more than 20 projects, 15 brands, 5 industries and 5 countries and still counting! You could call him “the multi-tool” and please do, as he’s desperate for this nickname to catch on. He studied Production Engineering and Management, he has a MSc in Operational Research from the University of Edinburgh and studied a bit of Cognitive Science. Recently he completed a self driving car nanodegree. Greg also runs an amateur online Python course entitled “your 10 minutes of Python per day” and is happy to be able to call Scotland home. Due to an injury, this is the first time -since his toddler years- that Greg is not playing basketball. He’s channeling all this extra energy into his work projects. So beware!

Leave a Reply

AT&T panel: AI as a Service
+
AT&T panel: AI as a Service (AIaaS)

Mark Austin, Vice President of Data Science at AT&T joined us on stage at H2O

March 22, 2023 - by Liz Pratusevich
+
[Infographic] Healthcare providers: How to avoid AI “Pilot-Itis”

From increased clinician burnout and financial instability to delays in elective and preventative care, the

March 15, 2023 - by
+
How Horse Racing Predictions with H2O.ai Saved a Local Insurance Company $8M a Year

In this Technical Track session at H2O World Sydney 2022, SimplyAI's Chief Data Scientist Matthew

March 8, 2023 - by Liz Pratusevich
+
AI and Humans Combating Extinction Together with Dr. Tanya Berger-Wolf

Dr. Tanya Berger-Wolf, Co-Founder and Director of AI for conservation nonprofit Wild Me, takes the

March 1, 2023 - by Liz Pratusevich
+
Improving Search Query Accuracy: A Beginner’s Guide to Text Regression with H2O Hydrogen Torch

Although search engines are vital to our daily lives, they need help understanding complex user

February 28, 2023 - by
Blog header image with boats on it
+
What it means—and takes—to be at AI’s edge with Dr. Tim Fountaine

Dr. Tim Fountaine, Senior Partner at McKinsey & Company joins us at H2O World Sydney

February 23, 2023 - by Liz Pratusevich

Request a Demo

Explore how to Make, Operate and Innovate with the H2O AI Cloud today

Learn More