AWS ECS Service

Saakshi Priya
8 min readJul 6, 2023

--

You can simply deploy, manage, and scale containerized applications with Amazon Elastic Container Service (Amazon ECS), a fully managed container orchestration service. Amazon ECS is a fully managed solution that includes built-in AWS configuration and operational best practises. It is integrated with both AWS and outside programmes like Docker and the Amazon Elastic Container Registry. Teams may more easily concentrate on developing the apps rather than the environment thanks to this connection. Without the hassle of controlling a control plane, you can run and expand your container workloads across AWS Regions both on-premises and in the cloud.

Setup of ECS Service in AWS:

STEP 1: CREATE A TASK DEFINITION:

WHAT IS A TASK DEFINITION?

A task definition is a blueprint for your application. It is a text file in JSON format that describes the parameters and one or more containers that form your application.

The following are some of the parameters that you can specify in a task definition:

  • The Docker image to use with each container in your task.
  • How much CPU and memory to use with each task or each container within a task.
  • The launch type to use, which determines the infrastructure that your tasks are hosted on.
  • The Docker networking mode to use for the containers in your task.
  • The logging configuration to use for your tasks.
  • Whether the task continues to run if the container finishes or fails.
  • The command that the container runs when it’s started.
  • Any data volumes that are used with the containers in the task.
  • The IAM role that your tasks use.

A Task Definition consists of one or more container definitions, each representing a single container within the task. This allows you to define and manage multi-container applications within ECS.

You can run a task definition as a task or a service after you’ve created it.

  1. Within a cluster, a task is the instantiation of a task definition. The quantity of tasks that will operate on your cluster can be specified once you build a task description for your application within Amazon ECS.
  2. Your specified number of tasks are run and maintained simultaneously by an Amazon ECS service in an Amazon ECS cluster. The Amazon ECS service scheduler launches a new instance according to your task specification if any of your tasks fail or halt for any reason. In order to keep the desired number of jobs in the service, it performs this to replace it.

STEPS TO CREATE TASK DEFINITION:

  1. Open the ECS service after logging into the AWS Management Console.

2. In the left sidebar of the ECS console, select “Task Definitions”.

3. Select “Create new Task Definition” from the menu.

4. Depending on your needs, choose either the EC2 or Fargate launch type compatibility. Simply select “Next step.”

5. Depending on the launch type compatibility option selected, select either the Fargate or EC2 task description type. Give your task definition a name and an optional description. Simply select “Next step.”

6. Set up the definitions for the job and container:

— Indicate the amount of CPU and memory your task will need under “Task size.”
— To specify your container settings, click “Add container” under “Container Definitions.”
— Name the container specifically.
— the container image, please. You may utilize an image from Amazon ECR, Docker Hub, or another container registry.— Set up environment variables, port mappings, resource restrictions for containers, and other parameters as necessary.
— Add any container dependencies that are required, like linking one container to another.
— By selecting “Add container” once more, you can add any other containers.
— Depending on your needs, change other parameters for networking, storage, logging, and IAM roles.

— Additionally, you can specify roles for job execution and container health checks.
— Examine your task definition, then click “Create” to produce it.

You can utilize the task definition after it has been built to execute tasks within an ECS cluster. When executing the tasks, you can provide the desired task count and launch method (EC2 or Fargate). It’s vital to keep in mind that depending on your unique requirements, launch type, and AWS services you are using, the precise stages and options may change. Be sure to consult the AWS documentation for comprehensive guidelines and recommended procedures when building Task Definitions in ECS.

NOTE: Enter the image that you want to use to start a container here for the image URI. Only the Amazon ECR Public registry name may be used to specify images in the Amazon ECR Public Gallery registry. The Amazon Linux container stored on the Amazon ECR Public Gallery is used, for instance, if public.ecr.aws/ecs/amazon-ecs-agent:latest is supplied. Use the repository-url/image:tag or repository-url/image@digest formats to indicate the repository for all other repositories.

STEP 2: CREATE ECS CLUSTER:

WHAT IS ECS CLUSTER?

An ECS cluster in AWS ECS (Elastic Container Service) is a logical collection of EC2 instances or Fargate jobs where your containerized applications can operate and be managed. It offers a highly available architecture that is scalable for operating containers.

Tasks (containers) can be planned and carried out within an ECS cluster as a pool of resources. It handles task distribution and scaling across the cluster as well as managing the underlying compute instances or Fargate infrastructure.

STEPS TO CREATE ECS CLUSTER:

  1. Open the ECS service after logging into the AWS Management Console.
  2. In the left sidebar of the ECS console, select “Clusters”.

3. Select “Create Cluster” from the menu.

5. Based on your needs, choose the cluster template:

— “EC2 Linux + Networking” to build a Linux-based cluster on an EC2-based platform.
— “Fargate” if you wish to use Fargate to build a serverless cluster.
— Select “Custom” to configure more complex options.

5. Give a name for the cluster and an optional description.

6. Adjust the cluster settings to suit your needs:
Choose the EC2 instance type and required capacity (number of instances) for EC2-based clusters.
— Set up your network’s subnets, security groups, and VPC.
Indicate the capacity provider and Fargate launch type version for clusters based on Fargate.

— Set up security and networking groups.

7. You can choose to enable cluster auto scaling, which will automatically increase or decrease the number of tasks or instances based on CPU usage or other configurable parameters.

8. After checking your cluster settings, press “Create” to start the ECS cluster.

STEP 3: CREATE A SERVICE IN CLUSTER

  1. Click on the Cluster name.
  2. Scroll down and click on “Services” tab and click on “Create” button.

3. Specify the “Task definition” in the “Family” textbox and specify the name of the service, number of desired tasks, subnets, security groups (either create a new security group or use an existing one), and then click on Create.

4. Click on “Tasks” tab to view the number of tasks running.

NOTICE: You can run containers using AWS Fargate and Amazon ECS without needing to manage servers or clusters of Amazon EC2 instances. You no longer need to provision, set up, or grow clusters of virtual machines to host containers thanks to AWS Fargate. This eliminates the need to decide on server kinds, whether to grow your clusters, or how to best pack your clusters.

You package your application in containers, establish the CPU and memory requirements, define networking and IAM controls, and launch the application when you run your tasks and services using the Fargate launch type. Each Fargate task has its own isolation border and does not share the elastic network interface, CPU, memory, or other resources with other tasks.

Step 4: Keep an eye on and control the container

— Once the task has begun, you may check the ECS service interface to see its status and logs.
— Additionally, you may see metrics at the container level, create alarms, and, if necessary, manage scaling and load balancing.
— You can modify the task specification and redeploy the task to run a new version of the container or update the job definition.
— Note: If you are utilizing private container images, make sure you have the appropriate rights and IAM roles set up to access the relevant AWS services like ECS, EC2, and ECR (Elastic Container Registry).

These procedures offer a high-level overview of how to configure the required settings and launch a container using particular images in AWS ECS. Depending on your unique requirements and the launch type (EC2 or Fargate) you select, the exact stages may change. Always consult the official AWS documentation for thorough guidelines and best practices.

THANK YOU FOR READING!!!

--

--