Create an Amazon ECS Service

Once you completed the Amazon ECS Task Definition, you are ready to create an Amazon ECS Service.

Select the ECS cluster that you created earlier, click the Services tab and then Create button.

create-service

Step 1: Configure service

In the Create Service wizard, follow the below configuration (make sure you select FARGATE in the Launch type).

  • Select the Task Definition that you created earlier
  • Select the Platform version 1.4.0
  • Select the ECS Cluster that you created earlier and enter the Service name (e.g. unicorns-svc)
  • Set Number of tasks to 2
  • Leave the default for the remaining and click Next step

configure-service

Step 2: Configure network

In the network configuration, select the VPC that you created earlier and specify your subnets and ECS-Tasks-SG in the security group.

configure-network-svc

svc-lb

Select Application Load Balancer in the load balancer type, and choose the load balancer that you created earlier.

container-lb

Click Add to load balance to add the container name:port

container-lb-details

service-discovery In the Service discovery (optional) section, uncheck the “Enable service discovery integration” and press [Next step]

Step 3: Set Auto Scaling

In Auto Scaling configuration, select Configure Service Auto Scaling and specify the minimum, desired, maximum number of tasks.

svc-autoscaling svc-autoscaling-policy

In the Automatic task scaling policies, set the scaling policy type to Target Tracking, provide name of the scaling policy (e.g. Requests-policy), select the service metric (e.g. ALBRequestCountPerTarget) and then set the Target value (e.g. 300).

You can repeat that for different service metric (e.g. CPU and Memory utilization).

Step 4: Review

Finally, Review and click Create Service to create the Amazon ECS Service.

Once the Service status is in Active state and all the tasks are in the Running state, browse to the target web site using the loadbalancer DNS.

You might also need to configure autoscaling for the ECS nodes, check the this guide for more details

In case you encounter any issues, Please check Amazon ECS Troubleshooting guide