Try Live Demo

Cluster Setup is the hot topic for us for a while. Yeah we know that there is a blog post that tells how to setup scalable ultra low latency streaming cluster in Amazon Web Services (AWS)  which shows the each step with screenshots to make everyone install Ant Media Server Cluster in AWS. It’s good to understand what’s under the hood at first. What about for the second time? Third or fourth times? Ooo my gosh, it becomes very boring to do the same things.

cluster setup easy way

Luckily, we have a solution right now.  You can install the all components (MongoDB, Origin Auto Scaling Group, Edge Auto Scaling Group, Load Balancer ) in your cluster with just one-click. To be honest, it’s for one-command with AWS Command Line Interface (CLI)

Let’s first install required softwares to run our one-click

Pre-requests

AWS CLI Installation

AWS has already provided lots of documentation for CLI. Please follow the Installation guide here. For convenience, we also explain how to install aws cli for ubuntu.

Install pip

Get installation script with curl.
$ curl -O https://bootstrap.pypa.io/get-pip.py

Run the script to install pip.
$ python3 get-pip.py --user

Make sure that pip3 is on your path.
$ export PATH=~/.local/bin:$PATH

Check pip3 is working as expected. Below command should write pip3 version to the terminal.
$ pip3 --version

Install the AWS CLI with pip

Use pip to install AWS CLI.

pip3 install awscli --upgrade --user

Verify that AWS CLI is installed.

aws --version

cluster setup aws

Configure the AWS CLI

In order to configure AWS CLI, we need to have Access Key and Access Secret Key. In order to create Access Key and Access Secret Key.

  1. Sign into IAM console https://console.aws.amazon.com/iam/.
  2. Choose Users in the navigation pane
  3. Click “Add User”
  4. Choose a username
  5. Select only Programmatic Access
  6. Click Next
  7. Choose “Attach existing policies directly”
  8. Write “AmazonEC2FullAccess” in the filter and select the  “AmazonEC2FullAccess” checkbox in the result pane
  9. Click Next and fill the optional entries if you wish
  10. At last “Create the User”

In the last step you will have Access Key and Secret Access Key . You can also download the CSV for these parameters. Keep in mind that Secret Access Key will not be visible after this stage.

Run the command for configure the AWS CLI

$ aws configure
AWS Access Key ID [None]: {YOUR_ACCESS_KEY}
AWS Secret Access Key [None]: {YOUR_SECRET_KEY}
Default region name [None]: {YOUR_DEFAULT_REGION}
Default output format [None]: json

Region names are available in here. We use us-east-1 for our sample.

Instal jq

jq is a JSON processor tool. Install it with apt-get.

sudo apt-get install jq

One-Click Cluster Setup

Get the installation script with wget.
wget https://raw.githubusercontent.com/ant-media/Scripts/master/aws_cluster_install/aws-ams-cluster-install.sh

Make the script executable.

chmod 755 aws-ams-cluster-install.sh

Here is the Cluster Setup with one command. But please get your SSL Certificate ARN for the load balancer with your domain name. We highly recommend using this parameter. Because web browsers only allows secure(https) web pages to access the camera and microphone for publishing streams. To learn more about how to get Certificate ARN, please visit our blog post about Get SSL Certificate on AWS ACM  and for further information visit AWS ACM documentation

./aws-ams-cluster-install.sh -c {CERTIFICATE_ARN}

If everything is installed properly, It means that MongoDB Instance, Origin Group, Edge Group and Load Balancer are installed.

Publishing Streams

So that you can visit https://DOMAIN_NAME:5443/WebRTCAppEE  to publish WebRTC streams

Playing Streams

In order to play streams, please visit https://DOMAIN_NAME/WebRTCAppEE

Please note that we use 5443 for publishing. We use 443 (default port for https) for playing because 5443 is forwarded to the origin group and 443 is forwarded to the edge group.

Uninstalling Cluster

If you want to uninstall the cluster, you can run the following command in the same directory where you run install script.

./aws-ams-cluster-install.sh -t uninstall

After that your components are deleted. Please also check that everything is deleted on your AWS EC2 Management Console as well.

Options

Right now, let’s look the options of the script.

./aws-ams-cluster-install.sh [-i AMI_ID] [-u UBUNTU_AMI_ID] [-y true|false] [-t install|uninstall] [-c CERTIFICATE_ARN]

Parameters:
-i AMI_ID: Optional. Amazon Machine Image Id of the Ant Media Server Enterprise, you can prepare your own AMI. If not set, it tries to get the Ant Media Server AMI from AWS Marketplace
u UBUNTU_AMI_ID: Optional. Ubuntu 16.04 AMI ID for installing MONGODB. If not set, try to get find an AMI from AWS Marketplace
-y true|false: Optional. Default value is false.  “true” is for headless install. It’s good for using in automation. “false” is for interactive install.
t uninstall|install:  Optional. Default value is install. Type of the operation. “uninstall” uninstalls and  delete the components  in the cluster. “install” installs the Cluster with all components.
-c CERTIFICATE_ARN: Optional. ARN(Amazon Resource Name) of the SSL Certificate in AWS ACM (Amazon Certificate Manager). It’s used for binding secure connections (https and wss). It’s highly recommended to use

Advance Cluster Configuration

After installation you can configure every parameter in your cluster components. If you are just creating automation and want to configure the things in advance. You can open the aws-ams-cluster-install.sh file in your editor and configure the each parameter. You will see  parameters with the definitions from “names” of the components to the “instance types”. All parameters are at the top section of the file. Just take a look at the parameters and tune your cluster in advance.

I hope this script will make life easier for some of us. Please send an e-mail to the contact@antmedia.io if you have any questions.

Categories: Tutorial

Ahmet Oguz Mermerkaya

Oguz is the co-founder of Ant Media. His tech stack includes VxWorks, UML, Rhapsody in C++. Java, OSGi, Swing, JSF, Web, PHP, FFmpeg API, Native WebRTC, Java EE, Hibernate, Spring, MongoDB, MySQL, Angular, JavaScript, HTML5, Android (Native) and iOS (Native). Oguz is one of the writers of "Merhaba Android", one of the first books published in Turkey about Android app programming. His second book is about HTML5 & CSS3. He has attended several conferences and universities talking about Android, business life and technical issues. He is a member of the GDG Community and also the founder of GDG Ankara.

chatsimple