How to run your rasa NLU Only server on Amazon Web Services

In the following I will show you how you run a rasa NLU Only server on aws.

How to run your rasa NLU Only server on Amazon Web Services

In the following I will show you how you run a rasa NLU Only server on aws. Please make sure that you have an aws account set up with all necessary configurations i.e. key pairs in your "~/.ssh" folder before you start coding. I also assume that you already have a rasa server running locally - if you don't have check this link: https://rasa.com/docs/rasa/nlu/using-nlu-only/.

To start log into your aws account and launch a new EC2 instance. For this we choose an Ubuntu Server 18.04 LTS (HVM), SSD Volume of the type "t2.small"(empfohlen ist größere aber wegen kosten small) - you can change the type of the instance later. Click button "Review and launch", create a new keypair or choose an existing one and wait until the instance is running.

When the instance is running, click on the instance and scroll down to the description and search for security groups. Click on "launch-wizard", then "inbound rules" and "edit inbound rules". Move on and create a custom TCP for ports 5000 and 5005 with the source "0.0.0.0/0".

You are now set up and ready to go. Connect to your instance with a right click and click connect. You will see an overview on how to connect to to your instance. Copy and paste the code that is written under "example:", open a new session in your terminal and paste the code.  

ssh -i "name_of_your_keypair.pem" name@ec2-XY-XY-XY....amazonaws.com

If you have issues with your keypair check this link: https://apple.stackexchange.com/questions/48502/how-can-i-permanently-add-my-ssh-private-key-to-keychain-so-it-is-automatically

When you are connected make sure you run:

sudo apt update 
sudo apt-get dist-upgrade

Note: At the time writing this article, rasa is not yet compatible with python 3.8. The server you chose only has python3.6 so we need to install python3.7 manually.

You then need to install pip3 first and after the installation is done tell pip3 that it should run with python 3.7. In the future there will be changes in versions so that you might have to change code here concerning version numbers.

sudo apt install python3.7-minimal
sudo apt install python3-pip
python3.7 -m pip install pip

sudo update-alternatives --install /usr/bin/python3 python3/usr/bin/python3.7 1

If there is an error run the following code:

cd /usr/lib/python3/dist-packages/
sudo ln -s apt_pkg.cpython-36m-x86_64-linux-gnu.so apt_pkg.so

You are set up to work with rasa now 🚀!

pip3 install rasa

Now you can copy your existing rasa model with:

scp -r path/to/your/rasa/model user@ec2-XY-XY.....amazonaws.com:

You can now train your model with the command:

rasa train nlu

Or run your rasa NLU Only server.

rasa run --enable-api --cors="*"

If you would close the ssh connection to your instance the server would stop running. If you want your server to keep running even if you stop the ssh connection you need to use "screen". Stop the running server and type the command:

screen

Now a new screen should open and you can start your server with the command you already know.

rasa run --enable-api --cors="*"

To exit the screen press: ctrl + a + d. You can now check if the server is still running:

screen -ls

If you would like to go back to the screen, stop the server or modify s.t. type:

screen -r screenname