Scale AMS with AWS ECS Fargate
This document will explain how to set up a Scalable Ant Media Server Cluster in Amazon Web Services (AWS) ECS Fargate with the 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. The first one is Ant Media Server Scalable Cluster and we will use Ant Media Server Cluster to refer to 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 to it.
Step 0. Register for Ant Media Server Container Product
Ensure you have registered & subscribed to the Ant Media Server Enterprise container image on the AWS Marketplace.
Step 1. Create AWS ECS Cluster
-
Open the AWS Management Console:
- Navigate to the Amazon Elastic Container Service (ECS).
-
Create the Cluster:
- Click Clusters → Create Cluster.
-
Configure Cluster Settings:
- Cluster name: ams-cluster-fargate
-
Configure Infrastructure Settings:
- Infrastructure: AWS Fargate (serverless).
-
Review & create the cluster.
Step 2: Create Mongo Task Definition for MongoDB Container
- Go to Task Definitions in ECS.
- Click Create New Task Definition.
- Name the task definition (e.g.,
mongo-task-definition
) - Infrastructure requirements:
- Launch type: AWS Fargate.
- Operating system/Architecture: X86_64
- Set CPU & Memory as you need.
- Create an IAM role with the name of
ecsTaskExecutionRole
and attachAmazonECSTaskExecutionRolePolicy
,AWSMarketplaceMeteringRegisterUsage
policies. - Select the
ecsTaskExecutionRole
under Task roles.
Check: Creating an IAM role.
-
Add a Container:
- Container Name: mongo-container
- Image: mongo
- Container port: 27017 TCP
-
Review & create the task.
Step 3: Run the Mongo Task Definition
-
In Clusters, select your cluster (e.g., ams-cluster-fargate).
-
Navigate to the Tasks tab and click Run New Task.
-
Environment:
- Launch type: Fargate
- Platform version: Latest
-
Deployment Configuration:
- Family: mongo-task-definition
- Revision: Latest
-
Networking:
- VPC: Select a public VPC.
- Subnets: Choose at least one.
- Security Group: Allow 27017 TCP.
- Public IP: Turned on.
-
Review & Create the task.
-
Once running, note the Private IP of the MongoDB container.
Step 4: Create the Ant Media Server (AMS) node task definition
- Create a new task definition (similar to MongoDB).
- Name it
ams-node-task-definition
. - Assign the
ecsTaskExecutionRole
. - Infrastructure requirements
- Launch type: Fargate
- Operating system/Architecture: X86_64
- In the task size, set CPU & memory as needed. For AMS, using at least a 4-core CPU-optimized instance with 8GB RAM is recommended.
- Assign the
ecsTaskExecutionRole
.
- Add a container.
- Container Name: ams-container
- Image: Replace with your AMS container image (e.g., 709825985650.dkr.ecr.us-east-1.amazonaws.com/ant-media/ant-media-server-ee:2.11.3).
- Port Mapping: Add 5080 TCP.
- Docker configuration.
-
Entry point:
/usr/local/antmedia/start.sh,-m,cluster,-h,172.31.23.234
(replace the private IP address with your MongoDB container private IP address). -
Review & Create the task definition.
-
Step 5: Set Up Load Balancers
Now, we will create an application load balancer, to create a LB, one must create target groups.
Origin Target Group
-
Go to EC2 Dashboard > Load Balancing > Target Groups.
-
Go to Create Target Group.
-
Configure:
- Target type: IP addresses.
- Target group name:
origin-target-group
. - Protocol: HTTP
- Port: 5080
- IP address type: IPv4.
- Select a public VPC.
-
Click Next.
-
Review & Create the target group.
Edge Target Group
-
Go to EC2 Dashboard > Load Balancing > Target Groups.
-
Go to Create Target Group.
-
Configure:
- Target type: IP addresses.
- Target group name:
edge-target-group
. - Protocol: HTTP
- Port: 5080
- IP address type: IPv4.
- Select a public VPC.
-
Click Next.
-
Review & Create the target group.
Create an Application Load Balancer
-
Go to EC2 Dashboard > Load Balancing > Load Balancers.
-
Go to Create load balancer.
-
Load balancer types: Application Load Balancer.
-
Load Balancer Name:
ams-load-balancer-fargate
. -
Scheme: Internet-facing.
-
Select the public VPC & AZs.
-
Security groups: Add a Security group that allows the ports 80, 5080, 443, and 5443.
-
Listeners and routing: Add Listeners as forwarding 80, 443 to the
origin-target-group
and 5080, 5443 to theedge-target-group
. -
Default SSL/TLS server certificate: Choose a certificate for SSL to access the LB. For this cluster, we'll use a certificate from the ACM.
-
Review & Create the Load balancer.
Step 6: Create an ECS Service for Origin Nodes
-
In ECS Clusters, select your
ams-cluster-fargate
cluster. -
Go to Services and click Create.
-
Configure:
-
Launch Type: Fargate.
-
Task Definition: ams-node-task-definition.
-
Service Name: origin-service.
-
-
Networking:
-
VPC: Public VPC
-
Subnets: Choose at least one.
-
Security Group: Edit Security Group for the Ant Medi Server to allow the required server ports.
-
-
Load Balancer:
-
Choose the Application Load Balancer.
-
Use the origin-target-group for HTTP/HTTPS listeners.
-
-
Service Auto Scaling:
-
Define min, max, and desired container numbers.
-
Add a CPU-based scaling policy.
-
Review & Create the service.
-
Step 7: Create an ECS Service for Edge Nodes
Repeat Step 6 with:
-
Rename service to
edge-service
. -
Replace HTTP/HTTPS listeners with AMS ports (5080/5443).
-
Use edge-target-group for routing.
-
Congratulations! The Cluster is created. You can also check the different services & their status in CloudFormation > Stacks.
Access the Cluster
-
Go to the Load Balancer under EC2 Dashboard.
-
Use the Load Balancer DNS Name to access the cluster.
-
The Origin Group is accessible via HTTPS on port 443
-
The Edge Group is accessible via HTTPS on port 5443
-
You can create DNS record to access the cluster securily over HTTPS.