In the new version 6 of Architecting on AWS, released in October 2018, there is a discussion on Docker, microservices and ECS.
There is an awesome workshop here about breaking a monolithic Docker application into microservices. The application hosts a simple message board with threads and messages between users.
The workshop is Intermediate level with a time to complete of 2 hours.
It may not be the ideal way to get started with ECS and Docker, on the other hand it is achievable even if you have never used either, and you will learn a lot along the way. It will probably take you longer than two hours.
To get started with Docker I recommend Docker Basics for Amazon ECS, which walks through installing Docker on an AMZ Linux instance, creating a Hello World Docker Image from a supplied Dockerfile, and pushing it to the AMZ Container Registry.
To get started with ECS the Getting Started wizard is the best way. At least you would think so. The problem is this:
ECS offers two modes: EC2 mode, and Fargate mode. With ECS mode the containers run on ECS optimized EC2 instances in an AutoScaling Group, and that is the best mode to start learning about ECS. However, at the time of writing Fargate is being rolled out to more regions. Fargate moves the AutoScaling Group and instances to a managed control plane, so you do not have visibility into the AutoScaling Group or the instance. That’s fine and that’s the whole point of Fargate but this project does not use Fargate. When Fargate is rolled to a new region, the ECS Getting Started wizard in that region changes from EC2 mode to Fargate mode, with no option to change it. In real life that’s not a problem a you wouldn’t use the Getting Started Wizard as that’s just for learning.
Going back to the workshop, once you start looking at the pre-requisites in the instructions, you may be put off. First it assumes you will install Docker and the AWS CLI locally on a Mac or Windows and links are provided. However, you can use an AMZ Linux instance instead, instructions here.
They also mention Atom as a popular open-source text editor. Good as it is, you don’t need it for this project. In fact you don’t edit any files, you just download the project files and look at them. I downloaded the project files to my local machine and then used WinSCP to copy the files to the Linux instance.
After that, the workshop worked as written, although given the fast evolving ECS GUI there will be some minor differences.
At the end of the workshop, we test our Microservices based application by navigating to the DNS name of our Load Balancer and appending a path:
The ALB routes this path to a particular target group, and on to a container running on one of the EC2 instances in an ECS Cluster.
As always, the last step involves a clean up. Personally I like to keep things around for a while for demos so until I automate the whole thing I save costs by scaling down the ECS services to 0 tasks, scaling the Cluster size to 0 instances, and deleting the ALB.