AWS TURN server: In 7 Simple Steps

AWS TURN server: In 7 Simple Steps

In this article, we will learn how to setup and run a TURN server in AWS in 7 simple steps

TURN servers are used in NAT traversal and are essential in WebRTC and VoIP communications

We will be using CoTURN to set up our TURN server. CoTURN is an open source implementation of the TURN server.

There is also an option to use Free and Paid TURN servers available

Free TURN SERVERPaid TURN Service
Open Relay ProjectMetered Video TURN Server

Pre-requisites

We need to have the following to start building a TURN server in AWS

  • An AWS account

  • Basic Knowledge of how to create an EC2 instance and command line tools

  • Some basic Knowledge of concepts like IP address and protocols

Step 1: Creating an AWS Instance

We need to create an AWS instance to be able to install the coturn to it

  1. login to your AWS console and

  2. On the EC2 dashboard click on the 'Launch Instance' button to launch an AWS instance

  3. choose the Debian or Ubuntu operating system

  4. Select the type of instance small or big depending on the TURN traffic that you anticipate (CPU, RAM and Bandwidth requirements vary based on your usage of the TURN server)

  5. Configure the security group to open necessary ports such as port 22 for ssh and port 3478 ports 80 and 443 for CoTURN click on 'Review and Next'

  6. Review the settings and launch the instance

  7. then ssh into your instance and move to step 2

What is Open Relay Project?

Open Relay is a free TURN server provided by Metered Video that you can use in your WebRTC applications. The Open Relay TURN server is highly available, reliable and offers both STUN and TURN Capabilities.

The Open Relay runs on port 80 and 443 to bypass corporate firewalls, many corporate/enterprise firewall only allow port 80 or 443, it also supports turns + SSL for maximum compatibility.

  • ✅ Runs on port 80 and 443

  • ✅ Tested to bypass most firewall rules

  • ✅ Enterprise grade reliability (99.999% uptime)

  • ✅ Support TURNS + SSL to allow connections through deep packet inspection firewalls.

  • ✅ Support STUN

  • ✅ Supports both TCP and UDP

  • ✅ Dynamic routing to the nearest server

  • ✅ Production Ready

Signup for free account

Step 2 : Connecting to the instance

  1. from the EC2 dashboard select 'Instances' from the left-hand corner and

  2. choose the instance that we created to install CoTURN and select that instance

  3. Follow the instructions to ssh to the server from your local machine

Step 3 : Update the server

When you are able to connect to the server, update and upgrade all its packages by running the below command

sudo apt update
sudo apt upgrade

Step 4: Installing CoTURN

Once we have installed and updated all the packages. Now it's time to install the CoTURN

Type the below command to install CoTURN

sudo apt install coturn

Step 5: Configuring CoTURN

open the configuration file of the CoTURN that you have just installed

cd coturn

sudo nano /etc/turnserver.conf
  1. then uncomment the following fields by removing the # before them
listening-port=3478
fingerprint
lt-cred-mech
use-auth-secret
static-auth-secret=YOUR_SECRET_KEY
realm=your-domain.com
total-quota=100
bps-capacity=0
stale-nonce
no-loopback-peers
no-multicast-peers

Replace 'YOUR_SECRET_KEY' with a secure key of your own and 'your-domain.com' with your domain and save the file

2. Enable CoTURN on boot by going to

and opening the file

sudo nano /etc/default/coturn

uncomment the 'TURNSERVER_ENABLED=1' and save the file

Step 6: Starting the CoTURN server

you can now start the CoTURN server by using the below command

sudo systemctl enable coturn

Step 7: Verify the CoTURN server is working

type the below command to verify if the coturn server is working on or not

sudo systemctl status coturn

You will see a message that the CoTURN is running

Bonus: Open Relay Project

While running on AWS is a good idea. You can also use the Free TURN server provided by the Open Relay project

you can create an account for the open relay project here

Open Relay: Free WebRTC TURN Server

the server provided by the Open Relay Project has the following features

The Open Relay runs on port 80 and 443 to bypass corporate firewalls, many corporate/enterprise firewall only allow port 80 or 443, it also supports turns + SSL for maximum compatibility.

  • ✅ Runs on port 80 and 443

  • ✅ Tested to bypass most firewall rules

  • ✅ Enterprise grade reliability (99.999% uptime)

  • ✅ Support TURNS + SSL to allow connections through deep packet inspection firewalls.

  • ✅ Support STUN

  • ✅ Supports both TCP and UDP

  • ✅ Dynamic routing to the nearest server

  • ✅ Production Ready

Bonus: Paid TURN Server by Metered Video

Metered Video also provides a TURN server service that is paid. You can use this service if you want a paid TURN service for your application

Metered WebRTC Turn Server Provider

The plans for the Metered video TURN service start from 99 USD /mo and here is the complete pricing table

Plan NameGrowthBusinessEnterprise
Price99 USD / mo199 USD /mo499 USD / mo
Included TURN Usage150 GB / mo500 GB / mo2 TB / mo
Overage Charges0.4 USD / GB0.2 USD / GB0.1 USD / GB
Email SupportYesyesyes
Uptime99.999%99.999%99.999%

You can sign up for Metered TURN service here:

Bonus: Costs and Considerations involved when running an AWS TURN Server

Here are considerations when running your own TURN server on AWS

  1. Installation

  2. Maintenance

  3. Instance limbo problems

  4. costs involved

  5. allocation of resources

1. Installation: Installation is an issue. You need to install your own turn server on aws. AWS does not offer pre built TURN server.

Installing the CoTURN is a difficult task and needs a lot of know how and technical expertise

while using the Open Relay Project is pretty easy and free to use. You can also consider using Metered Video TURN server which is a paid server but has additional features like 99.999% Uptime and email support.

2. Maintenance : One of the major issues when running your own TURN servers is maintenance. Once you have installed the TURN server your work is not done

You still need to maintain all the dependencies and have a look at the resources to ensure that the TURN server is working as it should

Another option is to use the free Open Relay Project, where there is no need to worry about maintenance.

You can also prefer the Metered TURN server which is a paid service that comes with additional features like 99.999% Uptime and email support.

3. Instance Problems : One of the major problems with cloud providers in general and AWS in particular is that the instance goes into limbo and just hangs. The only solution when this happens is to start the instance and face downtime

One of the ways to mitigate this problem is to use the Open Relay Project's Free TURN server or

the Metered Video TURN server which is a paid service but comes with additional features like 99.999% Uptime and email support.

4. Costs Involved: Running a TURN server on AWS is an expensive proposition.

TURN servers require both a lot of computing power and bandwidth. Both of these things come at a significant cost when purchased from AWS.

Plus there is the headache of running the TURN server and maintaining it.

You can easily use the Open Relay Project's Free TURN server or

the Metered Video TURN server which is a paid server but comes with a added features like 99.999% Uptime and email support.

Conclusion

AWS is an awesome resource for building applications but for running a TURN server is a complicated endeavor that can be done for learning purposes

But for production use getting a professional service like Metered TURN server is recommended

Even for casual use or for startups that need an economical service they can turn to the FREE TURN server provided by the Open Relay Project

Note: This article was originally written on the Metered Blog: AWS TURN server: In 7 Simple Steps