Amazon-web-services – the difference between Amazon ECS and Amazon EC2

amazon ec2amazon-ecsamazon-web-services

I'm just getting started on AWS EC2. I understand that EC2 is like a remote computer where I can do pretty much everything I want. Then I found out about ECS. I know it uses Docker, but I'm confused about the relationship between these two.

Is ECS just a Docker install in EC2?
If I already have an EC2 and I start an ECS, does it mean I have two instances?

Best Answer

Your question

Is ECS just a docker install in EC2? If I already have a EC2, then I start a ECS, does it mean I have two instance?

No. AWS ECS is just a logical grouping (cluster) of EC2 instances, and all the EC2 instances part of an ECS act as Docker host i.e. ECS can send command to launch a container on them (EC2). If you already have an EC2, and then launch ECS, you'll still have a single instance. If you add/register (by installing the AWS ECS Container Agent) the EC2 to ECS it'll become the part of the cluster, but still a single instance of EC2.

An Amazon ECS without any EC2 registered (added to the cluster) is good for nothing.


TL; DR

An overview

  • EC2 - is simply a remote (virtual) machine.
  • ECS stands for Elastic Container Service - as per basic definition of computer cluster, ECS is basically a logical grouping of EC2 machines/instances. Technically speaking ECS is a mere configuration for an efficient use and management of your EC2 instance(s) resources i.e. storage, memory, CPU, etc.

To simplify it further, if you have launched an Amazon ECS with no EC2 instances added to it, it's good for nothing i.e. you can't do anything about it. ECS makes sense only once one (or more) EC2 instances are added to it.

The next confusing thing here is the container term - which is not fully virtualized machine instances, and Docker is one technology we can use to create container instances. Docker is a utility you can install on our machine, which makes it a Docker host, and on this host you can create containers (same as virtual machines - but much more light-weight). To sum up, ECS is just about clustering of EC2 instances, and uses Docker to instantiate containers/instances/virtual machines on these (EC2) hosts.

All you need to do is launch an ECS, and register/add as much EC2 instances to it as you need. You can add/register EC2 instances, all you need is Amazon ECS Container Agent running on your EC2 instance/machine, which can be done manually or directly using the special AMI (Amazon Machine Image) i.e. Amazon ECS-optimized AMI, which already has the Amazon ECS Container Agent. During the launch of a new EC2 instance the Agent automatically registers it to the default ECS cluster.

The container agent running on each of the instances (EC2 instances) within an Amazon ECS cluster sends information about the instance's current running tasks and resource utilization to Amazon ECS, and starts and stops tasks whenever it receives a request from Amazon ECS. For more information, see Amazon ECS Container Agent. Once set, each of the created container instances (of whatever EC2 machine/node) will be an instance in Amazon ECS's swarm.


For more information – read step 10 from this documentation: Launching an Amazon ECS Container Instance:

Choose an AMI for your container instance. You can choose the Amazon ECS-optimized AMI, or another operating system, such as CoreOS or Ubuntu. If you do not choose the Amazon ECS-optimized AMI, you need to follow the procedures in Installing the Amazon ECS Container Agent.

By default, your container instance launches into your default cluster. If you want to launch into your own cluster instead of the default, choose the Advanced Details list and paste the following script into the User data field, replacing your_cluster_name with the name of your cluster.

#!/bin/bash
echo ECS_CLUSTER=your_cluster_name >> /etc/ecs/ecs.config

Or, if you have an ecs.config file in Amazon S3 and have enabled Amazon S3 read-only access to your container instance role, choose the Advanced Details list and paste the following script into the User data field, replacing your_bucket_name with the name of your bucket to install the AWS CLI and write your configuration file at launch time. Note For more information about this configuration, see Storing Container Instance Configuration in Amazon S3.

#!/bin/bash
yum install -y aws-cli
aws s3 cp s3://your_bucket_name/ecs.config /etc/ecs/ecs.config

Just to clarify it further – you can create containers on your single EC2 instance without ECS. Install any of the containerization technology i.e. Docker and run the create container command, setting your EC2 as a Docker host, and have as much Docker containers as you want (or as much as your EC2's resources allow).