We continue the serie “First steps with Amazon EC2 Container Service” focusing on the tasks and clusters that will host them.
1 – What is a Cluster
An ECS cluster is a group of EC2 instances that will host your containers
A cluster can contain one or more instances of different types and sizes. In our case, we will be using a t2.micro.
2 – ECS cluster creation
We are going to connect to the aws web console for ecs. We will go to the “Cluster” section on the left menu.On the next screen (Cluster list), we are going to click on “Create Cluster” so we can create our first cluster.
On creating cluster screen we have a very complete form with many options. We are going to use the following fields :
- Cluster Name : helloworldCluster
- Provisioning Model : On-Demand Instance
- EC2 instance type : t2.micro
- VPC : choose the VPC where you want to create your instances
- Security group : choose/create a security group that opens port 80
Click the “Create” blue button to create the cluster.
It should now appear in the clusters list
3 – Task definition or how to define the containers launch
A task definition is a list of parameters which will determine how our containers will be launched of.
To create it, we will go to “Task definitions”on the left menu, then we will click the “Create new Task Definition” blue button.
This first task definition will allow us to launch a container, with its HTTP (80) port linked to the host instance’s port 8080.
For our case we are going to fill the following fields:
- Task Definition Name : Helloworld-1
- Container Definitions : click “add container”
- Container name : Helloworld
- Image : 123456789012.dkr.ecr.eu-west-1.amazonaws.com/helloworld:latest
- Memory Limits (MB) : 128
- Port mappings :
- Host : 8080
- Container : 80
- protocol : tcp
- Click the button “Add”
You can then click the blue “Create” button
Plenty of other options are available in the Container Definitions, to allow a precise definition of the needs of the containers (Mapping of volumes, link between containers …)
4 – Task execution
Now that we have created our host machine cluster and we have described how to launch the container, we can finally run it.
To do this, we will click on the “Cluster” menu and choose from the list our helloworldCluster cluster. We get to here:
Click on the “Task” tab and then on the “Run new Task” button
In the next screen we will choose all the elements we created previously
The task is created and ready to receive messages
5 – Connection to the container
All that remains is to validate that the container respond our HTTP requests.
We will connect directly to the host instance on port 8080.
To find its IP, just click on the name of the task (in our case 67f6a5b4-4 …) to display the details.
In the container part click on the triangle next to the container name (helloworld) to display the details, the IP will be in the section “Network Bindings”
You can then go to your preferred browser, and enter the url of the container to display the page
Congratulations, you have ran your first container on Amazon EC2 Container Service.
In the next article we will see how to go further by creating a service based on the existing container image. Thus several containers will be launched and will be able to respond to your requests