Skip to content

Instantly share code, notes, and snippets.

@AMMullan
Last active November 8, 2022 17:03
Show Gist options
  • Save AMMullan/c5010007db1c7174ee173b4f578c64da to your computer and use it in GitHub Desktop.
Save AMMullan/c5010007db1c7174ee173b4f578c64da to your computer and use it in GitHub Desktop.
ECS Notes

ECS Notes

A Task Definition is a collection of 1 or more container configurations. Some Tasks may need only one container, while other Tasks may need 2 or more potentially linked containers running concurrently.

The Task Definition allows you to specify things like:

  • Which Docker image to use
  • Which ports to expose
  • How much CPU and memory to allot
  • How to collect logs
  • Define environment variables.

A Task is created when you run a Task directly, which launches container(s) (defined in the task definition) until they are stopped or exit on their own, at which point they are not replaced automatically. Running Tasks directly is ideal for short-running jobs, perhaps as an example of things that were accomplished via CRON.

A task placement strategy is an algorithm for selecting instances for task placement or tasks for termination.

  • When a task that uses the EC2 launch type is launched, Amazon ECS must determine where to place the task based on the requirements specified in the task definition, such as CPU and memory.
  • Similarly, when you scale down the task count, Amazon ECS must determine which tasks to terminate.

A task placement constraint is a rule that is considered during task placement.

  • You can use constraints to place tasks based on Availability Zone or instance type.
  • You can also associate attributes, which are name/value pairs, with your container instances and then use a constraint to place tasks based on attribute.

A Service is used to guarantee that you always have some number of Tasks running at all times. If a Task's container exits due to an error, or the underlying EC2 instance fails and is replaced, the ECS Service will replace the failed Task. This is why we create Clusters so that the Service has plenty of resources in terms of CPU, Memory and Network ports to use. To us it doesn't really matter which instance Tasks run on so long as they run. A Service configuration references a Task definition. A Service is responsible for creating Tasks.

Services are typically used for long-running applications like web servers. For example, if I deployed my website powered by Node.JS in Oregon (us-west-2) I would want say at least three Tasks running across the three Availability Zones (AZ) for the sake of High-Availability; if one fails I have another two and the failed one will be replaced (read that as self-healing!). Creating a Service is the way to do this. If I had 6 EC2 instances in my cluster, 2 per AZ, the Service will automatically balance Tasks across zones as best it can while also considering CPU, memory, and network resources.

References

Written with StackEdit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment