Skip to main content
Version: 2.12

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.

container-image

Step 1. Create AWS ECS Cluster

  1. Open the AWS Management Console:

    • Navigate to the Amazon Elastic Container Service (ECS).
  2. Create the Cluster:

    • Click ClustersCreate Cluster.

    aws-ecs-home-page

  3. Configure Cluster Settings:

    • Cluster name: ams-cluster-fargate
  4. Configure Infrastructure Settings:

    • Infrastructure: AWS Fargate (serverless).
  5. Review & create the cluster.

Step 2: Create Mongo Task Definition for MongoDB Container

  1. Go to Task Definitions in ECS.
  2. Click Create New Task Definition.
  3. Name the task definition (e.g., mongo-task-definition)
  4. 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 attach AmazonECSTaskExecutionRolePolicy, AWSMarketplaceMeteringRegisterUsage policies.
    • Select the ecsTaskExecutionRole under Task roles.

Check: Creating an IAM role.

  1. Add a Container:

    • Container Name: mongo-container
    • Image: mongo
    • Container port: 27017 TCP
  2. Review & create the task.

Step 3: Run the Mongo Task Definition

  1. In Clusters, select your cluster (e.g., ams-cluster-fargate).

  2. Navigate to the Tasks tab and click Run New Task.

  3. Environment:

    • Launch type: Fargate
    • Platform version: Latest
  4. Deployment Configuration:

    • Family: mongo-task-definition
    • Revision: Latest
  5. Networking:

    • VPC: Select a public VPC.
    • Subnets: Choose at least one.
    • Security Group: Allow 27017 TCP.
    • Public IP: Turned on.
  6. Review & Create the task.

  7. Once running, note the Private IP of the MongoDB container.

    image

Step 4: Create the Ant Media Server (AMS) node task definition

  1. Create a new task definition (similar to MongoDB).
  2. Name it ams-node-task-definition.
  3. Assign the ecsTaskExecutionRole.
  4. 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.
  5. 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.
  6. 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.

      image

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

  1. Go to EC2 Dashboard > Load Balancing > Target Groups.

  2. Go to Create Target Group.

  3. Configure:

    • Target type: IP addresses.
    • Target group name: origin-target-group.
    • Protocol: HTTP
    • Port: 5080
    • IP address type: IPv4.
    • Select a public VPC.
  4. Click Next.

  5. Review & Create the target group.

    image

Edge Target Group

  1. Go to EC2 Dashboard > Load Balancing > Target Groups.

  2. Go to Create Target Group.

  3. Configure:

    • Target type: IP addresses.
    • Target group name: edge-target-group.
    • Protocol: HTTP
    • Port: 5080
    • IP address type: IPv4.
    • Select a public VPC.
  4. Click Next.

  5. Review & Create the target group.

    image

Create an Application Load Balancer

  1. Go to EC2 Dashboard > Load Balancing > Load Balancers.

  2. Go to Create load balancer.

  3. Load balancer types: Application Load Balancer.

  4. Load Balancer Name: ams-load-balancer-fargate.

  5. Scheme: Internet-facing.

  6. Select the public VPC & AZs.

    image

  7. Security groups: Add a Security group that allows the ports 80, 5080, 443, and 5443.

  8. Listeners and routing: Add Listeners as forwarding 80, 443 to the origin-target-group and 5080, 5443 to the edge-target-group.

    image

  9. 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.

    image

  10. Review & Create the Load balancer.

Step 6: Create an ECS Service for Origin Nodes

  1. In ECS Clusters, select your ams-cluster-fargate cluster.

  2. Go to Services and click Create.

  3. Configure:

    • Launch Type: Fargate.

    • Task Definition: ams-node-task-definition.

    • Service Name: origin-service.

      image

  4. 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.

      image

  5. Load Balancer:

    • Choose the Application Load Balancer.

      image

    • Use the origin-target-group for HTTP/HTTPS listeners.

      image

  6. Service Auto Scaling:

    • Define min, max, and desired container numbers.

    • Add a CPU-based scaling policy.

      image

    • 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.

    image

  • Congratulations! The Cluster is created. You can also check the different services & their status in CloudFormation > Stacks.

    image

Access the Cluster

  • Go to the Load Balancer under EC2 Dashboard.

  • Use the Load Balancer DNS Name to access the cluster.

    image

  • The Origin Group is accessible via HTTPS on port 443

    image

  • The Edge Group is accessible via HTTPS on port 5443

    image

  • You can create DNS record to access the cluster securily over HTTPS.