ECS Flashcards
ECS clusters
are logical grouping of EC2 instances
the EC2 instances we’re going to launch will run
ECS agents = just a Docker container on each EC2 instance.
they will register our EC2 instance with the ECS cluster
The EC2 instances are a little bit special
they don’t run the plain Amazon Linux 2 AMI.
They run the special ECS AMI
tasks definitions
metadata in JSON form to tell ECS how to run a Docker Container
image name, the port binding for the container and the host, memory and CPU that are required, the environment variables, networking informationetc
tasks and roles (exam)
the task can have an IAM role
If a task cannot do anything, it cannot pull an image
from the ECR, it cannot talk to S3 or whatever,
if a container can’t do this, well it’s because it’s missing a task role so we could assign a role
ECS services
- help define how many tasks should be run and how
- they ensure that the number of tasks desired is running across our fleet of EC2 instances
- can be linked to LB
- are created inside the ECS cluster
Replica type of ECS services
tries to run as many tasks as possible
Daemon type of ECS services
tries to run only one task on each ECS instance in the cluster
(for monitoring and gathering metrics for ex.)
you can run several identical containers using (exam)
dynamic port forwarding
you roll out as many containers as you want and each of them has a dynamically assigned port (host port is left empty, 0 means random). To the outside they are available on 80, and Load Balancer will distribute requests across them
DNS name of Load Balancer is then used as entry point
EC2 Instance Profile
we have an EC2 Instance and it is running the ECS Agent. That’s what makes this EC2 Instance part of ECS. To make it work, we need to attach an
EC2 Instance Profile (IAM role = ECS instance role).
ECS agent will use that role to make API calls to the ECS service to register the instance, for example, with their ECS cluster, to send the container logs of any task rerun to CloudWatch Logs and also will be used to pull images from ECR
ECS agent has integration with ECS Service, CloudWatch Logs, and the ECR Service through the EC2 Instance profile.
on your EC2 Instances, you can run some tasks that may interact with other it via services and so each task needs
ECS Task Role (IAM role). This will allow each task to have a specific role with the minimum permissions.
for example, we will create an ECS Task Role A that we will attach to the Task A, and this task role may allow us to write to an Amazon S3 Bucket.
you want to use different task roles for different ECS Services and tasks that you run.
And where do you define the task role?
you define them in the task definition.
in the IAM console you can search for ECS and see all ECS related roles. You can also create a new role –> scroll to ECS and select it –> select use case, for ex., access to S3
Which ECS config must you enable in /etc/ecs/ecs.config to allow your ECS tasks to endorse IAM roles?
ECS_ENABLE_TASK_IAM_ROLE
You are looking to push Docker images into ECR with your AWS CodePipeline and CodeBuild. The last step fails with an authorization issue. What is the issue?
Any permissions issues against ECR is most likely due to IAM policies
double check your IAM permissions for CodeBuild service
You are looking to run multiple instances of the same application on the same EC2 instance and expose it with a load balancer. The application is available as a Docker container. You should use
Application load balancer + ECS
Uses the dynamic port feature