AWS Elastic Container Service (ECS) and Fargate

Microservices

distributed systems & service orientated architectures: create lots of independent decoupled services.
Containers are good for running these.

Features

Continuous integration continuous deployment (CICD)

Popular with microservices. Pipeline:

Theory

Terms

ECS launch type

EC2 launch type: Lower level, control EC2, file storage, do teh management, granular control

Fargate setup

ECS CLI create cluster

Dynamic host port mapping

Can have multiple tasks in a container wanting the same default port, e.g. Apache an nginx. The instance takes care of this, and maps to different ports. Also the ALB listens on a single port, HTTP 80, so need to set up the ALB to use rule based routing and paths. Can't do that with a network load balancer.

Cluster auto scaling

IAM roles for tasks

Specify IAM role for a container to use for a task. The tasks can then use AWS CLI. Use TaskRoleArn override.

Elastic Container Registry (ECS)

Create a docker image

New EC2 instance
SSH into it
sudo yam update -y (update EC2)
AWS configure (set up permissions: to set access key id for AWS CLI)
sudo amazon-linux-extra install docker
sudo service docker start
sudo systemctl enable docker (ensures restarts after a reboot of instance)
sudo usermod -a -G docker ec2-user (allows you to run commands as ec2-user rather than root)
docker info (if permissions issues, shutdown and restart instance with sudo shutdown -r now)
create Dockerfile (e.g. use ubuntu, install apache, expose a port, run apache)
docker build -t jb-container . (builds the image from Dockerfile)
docker run -t -i -p 80:80 jb-container (runs the image)
-> working docker image in a container.

Then want to copy the container to ECR
aws ecr create-repository --repository-name jer-ecr (created repository)
get repository urn
docker push (loads image)

Start in ECS:
ECS clusters, configure a new one, fargate type.
docker image uri
runs

Elastic Kubernetes Service (EKS)