Tạo ECS Service

Tổng quan

Amazon ECS (Elastic Container Service) Service is a service that run and maintain a specified number of instances of a task definition simultaneously in an Amazon ECS cluster.

Creating ECS Service

Create an ECS service based on an existing task definition using the following commands:

ecs_service_name=$project-service
# Create Service
aws ecs create-service \
   --cluster $ecs_cluster_name \
   --service-name $ecs_service_name \
   --task-definition $ecs_task_arn \
   --desired-count 1 \
   --network-configuration "awsvpcConfiguration={subnets=[$ecs_instance_subnet_id],securityGroups=[$ecs_instance_sgr_id]}" 

aws ecs update-service --cluster $ecs_cluster_name \
    --service $ecs_service_name \
    --desired-count 1 \
    --load-balancers targetGroupArn=$alb_tgr_arn,containerName=`echo $ecs_task_definition | jq -r '.taskDefinition.containerDefinitions[0].name'`,containerPort=8080

Execution: Create ECS Service

Update ECS Service

Verify the ECS Service created using the AWS Console:

Create ECS Service

Checking Lab Results

  1. Check the Target Group

    aws elbv2 describe-target-health --target-group-arn $alb_tgr_arn
    

    Target Group check Healthy

  2. Access the ALB public DNS

    aws elbv2 describe-load-balancers \
        --load-balancer-arns $alb_arn \
        --query 'LoadBalancers[0].DNSName' \
        --output text
    

    Retrieve ALB DNS

  3. Check the application using the api endpoint

    Check Application