Skip to main content

Scale AMS with AWS ECS Fargate

In this document, we’re going to explain how to setup a Scalable Ant Media Server Cluster in Amazon Web Services (AWS) ECS Fargate with Ant Media Server Container. If you are not familiar with Ant Media Server Cluster, you may check the introduction part of this to be familiar with the definitions and the components.

Please consider there will be two different "Cluster" word usage in this document. First one is Ant Media Server Scalable Cluster and we will use Ant Media Server Cluster to refer it. The other is the AWS ECS Cluster which is a logical grouping of tasks or services and we will use ECS Cluster to refer it.

Step 0. Register to Ant Media Server Container product

Step 1. Create AWS ECS Cluster

  • Open AWS ECS Service

  • Navigate Clusters

  • Click Create Cluster

  • Select Networking Only Type then click next

  • Write ams-cluster as cluster name then click create

Step 2: Create mongo task definition for MongoDB Container

  • Open AWS ECS Service

  • Navigate Task Definitions

  • Click Create New Task Definition

  • Select Fargate then click next

  • Write mongo-task-definiton as Task Definition Name

  • Create a role with name of ecsTaskExecutionRole and attach AmazonECSTaskExecutionRolePolicy, AWSMarketplaceMeteringRegisterUsage policies

  • Select ecsTaskExecutionRole as Task Role

  • In Task size Part set Task Memory 2 GB and Task CPU 1 vCPU

  • Click Add Container

  • Write mongo-container into Container Name, Write mongo into Image then click Add

  • In Task Definition Page click Create

Step 3. Run mongo task definition

  • Open AWS ECS Service

  • Navigate Clusters

  • Selec ams-cluster

  • Navigate Tasks tab

  • Click Run New Task

  • Select Fargate as Launch type

  • Select mongo-task-definition as Task Definition

  • In VPC and security groups Part

  • Select public VPC as Cluster VPC

  • Select at least one subnet from VPC

  • Edit Security Group as enabling 27017 TCP port

  • It should be like

  • Click Run Task

  • When task starts to work, copy the Private IP of Mongo Container

Step 4. Create AMS node task definition

  • Open AWS ECS Service

  • Navigate Task Definitions

  • Click Create New Task Definition

  • Select Fargate then click next

  • Write ams-node-task-definiton as Task Definition Name

  • Select ecsTaskExecutionRole as Task Role

  • In Task size Part set Task Memory 8 GB and Task CPU 4 vCPU

  • Click Add Container

  • Write

    • ams-container into Container Name,
    • 709825985650.dkr.ecr.us-east-1.amazonaws.com/ant-media/ant-media-server-ee:2.4.0.2 into Image
    • add 5080 TCP into Port Mapping

    • /usr/local/antmedia/start.sh,-m,cluster,-h, {Mongo Container IP} into Entry point then click Add
  • In Task Definition Page click Create

Step 5. Create Load Balancer

  • Create an origin-target-group from EC2 Load Balancing

  • Set Target Type IP, Port 5080, VPC the public VPC

  • Create an edge-target-group from EC2 Load Balancing

  • Set Target Type IP, Port 5080, VPC the public VPC

  • Create an Application Load Balancer

  • Add listeners for HTTP(S) 80, 5080, 443, 5443

  • Add Sertificate to ALB

  • Add Security group that allows the ports 80, 5080, 443, 5443

  • Configure routing using the previously created origin-target-group. Note that we will edit the routing after creation.

  • When it is created edit Listeners as forwarding 80, 443 to origin-target-group, 5080, 5443 to edge-target-group

Step 6. Create ECS Service for origin nodes

  • Open AWS ECS Service

  • Navigate Clusters

  • Selec ams-cluster

  • Navigate Services tab

  • Click Create

  • Select Fargate as Launch type

  • Select ams-node-task-definition as Task Definition

  • Write origin-service as Service Name

  • Click Next

  • In Configure network Page

    • Select public VPC as Cluster VPC
    • Select at least one subnet from VPC
    • Edit Security Group for Ant MediaServer

    • Select Application LoadBalancer
    • Add 80/443 Listener Ports and select origin-target-group

  • In Auto Scaling Page

  • Define min, max, desired number of containers

  • Add a CPU policy for scale in

Step 7. Create ECS Service for edge nodes

  • Follow Step 6 by changing all origin to edge and 80/443 to 5080/5443

Step 8. Test the structure

  • Access the login page http://Load-Balancer-URL:5080
  • Login to access to the dashboard
Share feedback