TechWriterDev
  • Cloud
    • AWS
      • 00_Doubts
      • CloudPractitioner
        • Cloud Computing
        • AWS Global Infrastructure
        • Introduction to AWS EC2
        • Elastic load balancer(ELB)
        • 04_Messaging_Queuing
        • Aditional Computing Service
        • Accessing AWS resources
        • AWS Networking
        • Storage
        • Amazon Database Solutions
        • Monitoring Tools
        • AWS Security
        • Distributed Denial Of Service Attacks
      • DeveloperAssociate
        • References
        • AWS DVA-C02 Services Index
        • Services
          • 00_IAM
            • Identity and Access Management (IAM)
            • Account Protection Mechanisms
            • Access Mechanism of AWS Resources
            • Security Tools
            • Responsibility Model
            • Advanced Concepts
          • 01_EC2
            • Elastic Compute Cloud (EC2)
            • EC2 Volume Types
            • Amazon Machine Image (AMI)
            • AWS charges for IPv4 address
          • 02_SecurityGroups
            • Security Groups
          • 03_Elastic_LoadBalancing
            • Terminology
            • Elastic load balancer
            • Features
            • Basics
          • 04_AutoScaling
            • Auto Scaling
          • 05_RDS
            • Relational Database Service (RDS)
            • Aurora
            • Security
            • RDS Proxy
          • 06_ElastiCache
            • Cache
            • Cache Offerings
          • 07_Route53
            • Basics of DNS
            • Route 53
          • 08_VPC
            • Virtual Private Cloud (VPC)
          • 09_S3
            • Simple Storage Service (S3)
            • S3 Features
            • S3 Encryption
            • S3 Features
            • S3 Bucket Policy and IAM Policy
          • 10_ECS
            • Elastic Container Service (ECS)
            • Elastic Container Registry (ECR)
            • AWS Copilot
          • 11_EKS
            • Elastic Kubernetes Service (EKS)
          • 12_SDK_CLI_Tips
            • Access AWS Resources
          • 13_CloudFront
            • Cloud Front
          • 14_Messaging
            • Simple Queue Service (SQS)
            • Simple Notification Service (SNS)
            • Fan Out Pattern
            • Kinesis
            • Compare and Contrast
          • 15_ElasticBeanStalk
            • Elastic Beanstalk
          • 16_CloudFormation
            • CloudFormation
            • Dynamic References
          • 17_Monitoring
            • AWS Monitoring
            • AWS CloudWatch
            • CloudWatch Alarms
            • Synthetics Canary
            • Amazon EventBridge (formerly CloudWatch Events)
            • X-Ray
            • OpenTelemetry
            • CloudTrail
          • 18_Lambda
            • Lambda
            • Lambda Integrations
            • Configuring Lambda
            • Lambda Layers
          • 19_API_Gateway
            • API Gateway
            • API Gateway Integrations
          • 20_DynamoDB
            • DynamoDB
            • Operations
            • Indexes
            • DynamoDB Accelerator (DAX)
            • DynamoDB Streams
            • Transactions
            • Integrations
          • 21_CICD
            • CICD
            • CodeCommit
            • CodePipeline
            • CodeBuild
            • CodeDeploy
            • CodeArtifact
            • CloudGuru
          • 22_SAM
            • Serverless Application Model (SAM)
          • 23_CDK
            • Cloud Development Kit (CDK)
          • 24_StepFunctions
            • Step Functions
            • Types of step function
          • 25_AppSync
            • AppSync
          • 26_Amplify
            • Amplify
          • 27_STS
            • Security Token Service (STS)
          • 28_DirectoryService
            • Active Directory
          • 29_KMS
            • Encryption
            • KMS API
            • Features
            • Cloud Hardware Security Module (HSM)
          • 30_SSM_Store
            • SSM Parameter Store
          • 31_SecretsManager
            • Secrets Manager
          • 32_Cognito
            • Cognito
      • Questions
        • AWS_Region
        • EC2
        • IAM
  • Database
    • MongoDb
      • Mongo db Basics
      • Mongo DB Atlas
      • Document
      • Import-Export based on Data Format
      • Mongo Shell Commands
      • Query Operators
      • Indexes
      • Upsert
      • MongoDB Aggregation Framework
      • Aggregation Framework Operators
    • PostgreSQL
      • POSTGRE SQL DataTypes
      • About table
      • Constraints
  • Technologies
    • RabbitMQ
      • RabbitMQ Concepts
      • Introduction to Exchanges
      • Introduction to Queues
    • Terraform
      • 00_Introduction
      • Configuration blocks
      • Commands
      • Variables
      • Terraform Cloud
      • Modules
  • Languages
    • Java
      • Logging
        • Getting Started
      • 00_Core
        • 00_Basics
          • Java Vs C++
          • Object oriented principles
          • Steps to compile a java program
          • JVM Internals
          • Understanding Java Development Kit
          • What is JIT Compiler?
          • Java data types
          • 07_identifiers_type_conversion
          • 08_references_and_packages
          • Steps for attaching scanner
        • Concurrency
          • 00_Threads
            • Threads
          • 01_ExecutorFramework
            • Executor Framework
            • Asynchronous Computation
      • 01_Backend
        • 01_HttpAndWebServerBasics
          • HTTP
          • Content Type
          • Web Server
        • 02_J2EE_Basics
          • J2EE_Basics
          • Why HttpServlet classs is declared as abstract class BUT with 100 % concrete functionality ?
        • 03_TomCatAndSession
          • What is a Session?
          • WebContainer
        • 04_PageNavigation
          • Cookies Additional Information
          • Page Navigation Techniques
        • 05_AboutServlet
          • CGI v/s Servlet
          • Executor Framework
          • Servlet Life cycle
          • SERVLET CONFIG
          • Servlet Context
          • Servlet Listener (web application listener)
        • 08_SpringBoot
          • Spring Boot
          • Some common annotations used in spring eco system
        • 09_SpringDataJPA
          • Spring Data JPA
        • Java_Language_Changes
          • JDK enhancement tracking reference
        • 06_ORM_Hibernate
          • readmes
            • Hibernate
            • Advantages of Hibernate
            • Hibernate Caching
            • Hibernate API
            • Hibernate Query API
            • Hibernate Annotations and JPQL
            • Entity and Value Type
        • 07_SpringFramework
          • bean_validation
            • Bean Validation
          • core
            • readme
              • Spring
              • Spring Framework Modules
              • Spring MVC Request flow
              • Dependency Injection
              • Spring Beans
              • 06_Spring_Framework_Annotations
      • 03_Tools
        • Maven
          • Maven
  • SoftwareEngineering
    • DesignPatterns
      • Notes
        • Basics
        • OOP
        • SOLID Principles
        • 03_Creational
          • Abstract Factory (aka Kit)
          • Builder
          • Factory Method (aka Virtual constructor)
          • Prototype
          • Singleton
        • 04_Structural
          • Adapter (aka Wrapper)
          • Bridge (aka Handle | Body)
          • Composite
          • Decorator (aka Wrapper)
          • Facade
          • Flyweight
          • Proxy (aka Surrogate)
        • 05_Behavioral
          • Chain of Responsibility
          • Command (aka Action | Transaction)
          • Iterator (aka Cursor)
          • Observer (aka Publish-Subscribe | Dependents)
          • Strategy (aka Policy)
    • Principles
      • REST
        • REST
  • Tools
    • Containers
      • Docker
        • Docker
        • Docker Image
        • Commands
        • Compose
        • Best Practices
      • Kubernetes
        • Kubernetes
    • VCS
      • Git
        • Quick reference of useful Git commands
Powered by GitBook
On this page
  • Icon
  • Basics
  • Capacity Management
  • Terminology
  • IAM roles
  • EC2 Instance Profile
  • ECS Task Role
  • Load Balancer Integration
  • Auto Scaling
  • ECS Service Auto Scaling
  • Auto Scaling EC2 instances
  • Rolling Updates
  • Data Volumes
  • EFS integration
  • S3 integration
  • References
  1. Cloud
  2. AWS
  3. DeveloperAssociate
  4. Services
  5. 10_ECS

Elastic Container Service (ECS)

Previous10_ECSNextElastic Container Registry (ECR)

Last updated 4 months ago

Icon

ECS Icon

Basics

  • Its a fully managed container orchestration service that helps you easily deploy, manage, and scale containerized applications.

Capacity Management

  • There are 3 ways to do capacity management for this orchestration service.

EC2 instance Launch Type

  • Docker containers are placed on Amazon EC2 instances in this type of launch configuration.

  • Provisioning and managing the EC2 instance infrastructure needs to be done.

  • Each EC2 instances would be running ECS Agent who would be registering EC2 instances to ECS cluster.

  • ECS Task Placement strategy and Task placement constraints assists us to decide which ECS task to terminate when adding new adding new ECS Task due to scaling or new deployment to cluster.

    • Task Placement Strategy

      • This strategy is done based on best effort basis.

      • Following is the strategy algorithm

        • Identify instances that satisfy ECS task requirement of CPU, Memory and port as per Task definition.

        • Identify instances that satisfy the Task Placement Constraints.

        • Select instance for task placement.

      • Following are the strategies.

        • Binpack

          • Place Task based on least available CPU or memory.

          • Reduces the number of instances in use, resulting in cost savings.

        • Random

          • Places Task randomly.

        • Spread

          • Places based on specified value.

          • This value can be ECS availability zones, Instance Id and so on...

      • These strategies can be mixed and matched.

    • Task Placement Constraints

      • distinctInstance

        • Two task of same type are never placed on same EC2 instance.

      • memberOf

        • Places instances based on the result of an expression written in cluster query language.

Fargate

  • In this type of configuration, the infrastructure (no EC2 instances to manage) is serverless.

  • Based on configuration for RAM and CPU provided, ECS will run the ECS tasks behind the scene.

  • Scaling is simply increasing the number of tasks.

  • Fargate launch type does not require host port to be configured as each ECS task gets its own private IP address throug an Elastic Network Interface (ENI) i.e., infrastructure is not to be managed by the user.

External

Terminology

Task Definition

  • Task Definition is a blueprint of an application to be created.

  • It is a JSON document which has details regarding how to run a task definitions.

  • Following are the crucial information,

    • Image Name

    • Port bindings

    • Environment Variables

    • CPU and Memory usage

    • Networking information

    • IAM roles

    • Logging configuration

  • Can define upto 10 containers per task definition.

  • Environment variables can be loaded from,

    • Hardcoded i.e from URL etc..

    • Secret Manager

    • SSM parameter store

    • Amazon S3 (Bulk )

  • Data can be shared between containers created from same task defintion by mounting data volumes (Bind Mounts).

    • This concept is called SideCar container pattern, where sidecar container is used to read or write data (e.g., metrics/logs) to other destinations.

    • For EC2 instance launch type, EC2 instance store is the Bind Mount with

    • For Fargate launch type, Ephemeral Storage is the Bind Mount.

  • ECS tasks are runtime instance of Task Definition.

  • Containers are ECS tasks that run on ECS clusters.

IAM roles

  • IAM roles are assigned per task definition

  • Following roles are used based on launch type to create and manage ECS Task

EC2 Instance Profile

  • Used by EC2 agent when launch type is EC2 instance.

  • This role helps to make API calls to ECS service.

  • Send logs to CloudWatch Logs.

  • Pull docker image from ECR.

  • Reference sensitive data in Secret Manager or SSM parameter store.

ECS Task Role

  • Applicable to both launch types.

  • Allows each tasks to have specific role based on the requirement.

  • These roles are defined in the task definition of ECS service.

Load Balancer Integration

  • ALB and NLB is supported to be integrated with ECS cluster.

  • Classic Load balancer is not recommended for integration and does not support Fargate Launch Type.

  • Application Load Balancer can connect to correct EC2 port for EC2 Launch Type when Dynamic Host Port Mapping is configured (i.e only container port is mapped), provided that Inbound Rules allow mapping to any port from ALB's security group.

Auto Scaling

ECS Service Auto Scaling

  • AutoScaling allows to increase or decrease the desired number of ECS task.

  • Scaling can be one of the following

    • Target Tracking (based on configured CloudWatch Metrics).

      • Scaling can be based on following metrics,

      • ECS Service Average CPU Utilization

      • ECS Service Average Memory Utilization

      • ALB Request Count Per Target

    • Step Scaling

    • Scheduled Scaling

  • This scaling is not same as EC2 Auto Scaling.

Auto Scaling EC2 instances

  • Auto Scaling Group Scaling

    • Scale your ASG based on CPU Utilization i.e Add EC2 instance when CPU utilization reaches the target threshold.

  • ECS Cluster Capacity Provider

    • Capacity provider paired with Auto Scaling Group.

    • Add EC2 instances when resource utilization reaches the target threshold configured.

    • This is a better scaling option that the Auto Scaling Group Scaling.

Rolling Updates

  • Rolling updates ensure high availability of your application when it getting updated or new changes are being deployed.

  • This is done by making sure a min number of tasks are running at the time of updates, but doesnt cross the max number of tasks running.

Data Volumes

EFS integration

  • Can be mounted to ECS tasks of both EC2 and Fargate launch types.

  • Tasks running in any AZ can connect with EFS and share data. Hence help us achieve multi-AZ shared storage for your containers.

  • EFS + Fargate => Serverless.

S3 integration

  • Cannot be mounted as file system.

References

When min is 50% and max is 100% the following diagram shows how an application does rolling update.

External Instances using ECS Anywhere
Docker-vs-VM
Launch Types
Load Balancer Integrations
Cluster and Scaling
EC2 Instance
ECS Fargate