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 setup our TURN server. CoTURN is an open source implementation of TURN server.
There is also an option to use Free and Paid TURN servers available
Free TURN SERVER Paid TURN Service
Open Relay Project Metered Video TURN Server
Pre-requisites
We need to have the follow 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
- login to your AWS console and
- On the EC2 dashboard click on the 'Launch Instance' button to launch an AWS instance
- choose the Debian or Ubuntu operating system
- Select the type of instance small or big depending on the TURN traffic that you anticipate (CPU, RAM and Bandwidth requirement vary based on your useage of the TURN server)
- Configure the security group to open necessory ports such as port 22 for ssh and port 3478 port 80 and 443 for CoTURN click on 'Review and Next'
- Review the settings and launch the instance
- then ssh into your instance and move to the 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
Step 2 : Connecting to the instance
- from the EC2 dashboard select 'Instances' from the left-hand corner and
- choose the instance that we created for the purposes of installing CoTURN and select that instance
- 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 srver 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
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
The plans for the Metered video TURN service starts from 99 USD /mo and here is the complete pricing table
Plan Name | Growth | Business | Enterprise |
---|---|---|---|
Price | 99 USD / mo | 199 USD /mo | 499 USD / mo |
Included TURN Usage | 150 GB / mo | 500 GB / mo | 2 TB / mo |
Overage Charges | 0.4 USD / GB | 0.2 USD / GB | 0.1 USD / GB |
Email Support | Yes | yes | yes |
Uptime | 99.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
- Installation
- Maintenance
- Instance limbo problems
- costs involved
- 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 TURN server on AWS is an expensive proposition.
TURN server require both a lot of compute power and bandwidth. Both of these things come at a significant costs 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 application but for running a TURN server is a complicated endeavour 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 a economical service they can turn to the FREE TURN server provided by the Open Relay Project
Note: This article was originally published on Metered Blog: AWS TURN server: In 7 Simple Steps
Top comments (0)