Setup your own TURN/STUN signal/relay Server on AWS EC2

So you want to set up your own TURN/STUN server to handle signaling and relaying webRTC calls. Ok, I searched quite a bit and was finally able to build something. Took me hours so hopefully this can help you do it in 30 minutes!

We needed something simple for Mocha Video Chat

  1. Create an EC2 instance with Amazon Linux AMI 2 (CentOs) or Debian/Ubuntu

2. Configure AWS Security group (Incoming) and Firewall rules:

3. Install CoTurn

Note: on Debian/Ubuntu

Or you can build using the following steps which what you need to for Amazon Linux AMI or any distro that doesn’t include the turn server package

4. configure

Edit the configuration file. It’s usually in one the following locations based on your linux and installation:


Note: you can also search for it using the very useful search command

search / -name turnserver.conf

Note: you get your ec2 public address in the aws console in your ec2 instance details. You don’t nee the private address flag (-L). it can cause issues.

4. Run

5. Test

You can use Trickle to test your turn server once it’s running

Bonus: Once you tested your server, you want to use time-limited credentials. Very easy to implement and prevent unauthorized usage of your server. Also you can use Supervisor or Systemd to manage and monitor your TurnServer.

Hi! My name is Omid and I’m a remote work enthusiast