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.
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:
Verify the ECS Service created using the AWS Console:
Check the Target Group
aws elbv2 describe-target-health --target-group-arn $alb_tgr_arn
Access the ALB public DNS
aws elbv2 describe-load-balancers \
--load-balancer-arns $alb_arn \
--query 'LoadBalancers[0].DNSName' \
--output text
Check the application using the api
endpoint