What is Amazon ECS and ECR? How do They Work with an Example!

Amazon ECS -101

Mohit Shrestha
FAUN — Developer Community 🐾

--

Amazon ECS

Hello Tech Maniacs!

This is a very basic introduction to what is Amazon ECS and ECR are!
When I went through my “Associate solution architect certification” Ryan’s course on Udemy, I first had firsthand experience with this ECS and ECR and to be honest it just blew me away! I learned the basics of it and simply moved out of this cluster :P

I just kept on skipping this TOPIC, not sure why but I found this very tough at first glance but discovered much later when I started my journey with ECS, that “it’s Awesome” and quite easy.
Its literally awesome, and hence I want you guys to give a very basic introduction of all the terms we use with ECS and what is ECS and ECR at a very high level.

Let's get started

WHAT IS ECS?

ECS is an acronym for “EC2 container service”. In simple terms, it provides a way to deploy your Docker containers over the Amazon platform on an EC2 instance or serverless(FARGATE)! ECS helps you orchestrate your containers and helps your provision your, yes! your own containers!
So if you have any containers running on your local machine but you want to make it live on a public platform to get publically accessible, AWS ECS is the solution for that along with “ECR” and “Task definitions” and “services”. DONT WORRY! I will let you know what these terms mean.

WHAT IS ECR?

ECR is an acronym for the “Elastic container registry”. In simple terms, it is the so-called “AMAZON DOCKER HUB” of your containers!

You can push all your local containers images from your LOCAL to ECR, ECR is the home for all your pushed container images where later it can be used by ECS service to get deployed on AMAZON platform! Please go through my following blog to understand how you can push your image from local to ECR and how this ECR works:

SOME OTHER ECS TERMS!

  • CLUSTER
  • TASK DEFINITION
  • TASKS
  • SERVICE
  • CONTAINER INSTANCE

CLUSTER: ECS cluster is a regional grouping of one or more container instances on which you can run task requests.When an instance launches, the ECS-agent software on the server registers the instance to an ECS Cluster. You can choose an existing VPC, or create a new one to spin up your container instances.

TASK DEFINITION: It is the complete definition of your tasks(in simple terms, your containers) and to describe how containers should be provisioned. Here You need to provide a link to ECR’s saved container images, CPU units, Memory, Container ports to expose, network type and many more. Simple terms, you are defining your containers and how to launch them via Task definitions.

TASKS: It is nothing but “ A RUNNING CONTAINER “. The description you provided for your containers in TASK DEFINITION, TASKS are the result of that. It can be thought of as a “RUNNING INSTANCE” of a Task Definition.

SERVICE: ECS SERVICE allows you to run your container instances as defined in your task definition. It also allows you to run and maintain a specified number of instances by configuring the auto-scaling policies. If any of your tasks fail or stop for any reason, the Amazon ECS service scheduler launches another instance of your task definition to replace it and maintain the desired count of tasks. You can optionally run your service behind a load balancer, The load balancer distributes traffic across the tasks that are associated with the service.

CONTAINER INSTANCE: This is nothing but an EC2 instance that is part of an ECS Cluster and has docker and the ECS-agent running on it.

Complete ECS flow

This is a very basic introduction of everything with ECS and ECR! To summarize everything,

  1. Create a docker image for your application, get ECR login on your local machine and push your image to your ECR.
  2. Create an ECS cluster using desired no. of EC2 instances (if you are using EC2+Networking type) or if you are using the FARGATE option, this will be serverless. You can create this cluster in default or a custom VPC.
  3. Create a new task definition and describe everything about your container. Including the network type, ECR’s saved image path that you pushed from your local to Amazon ECR. Provide memory, CPU units and expose ports.
  4. Create a new service and choose your task definition to spin up TASKS from. Create a load balancer and configure it, depending upon the needs. Choose autoscaling policies and the desired number of instances.
  5. You are done with your part now just wait for your tasks/containers to come UP and you can access it via the load balancer and the port you defined!

I hope this blog helped you clearing concepts regarding ECS. Don't forget to like this blog if you genuinely liked it.

Follow for more awesome blogs!

Follow us on Twitter 🐦 and Facebook 👥 and Instagram 📷 and join our Facebook and Linkedin Groups 💬.

To join our community Slack team chat 🗣️ read our weekly Faun topics 🗞️, and connect with the community 📣 click here⬇

If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇

--

--