AWS Learn In Public Week 7, ECR, ECR and Fargate
Tags: aws, ecs, ecr
Published: 2021-04-11 21:19:25

---
title: AWS Learn In Public Week 7, ECR, ECR and Fargate
published: true
description: Docker on AWS and more
tags: 
- aws
- ecs
- ecr
cover_image: https://user-images.githubusercontent.com/630705/114321478-d5959a00-9b12-11eb-84e0-b29be033d527.jpeg
canonical_url: https://www.harrisgeo.me/blogs/aws-learn-in-public-week-7-ecs-ecr-and-fargate
series: AWS Learn in public
---

How's everyone doing? This section I have to admit is the one that I found the most difficult to understand all of the concepts within ECS so I hope that my notes will help explaining it in a simple way. Let's get started.

## [ECS](https://twitter.com/harrisgeo88/status/1379041394141003781)

What AWS ECS (Elastic Container Service)?

- ECS is Amazon's platform for managing Docker containers.
- ECS clusters are groups of EC2 instances that run the ECS agent for Docker containers which then register the instance to the cluster.
- EC2 instances run an AMI designed for ECS

## [ECS Task Definitions, Services and Clusters](https://twitter.com/harrisgeo88/status/1379406049552310272)

### Task Definitions

Task Definitions are metadata in JSON format that give instructions to ECS on how to run a Docker container.

The contain crucial information about image names, port bindings for container and host, memory and cpu required, environment variables and networking information

### ECS Services

We can configure the way tasks run and also how many should run and spread them amongst your EC2 instances and can also be linked to load balancers

### Clusters

We need to create an ECS Cluster in which we add services and task definitions

Clusters can be of type EC2 or Fargate. For EC2 Clusters the corresponding EC2 instance are automatically created along with an autoscaling group

- A task definition depends on an ECS service in order to run
- Creating an ECS service also adds a Docker container image for it inside the EC2 instances
- We can update the number of tasks in the ECS service and corresponding ASG group if we want to scale

## [ECR](https://twitter.com/harrisgeo88/status/1379770448989155347)

Let's talk about AWS ECR (Elastic Container Registry) which is a private repo for storing our Docker images

It is used for creating custom images locally and then push them to ECR so that they are available to use in ECS

To create a repo, in our CLI we need to

1. Authenticate our Docker client to the ECR registry
2. Build our Docker images
3. Tag the image
4. Push the image into ECR

## [Fargate](https://twitter.com/harrisgeo88/status/1380130571800612872)

Let's talk about AWS ECS with Fargate

Fargate is a Serverless way of launching ECS Clusters

We only create the task definitions and AWS will run our containers. To scale we only increase the task number

We don't have to worry about managing EC2 instances anymore

## [ECS Task placement](https://twitter.com/harrisgeo88/status/1380494469494046720)

Let's talk about ECS tasks placement

Task placement strategy: Determine where to place newly launched EC2 type tasks. Task placement constraints: Based on CPU, memory and available port. The same logic constraints also apply when scaling in and need to terminate tasks

Now about Task placement strategies we have

1. Binpack: Based on the least available amount of memory or CPU which is great for cost savings
2. Random: without any logical order
3. Spread: Based on specified value like instanceId
4. Mix them together

## Summary

Most of these concepts mentioned above may not make perfect sense if you don't see them being applied on the AWS console but still they are good theory to know. Maybe that can be a future version of this sets of tutorials :)

Next week we're talking about Elastic Beanstalk where things start getting more interesting as we can see combination of several services.