The Internet of Things on AWS – Official Blog
Migrating Your WebRTC Application from Twilio to AWS: A Developer’s Guide
On December 5th, 2023 Twilio announced the End of Life (EOL) of their Programmable Video product. This abrupt offering discontinuation has forced many customers to explore alternative options for running smart camera or video streaming solutions. In this blog, we will highlight some considerations that customers can utilize as guidance to shape their migration strategy.
Scalability, depth and breadth of capabilities, and security implementation are critical parameters that will influence the design of your video streaming solutions and the applications built around it. Designing for long term reliability requires taking into consideration how your application will handle high traffic volumes and video quality. These are common challenges while delivering for range of devices through available Software Development Kits (SDKs). Therefore, when your existing technology requires code changes to lift-and-shift to new WebRTC technology, it should include a purpose-fit code migration strategy that addresses the previously mentioned challenges and provides comprehensive testing routine to frequently cross-check your migration progress.
Amazon Kinesis Video Streams, a managed cloud service that makes it easy for you to securely stream video from connected devices to AWS for analytics, machine learning (ML), playback, and other processing. It offers an ideal path for you to easily support and integrate near real-time video streams from connected cameras and similar devices for use cases, such as surveillance, live streaming, and video analysis. Moreover, Amazon Kinesis Video Streams integration with other AWS services allows you to extensively process and store large volumes of data, making it easy for you to migrate your existing solution with minimal disruption. In this blog, our example code will focus on helping you migrate your existing Twilio-based streaming solution to AWS with the help of Amazon Kinesis Video Streams. But, before we go further into the specific implementation with Amazon Kinesis Video Streams, it is critical that you learn about all the available options and make an informed choice aligned with your use case and business needs. Therefore, please read Choose the right AWS video service for your use case to familiarize yourself with all feasible options.
Twilio to Amazon Kinesis Video Streams Implementation
The code examples below provide a scenario where you may be replacing Twilio with Amazon Kinesis Video Streams with WebRTC functionality. It demonstrates basic WebRTC functionality with Twilio and replacing it with Amazon Kinesis Video Streams. This code doesn’t dive into many complexities of a real-world application, such as complete signaling logic, ICE candidate handling, and UI interaction. To get more familiar with the WebRTC protocols and Amazon Kinesis Video Stream signaling, please review some of the reference materials mentioned below.
- What Is Amazon Kinesis Video Streams with WebRTC
- Amazon Kinesis Video Streams with WebRTC: How It Works
- API reference
Prerequisites
-
- An AWS account
- Kinesis Video Streams service permissions via IAM role or IAM policy
- An EC2 instance or serverless ability to run NodeJS with Express would also be necessary to replicate the code examples.
Setting up a WebRTC Connection With Twilio
The source code below demonstrates Twilio API use for room creation, token generation and passing the security token to the client to allow connection to the room. Your use and classes may vary depending on your implementation. For the purpose of keeping this example simple, our main JavaScript class file is where these functions are defined.
The above function definitions facilitate acquisition of a new Twilio room or joining one if it already exists. Twilio utilizes JSON Web Tokens (JWT) to grant access to new or existing rooms. The JWT is generated from Twilio credentials then granted to the room. These server-generated tokens are then passed to clients to connect to a room.
Migrating to Amazon Kinesis Video Streams
The JavaScript source code below demonstrates using the AWS SDK to create an Amazon Kinesis Video Streams signaling channel for use. Again, our main JavaScript class file is where these functions are defined; however, you may desire to create new classes or file nomenclature to create new instantiations of Kinesis Video Stream clients. Producer and client applications require valid credentials to access Amazon Kinesis video streams. Though not demonstrated below, this can be achieved with temporary security credentials in IAM for your producer and client application access.
The aws-sdk provides the necessary libraries for your Amazon Kinesis Video Streams migration. It is useful and consistent beyond this use case for the aforementioned credential management for client application access. The JavaScript above creates a signaling channel. The signaling component manages the WebRTC signaling endpoints that allow applications to securely connect with each other for peer-to-peer live media streaming.
Server Side POST handling
The app.post Express routing examples below demonstrate a scenario where application HTTP POST calls can be modified to utilize the newly created Amazon Kinesis Video Streams signaling channels for your video needs. It is important to note that additional functions for ICE signaling will be required for peer connectivity.
Key Changes in the Migration
-
-
- Use of Async/Await: The example above makes use of async/await for better handling of asynchronous operations. This can improve application performance reducing the need for complex function callback chains.
- Signaling for WebRTC: The Amazon Kinesis Video Streams example acknowledges the need for additional WebRTC signaling code, which is a complex process involving creating offers, answering, and handling ICE candidates.
-
Conclusion
Transitioning to Amazon Kinesis Video Streams provides a robust platform for real-time video processing and analytics, suitable for scenarios like live streaming and surveillance. With its user-friendly features, AWS service integration and WebRTC capabilities, you only pay for what you use. Another option mentioned above in this blog could be migrating to Amazon Chime SDK, which offers an ideal solution for real-time communication needs, facilitating video/audio conferencing and collaborative platforms with its user-friendly features and AWS service integration. For further guidance or inquiries regarding this migration, please reach out to AWS Support or your AWS Account Team or submit an IoT Migration Request here.