Introduction

In this article, I provide a step-by-step guide on how you can easily deploy your Rust application in the cloud with Amazon AWS EC2. Depending on your system requirements, you can deploy your application in the cloud to save you the hassle of managing the hardware infrastructure yourself so you can focus on what matters - your application and the customers they serve.

Prerequisites

I am assuming you already have an AWS account, if not please create one and login as root user. We will be using the AWS EC2 Free Tier t3.micro compute, as our virtual server in the cloud.

Step 1

After logging in as root to your AWS account, switch to the new view and nagivate to EC2 as shown in the screenshot below. Select Services, Compute and then click on EC2.

Step 2

Click on Launch instances as shown below.

Step 3

Under choose AMI, first check the Free tier only box on the left side of the window and then select any image. I selected Ubuntu Server 20.04 LTS image. You can experiment with any of the images.

Step 4

Make sure you select the t3.micro (it is the free tier instance type) and then click on Review and Launch then Launch. This will display a window asking you to select or create a key pair. Select the applicable option and then click on Launch Instance

Step 5

Give your virtual server a name. Mine is named server-01. Wait for your server to change Instance state to Running before you connect to it.

Step 6

Now, you can connect to your virtual server using PuTTy, Powershell, Bash (if you are using Linux), CMD or any client application that supports SSH. I am using PuTTy. To connect to the compute or virtual server, ssh to the Public IPv4 DNS address specified under the Details tab.

Step 7

The user name is ubuntu. The virtual server has access to the internet and you can install any package you need. Now, let’s install the Rust compiler.

Step 8

Install Rust and buid-essential (sudo apt install build-essential).

Step 9

We will be deploying two types of application on the virtual server - a telecoms application (a GTPv2-C server) and a web application based on the warp crate. GTPv2C protocol is used in the 3GPP based 3G, 4G and 5G networks for signaling and it uses port 2123 and the UDP transport protocol. We will configure our Rust GTP server to listen on UDP port 2123 in compilance with the 3GPP TS 29.274 (GTPv2-C) standard.

The web server will listen on TCP port 3030.

Configure the Inbound rules as shown below. AWS EC2 will apply these rules to our virtual server and it will allow our Rust applications to send and receive messages using these rules.

Step 10

Create your web server application using cargo new web_server and edit with nano as shown below. The original code is available here:https://github.com/seanmonstar/warp and it has been slightly modified for this tutorial. Run the web server with cargo run.

After this step, you will have two Rust applications running in the cloud. You can use the ps aux | grep target to check the two processes running (gtp and web_server)

Step 11

Open another PuTTy session and connect to the virtual server. Clone the GTPv2-C server from https://github.com/eshikafe/ngc and edit the ngc/common/gtp/src/main.rs so that the server listens and accepts conections from any IP address (i.e 0.0.0.0) as shown below. Run the application with cargo run

In the screen shot below, a simple Python script (the client) sends a message to the gtp server application using the Public IP address and port 2123. The script sends a GTPv2-C Create Session Request message from my Windows PC, through the internet, to the Rust GTPv2-C server application running in the cloud. This implies that you can deploy a telecom application (based on Rust) in the cloud to serve multiple devices concurrently and efficiently. The sample gtp application uses the tokio crate to achieve concurrency. Concurrency is a key requirement for a 4G/5G telecom server application.

Step 12

Lastly, open a web browser and paste the following URL in the address bar:{Public IPv4 DNS}:3030/hello/Rustacean. Replace Public IPv4 DNS with the domain assigned to your compute. You should see the message below.

You can also use curl to test your web server as shown below.

To deploy your applications securely in the cloud, you need to understand how the AWS EC2 security group works. Please read the AWS EC2 security group documentation before you deploy your application as a production system in the cloud.

Reference

AWS Tutorial for Beginners. Full Crash Course by Neal Davis