Launching Flashphoner server in AWS Auto Scaling Group

jasonkc

Member
I would like to find out whats the best way to create auto scaling group in AWS to host Flashphoner instances behind a load balancer, questions like:

a) how to configure load balancer? Determine in flow request by port 8443?
b) How to apply license on scaled instances?
 

Max

Administrator
Staff member
Good day.
a) how to configure load balancer? Determine in flow request by port 8443?
Please read this article with step by step guide. Also read the details in this doc.
b) How to apply license on scaled instances?
You can apply the same license key to all the instances. If you're using AWS Marketplace AMI, it will be billed by Amazon itself for their own price. If you're using custom base image with your own license key, it will be billed according to running instances count as described here.
 

Max

Administrator
Staff member
Currently I hv a license that its renewly on monthly basis, can I apply that to all scalable instances?
Yes, you can apply your current license. But in this case you should use custom image, not Marketplace AMI.
 

jasonkc

Member
As I currently pointing to my single Flashphoner instance as the webrtc server in the exisitng JS file:

var URL = "wss://52.221.208.40:8443"

I just need to replace it with LB hostname right?

Also to use port 8443 in the LB protocol setting?
 

jasonkc

Member
I hv configured LB in AWS to forward http/https (port 80, 8443 and 8888) to webcallserver sitting in a auto scaling group, but how about RTMP traffic? How would it figure which server (if more than 1 in auto scaling group) to forward the RTMP traffic to?
 

Max

Administrator
Staff member
I hv configured LB in AWS to forward http/https (port 80, 8443 and 8888) to webcallserver sitting in a auto scaling group, but how about RTMP traffic? How would it figure which server (if more than 1 in auto scaling group) to forward the RTMP traffic to?
You can add 1935/TCP port forwarding to load balancer too.
But, if you want to know on which server the stream is published, you have to set up a separate backend server and use REST hook /publishStream to detect this. Then, you should pass to playing client the server address to connect.
 

jasonkc

Member
If I were to renew my license on monthly basis, whats the most effective way to ensure the newly launched instance (2nd and above) would start with the new license?
 

Max

Administrator
Staff member
1. Start first instance with monthly license.

2. Make a snapshot or launch template based on this instance.


3. Start your first, second, etc, instance.

There are two ways to check current license:

1. SSH

cd /usr/local/FlashphonerWebCallServer/bin
./activation.sh
Press CTRL+C to exit

It should print current license.

2. Admin UI.

Sign in as admin admin or as admin:{instance_id} to https://ec2-host:8444
Select License menu to check license number.

Example: https://demo.flashphoner.com/admin/license.html

1627397497356.png


3. Check Subscription License activity.

tail -f /usr/local/FlashphonerWebCallServer/logs/license.log

This log should show regular pings to License server.
Status should be success.
 

jasonkc

Member
but what about the next month when i renew the license? Its impractical to update the snapshot and template on monthly basis.
 

Max

Administrator
Staff member
but what about the next month when i renew the license? Its impractical to update the snapshot and template on monthly basis.
This is a bad approach to renew license every month. You should buy a monthly subscription which covers all your server instances and don't need to be renewed.
 

jasonkc

Member
I constantly encountering as issue when there are 2 EC2 instances sit behind LB - when I start a stream thru webRTC, its ended with stream not found; I suspect it is due to the fact that the websocket was established with instance 1, but the RTMP traffic (to port 1935) was sent to instance 2, how do I ensure RTMP traffic would be sent to the same instance (i did configure TCP port 1935 as listener in LBS, but I cant enable sticky bit for TCP connection)?
 

Max

Administrator
Staff member
Please clarify: do you publishing RTMP to WCS and playing it as WebRTC, or vice versa?
Anyway, in this case you should arrange a separate backend server and catch REST hooks /connect and /publishStream to detect on which server a stream is published. Then, you should send server IP address to client, and client should connect to the server by IP address (not to LB entry point) to play the stream.
Please read details about REST hooks here:
Type 1 - the connect method
Type 2 - the direct invoke
 
Last edited:

jasonkc

Member
From browser, I used the modified 'webrtc-as-rtmp-republishing.js' to connect to WebRTC server in instances behind the load balancer, then stream RTMP traffic to it; so with 2 and above instances behind LB, I notice the session would fail (presume the RTMP stream was send to wrong WebRTC server).
 

Max

Administrator
Staff member
From browser, I used the modified 'webrtc-as-rtmp-republishing.js' to connect to WebRTC server in instances behind the load balancer, then stream RTMP traffic to it; so with 2 and above instances behind LB, I notice the session would fail (presume the RTMP stream was send to wrong WebRTC server).
If you're republishing WebRTC stream as RTMP to the same server, use RTMP URL like this rtmp://localhost:1935/live/streamName. In this case, RTMP stream will always be published to the same WCS.
But if you want to connect to right WCS instance to play the stream published, you should use backend as we recommended above.
 

jasonkc

Member
Not republishing....what i meant is the WebRTC stream triggered from the browser seems to be forwarded to wrong EC2 instance behind LBS when there are 2 instances running behind.

For example, when a stream is started from web browser, and the websocket connection is to instance 1, but when I used ffmpeg to try to grep the stream from instance, it says the stream is not valid; thus I suspect the stream was actually sent to instance 2, causing the error.
 

Max

Administrator
Staff member
For example, when a stream is started from web browser, and the websocket connection is to instance 1, but when I used ffmpeg to try to grep the stream from instance, it says the stream is not valid; thus I suspect the stream was actually sent to instance 2, causing the error.
So, you publish WebRTC and play it as RTMP from server, right?
In this case, you should catch /connect and /publishStream REST hooks on your backend (as we recommenede above), get direct server instance ip from sessionId field, form RTMP link like rtmp://direct_instance_ip:1935/live/streamName and pass this link to ffmpeg by any possible way.
 
Top