AWS ECS in Simple Words
When it comes to Amazon’s AWS, the amount of service each with their own terminology can be mind-boggling and AWS’ relatively new EC2 Container Services (ECS) is no exception.
In a series of blog posts, I am going to introduce the very basics of ECS starting from the terminology and gradually move to more advanced topics such as deploying a production ready cluster with autoscaling.
I assume you are already familiar with concepts around EC2 and have some experience working with Docker.
In this post I mainly focus on explaining the ECS terminology in very simple terms.
Amazon EC2 Container Service (Amazon ECS) is a highly scalable, fast, container management service that makes it easy to run, stop, and manage Docker containers on a cluster of Amazon Elastic Compute Cloud (Amazon EC2) instances.
The key components involved in ECS are:
- Container Instance
- Task Definition
These may sound a bit abstract, but you will understand them better when we put them in context and define them one by one.
1. Container Instance
A Container Instance is just a fancy word for an EC2 instance. Each Container Instance is host to one or more Docker Containers.
Simply put, a cluster a logical grouping of a few Container Instances. Well, a logical group of EC2 instances to make it even simpler.
However, each Container Instances in a cluster runs Amazon ECS container agent which allows instances to connect to a cluster.
3. Task Definition
As mentioned, each Container Instance hosts one or more Docker containers. In order for these Docker containers to run on the Container Instance you need to provide a little configuration [file] to define how should this container run, how much resources does it need, which Docker image to use and etc.
Simply put, this is “almost” like a Dockerfile(with a different syntax) with some additional AWS specific configuration fields. Below is a shortened example of an empty task definition:
"value": "-Xms64m -Xmx256m"
For more information on the configuration parameters, have a look at ECS Task Definition Parameters.
Here is the place when things might get confusing. When a Docker container is run based on what has been defined in a Task Definition, AWS calls that running container, a Task. Although not entirely correct, the image below should give you a rough idea:
So far we know how containers are defined and where they are being hosted. But who manages the containers lifecycle? Who manages the desired number of Tasks per Task Definition? AWS ECS provides you with something called a Service.
When you create a service, you always assign a Task Definition and based on that, the Service will always make sure that there is a defined number of Tasks running.
In addition to maintaining the desired count of Tasks in your service, you can optionally run your Service behind a load balancer. The load balancer distributes traffic across the Tasks that are associated with the Service.
If you are familiar with Docker Hub, AWS has its own version of image repository.
Hopefully, you now have a better understanding of ECS concepts. If you are curious and would like to give it a try you can run a guided tutorial provided by AWS: ECS First Run (remember that it costs will be incurred on your credit card)
- Make sure to follow me here on Medium and also on twitter (https://twitter.com/hossein761) for more!