Building a SIP Calling Lab on AWS: Talking Between My Phone and Laptop Through the Cloud
I wanted to actually understand SIP, not just read about it. So I set myself a hands-on goal: run my own SIP server in the cloud and make a real voice call between my phone and my laptop, with the audio flowing through that server. This post is the full story, including the dead ends I hit, because the mistakes taught me more than the happy path did. What you'll have at the end: one small AWS EC2…
The author sought to gain practical experience with SIP (Session Initiation Protocol) by setting up their own SIP server in the cloud and making a real voice call between their phone and laptop. This post details the entire process, including the obstacles encountered along the way. The essential elements of the setup include:
1. A small AWS EC2 instance running Kamailio (the SIP server) and rtpengine (the audio relay).
2. Two softphones registered to the server.
3. Successful two-way communication between the softphones.
To grasp SIP, it is essential to understand that it is merely the signaling component of a call and doesn't carry the voice. Instead, audio travels via a separate protocol called RTP on a distinct set of ports. This distinction is critical, as it is the root cause of the majority of problems people face when working with SIP.
The system comprises three main components:
1. A server (registrar/proxy) that knows where everyone is and routes calls (Kamailio in this setup).
2. Clients (softphones) with microphones and speakers, residing on devices equipped with audio hardware (like the author's phone and laptop).
3. A cloud server (EC2 instance) that lacks a microphone and cannot capture audio.
The author eventually moved from using Windows Subsystem for Linux (WSL) to AWS due to the complications of WSL, such as NAT and port forwarding issues. An AWS EC2 instance provided a more straightforward and reliable environment for the lab.
Step-by-step guide:
1. Launch an Ubuntu 24.04 EC2 instance with a sufficient amount of resources (e.g., t3.small).
2. Open the necessary ports in the AWS Security Group:
- All UDP (covers SIP 5060 and RTP media range in one rule).
- Custom TCP (TCP 5060) for SIP fallback if UDP is blocked.
- SSH (TCP 22) for remote access to the instance.
3. Install Kamailio and rtpengine on the EC2 instance:
- Run the commands: `sudo apt update`, `sudo apt install -y kamailio kamailio-extra-modules sqlite3`, and `sudo apt install -y rtpengine`.
4. Configure rtpengine (NAT fix) by editing the `/etc/rtpengine/rtpengine.conf` file:
- Set `interface = 172.31.42.238!52.91.109.231 port-min = 10000 port-max = 20000`.
5. Point the control tool at the database using DBTEXT, a flat-file database:
- In `/etc/kamailio/kamctlrc`, set `SIP_DOMAIN = 52.91.109.231`, `DBENGINE = DBTEXT`, and `DB_PATH = /etc/kamailio/dbtext`.
6. Enable required features in `kamailio.cfg`:
- Uncomment lines `#!define WITH_AUTH`, `#!define WITH_USRLOCDB`, `#!define WITH_NAT`, `#!define WITH_RTPENGINE`, and `#!define DBURL text:///etc/kamailio/dbtext`.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.