Amazon EC2 Container Service (ECS)

The next tool that we are going to be looking at is the Elastic Container Service from Amazon. The description that Amazon gives is as follows:

"Amazon EC2 Container Service (ECS) is a highly scalable, high performance container management service that supports Docker containers and allows you to easily run applications on a managed cluster of Amazon EC2 instances. Amazon ECS eliminates the need for you to install, operate, and scale your own cluster management infrastructure. With simple API calls, you can launch and stop Docker-enabled applications, query the complete state of your cluster, and access many familiar features like security groups, Elastic Load Balancing, EBS volumes, and IAM roles. You can use Amazon ECS to schedule the placement of containers across your cluster based on your resource needs and availability requirements. You can also integrate your own scheduler or third-party schedulers to meet business or application specific requirements." - https://aws.amazon.com/ecs/

It wasn't a surprise that Amazon would offer their own container-based service. After all, if you are following Amazon's best practices, then you will already be treating each of your EC2 instances in the same way you are treating your containers.

When I deploy applications into Amazon Web Services, I always try to ensure that I build and deploy production-ready images, along with ensuring that all the data written by the application is sent to a shared source as the instances could be terminated any time due to scaling events.

To help support this approach, Amazon offers a wide range of services such as:

  • Elastic Load Balancing (ELB): This is a highly available and scalable load balancer
  • Amazon Elastic Block Store (EBS): This provides persistent block-level storage volumes for your compute resources
  • Auto Scaling: This scales EC2 resources up and down, allowing you to manage both, peaks in traffic and failures within the application
  • Amazon Relational Database Service (RDS): This is a highly available database as a service supporting MySQL, Postgres, and Microsoft SQL

All of these are designed to help you remove all single points of failure within your Amazon-hosted application.

Also, as all of Amazon's services are API-driven, it wasn't too much of a jump for them to extend support to Docker containers.

Launching ECS in the console

I am going to be using the the AWS Console to launch my ECS cluster. As my AWS account is quite old, a few of the steps may differ. To try and account for this, I will be launching my cluster in one of the newer AWS regions.

Once you have logged into the AWS Console at http://console.aws.amazon.com/, make sure that you are in the region you would like to launch your ECS cluster in, and then click on the EC2 Container Service link from the Services drop-down menu.

As this is your first time launching an ECS cluster, you will be greeted with an overview video of the service.

Click on Get started to be taken to the Wizard that will help us launch our first cluster.

First of all, you will be prompted to create a task definition. This is the equivalent of creating a Docker Compose file. Here you will define the container image that you would like to run and the resources it is allowed to consume, such as RAM and CPU. You will also map the ports from the host to container here.

For now, we will use the defaults and look at launching our own containers once the cluster is up and running. Fill in the details as per the following screenshot and click on Next step:

Launching ECS in the console

Now that the task has been defined, we need to attach it to a service. This allows us to create a group of tasks, which initially will be three copies of the console-sample-app-static task, and register them with an Elastic Load Balancer. Fill in the details as per the following screenshot and click on Next step button:

Launching ECS in the console

Now that we have the service defined, we need a location to launch it. This is where EC2 instances come into play, and also where you still to be charged. While the Amazon EC2 Container Service is free of charge to set up, you will be charged for the resources used to deliver the compute side of the cluster. These will be your standard EC2 instance charges. Fill in the details as per the following screenshot and click on Review & launch:

Launching ECS in the console

Before anything is launched, you will get the opportunity to double-check everything that is configured within your AWS account, this is your last chance to back out of launching the ECS cluster. If you are happy with everything, click on Launch instance & run service button:

Launching ECS in the console

What you will see now is an overview of what is happening. Typically, it will take about 10 minutes to run through these tasks. In the background, it is doing the following:

  • Creating an IAM role that accesses the ECS service
  • Creating a VPC for your cluster to be launched in
  • Creating a Launch Configuration to run an Amazon ECS-optimized Amazon Linux AMI with the ECS IAM role
  • Attaching the newly created Launch Configuration to an Auto Scaling Group and configuring it with the number of instances you defined
  • Creating the ECS Cluster, Task, and Service within the Console
  • Waiting for the EC2 instances that have been launched by the Auto Scaling Group to launch and register themselves with the ECS service
  • Running the Service on your newly created ECS cluster
  • Creating an Elastic Load Balancer and registering your Service with it

You can find more information on the Amazon ECS-Optimized Amazon Linux AMI on its AWS Marketplace page at https://aws.amazon.com/marketplace/pp/B00U6QTYI2/ref=srh_res_product_title?ie=UTF8&sr=0-2&qid=1460291696921. This image is a cut-down version of Amazon Linux that only runs on Docker.

Once everything is completed, you will be given the option to go to your newly created Service. You should see something similar to the following screenshot:

Launching ECS in the console

As you can see, we have three running tasks and a load balancer.

Now let's create our own task and service. From the preceding Service view, click on Update button and change the desired count from three to zero, this will stop the tasks and allow us to remove the Service. To do this, click on default button to go to the cluster view and then remove the Service.

Now that the sample-webapp Service has been removed, click on the Task Definitions button and then the Create new task definition button. On the page that opens, click on the Add container button and fill in the following details:

  • Container name: cluster
  • Image: russmckendrick/cluster
  • Maximum memory (MB): 32
  • Port mappings: 80 (Host port) 80 (Container port) tcp (Protocol)

Everything else can be left at the default values:

Launching ECS in the console

Once filled in, click on the Add button. This will take you back to the Create a Task Definition screen, fill in the Task Definition Name, let's call it our-awesome-cluster and then click on the Create button:

Launching ECS in the console

Now that we have our new Task defined, we need to create a Service to attach it to. Click on the Clusters tab, then click on the default cluster, you should see something similar to the following image:

Launching ECS in the console

Click on the Create button in the Services tab. From this screen, fill in the following information:

  • Task Definition: our-awesome-cluster:1
  • Cluster: default
  • Service name: Our-Awesome-Cluster
  • Number of tasks: 3
  • Minimum healthy percent: 50
  • Maximum percent: 200

Also, in the Optional configurations section, click on Configure ELB button and use the Elastic Load Balancer that was originally configured for the sample-webapp service:

Launching ECS in the console

Once you have filled in the information, click on the Create Service button. If all goes well, you should see something similar to the following page:

Launching ECS in the console

Clicking on View Service will give you an overview similar to the one we first saw for the Sample-Webapp Service:

Launching ECS in the console

All that's left to do now is to click on Load Balancer Name to be taken to the ELB overview page; from here, you will be able to get the URL for the ELB, putting this into a browser should show you our clustered application:

Launching ECS in the console

Click refresh a few times and you should see the container's hostname change, indicating that we are being load balanced between different containers.

Rather than launching any more instances, let's terminate our cluster. To do this, go to the EC2 service in the Services menu at the top of the AWS Console.

From here, scroll down to Auto Scaling Groups that can be found at the bottom of the left-hand side menu. From here, remove the auto scaling group and then the launch configuration. This will terminate the three EC2 instances that formed our ECS cluster.

Once the instances have been terminated, click on Load Balancer and terminate the Elastic Load Balancer.

Finally, go back to the EC2 Container Service and delete the default cluster by clicking on the x. This will remove the remainder of the resources that were created by us launching the ECS cluster.

Recap

As you can see, Amazon's EC2 Container Service can be run from the web-based AWS Console. There are command tools available, but I won't be covering them here. Why, you might ask?

Well, although the service offering Amazon has built is complete, it feels very much like a product that is in an early alpha stage. The versions of Docker that ship on the Amazon ECS-Optimized Amazon Linux AMI are quite old. The process of having to launch instances outside of the default stack feels very clunky. Its integration with some of the supporting services provided by Amazon is also a very manual process, making it feel incomplete. There is also the feeling that you don't have much control.

Personally, I think the service has a lot of potential; however, in the last 12 months, a lot of alternatives have launched and are being developed at a more rapid pace, meaning that Amazon's ECS service is left feeling old and quite outdated compared to the other services we are looking at.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset