Looking for good programming challenges?

Use the search below to find our solutions for selected questions!

How to Install and Run Local TURN Server on AWS for WebRTC

Traversal Using Relays around NAT (TURN) is a protocol that assists in traversal of network address translators (NAT) or firewalls for multimedia applications. For most WebRTC applications to function a server is required for relaying the traffic between peers, since a direct socket is often not possible between the clients (unless they reside on the same local network). The common way to solve this is by using a TURN server. There are currently several options for TURN servers available online, both as self-hosted applications (like the open-source COTURN project) and as cloud provided services. In this article I describe how to setup your own TURN server on your AWS instance. Below are the steps.

Step 1

wget https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz tar xvfz libevent-2.1.8-stable.tar.gz
cd libevent-2.1.8-stable ./configure
make sudo make install

Step 2

Go to Coturn and download the latest version. I used turnserver-4.5.0.7.tar.gz.
wget http://coturn.net/turnserver/v4.5.0.7/turnserver-4.5.0.7.tar.gz tar xvfz turnserver-4.5.0.7.tar.gz
cd turnserver-4.5.0.7 export LDFLAGS=-L/usr/local/opt/openssl/lib
export CPPFLAGS=-I/usr/local/opt/openssl/include ./configure
make make install

Step 3

Setup TURN server users (for more info see Coturn Wiki).
sudo turnadmin -a -u admin -r rtcrandom -p s3cret sudo turnadmin -A -u admin -p s3cret

Step 4

Start the server as a daemon (Note STUN requires username and password otherwise it will reject any requests!)
$ screen -S "coturn" -dm turnserver -u 'rtcrandom:s3cret' -v -n  -p 3478 -L 172.31.25.195 -r rtcrandom -X 35.158.16.195\172.31.25.195  --no-dtls --no-tls