(Illustration: Brazil’s largest port, Port of Santos, provides container loading and unloading services. Image source: Photo by sergio souza on Unsplash。)
Briefing
(Command/Ctrl + Press the image to enlarge.)
History
From ancient to modern times. Get through all the context.
- 2014-11-13: AWS launches a preview of EC2 Container Service (ECS) – Container Management for the AWS Cloud.
- 2016-05-18: AWS announces Automatic Auto Scaling for Amazon EC2 Container Service (ECS) services.
- 2017-11-21: Amazon Elastic Container Service is renamed (previously Amazon EC2 Container Service).
- 2019-12-03: AWS announces Amazon ECS Capacity Providers.
- 2020-04-08: AWS Fargate launches platform version 1.4.0 | Containers
- 2020-06-16: AWS announces Amazon EC2 Auto Scaling now supports Instance Refresh within Auto Scaling Groups
- 2020-06-20: AWS::ECS::CapacityProvider resource was added in CloudFormation.
- 2020-11-30: Announcing Amazon ECS deployment circuit breaker
- 2020-12-01: Introducing Amazon ECS Anywhere
- 2020-12-30: Amazon Elastic Container Service launches new management console
- 2021-03-16: Using Amazon ECS Exec to access your containers on AWS Fargate and Amazon EC2
- 2021-05-27: Getting Started with Amazon ECS Anywhere – Now Generally Available
Terms
Here is a list of nouns that appear on the scene, and the full name of the original text, noun definition and source are noted.
- Amazon ECS:
- Amazon Elastic Container Service is a highly scalable, fast, container management service that makes it easy to run, stop, and manage Docker containers on a cluster.
- Amazon ECS Launch Types:
- Amazon ECS Launch Types determines the type of infrastructure on which your tasks and services are hosted.
- Features of Amazon ECS
- Containers:
- To deploy applications on Amazon ECS, your application components must be architected to run in containers. For more information about container technology, see Docker Basics for Amazon ECS.
- Container Images:
- Containers are created from a read-only template called an image.
- Task Definitions:
- A blueprint for your application. To prepare your application to run on Amazon ECS, you create a task definition. The task definition is a text file, in JSON format, that describes one or more containers, up to a maximum of ten, that form your application.
- Tasks:
- A task is the instantiation of a task definition within a cluster.
- Task Scheduling:
- The Amazon ECS task scheduler is responsible for placing tasks within your cluster. There are several different scheduling options available. For example, you can define a service that runs and maintains a specified number of tasks simultaneously.
- Clusters:
- When you run tasks using Amazon ECS, you place them on a cluster, which is a logical grouping of resources.
- Amazon ECS Container Instances:
- When using the EC2 launch type, then your clusters are a group of container instances you manage. An Amazon ECS container instance is an Amazon EC2 instance that is running the Amazon ECS container agent.
- Container Agent:
- The container agent runs on each infrastructure resource within an Amazon ECS cluster. It sends information about the resource’s current running tasks and resource utilization to Amazon ECS, and starts and stops tasks whenever it receives a request from Amazon ECS.
- Containers:
Use Cases
- Suitable: all kinds of industries.
- Suitable: The initial stage of digital transformation.
- Encapsulate, isolate, and getting cloud native to get rid of depreciation of fixed assets.
- Suitable: scenario where auto scaling is done at the granularity of minutes.
- Not suitable: scenario where auto scaling is done at the granularity of seconds.
(2020) Case Study: rt.live
rt.live, a measure of how COVID-19 is spreading for each state in the United States. Made by Instagram co-founders Mike Krieger and Kevin Systrom after their leaving Facebook.
Mike Krieger published a post on Medium: Automating daily runs for rt.live’s COVID-19 data using Airflow & ECS.
The goals of rt.live:
- Ran daily on a schedule
- Would re-try steps automatically if transient failures occurred
- Could run many US states in parallel, since each states’ ML model run doesn’t depend on other states
- Could be manually re-run for a subset of states without rerunning the whole thing, if we needed to make a data correction for just one or two states
The tools used are mainly: Apache Airflow and Amazon’s Elastic Constiner Service (ECS), especially Fargate. By using Fargate, they can build Docker containers as the Airflow workers, and can be scaled to N instances without worrying about creating and maintaining EC2 instances. Also it takes just 30 minutes everyday, that cost is managed.
(Image source: original post)
- Before starting the calculation, change the ECS service
desiredCount
to 25 and stand by. - Each ECS Task on Fargate is shared and stored in model code of Elastic File System (EFS).
- Use S3 to store original data from COVIDTracking.
- Put one Airflow task per state into the queue and let the ECS task (Airflow worker) execute it. The calculation result is also stored in S3.
- After the calculation of the day is completed, change the ECS service
desiredCount
back to 0.
Other extended reference materials, you can create similar pipelines: How to deploy Apache Airflow with Celery on AWS and Lessons learned deploying Apache Airflow to ECS.
Limits
Amazon ECS service quotas
- Memo: 2021/01 Amazon ECS announces increased service quotas for tasks per service and services per cluster
Adjustable
Service quota | Description | Default |
---|---|---|
Clusters | The maximum number of clusters in this account in the current Region. | 10,000 |
Container instances per cluster | The maximum number of container instances per cluster. | 2,000 |
Services per cluster | The maximum number of services per cluster. | 5,000 |
Tasks per service | The maximum number of tasks per service (the desired count). | 5,000 |
Non-Adjustable
Service quota | Description | Default |
---|---|---|
Tasks launched (count) per run-task | The maximum number of tasks that can be launched per RunTask API action. | 10 |
Container instances per start-task | The maximum number of container instances specified in a StartTask API action. | 10 |
Revisions per task definition family | The maximum number of revisions per task definition family. Deregistering a task definition revision does not exclude it from being included in this limit. | 1,000,000 |
Task definition size limit | The maximum size, in KiB, of a task definition. | 32 |
Task definition max containers | The maximum number of containers definitions within a a task definition. | 10 |
Subnets specified in an awsvpcConfiguration | The maximum number of subnets specified within an awsvpcConfiguration . | 16 |
Security groups specified in an awsvpcConfiguration | The maximum number of security groups specified within an awsvpcConfiguration . | 5 |
Target groups per service | The maximum number of target groups per service, if using an Application Load Balancer or a Network Load Balancer. | 5 |
Classic Load Balancers per service | The maximum number of Classic Load Balancers per service. | 1 |
Tags per resource | The maximum number of tags per resource. This applies to tasks, services, task definitions, clusters, and container instances. | 50 |
Pricing
Please refer to the latest official documents. This is just shorthand.
- According to Amazon ECS Launch Types, there are two categories.
Fargate Launch Type Model
- Charge according to the Fargate resources used. Refer to AWS Fargate pricing page. There is no additional charge for Amazon ECS.
EC2 Launch Type Model
- Charge according to the EC2 resources used. Refer to Amazon EC2 pricing page. There is no additional charge for Amazon ECS.
Amazon ECS on AWS Outposts
Cf. above EC2 Launch Type Model.
Deep Dive
The general direction is a path, but beware of pits on the ground.
- Scaling
- Deep Dive on Amazon ECS Cluster Auto Scaling, by Nick Coult, on 03 JAN 2020.
CapacityProviderReservation = M / N * 100
- M = desired count
- N = current count
- if N = M, scaling out is not required, and scaling in isn’t possible.
- if N < M, scale out is required because you don’t have enough instances.
- if N > M, scale in is possible (but not necessarily required).
- Deep Dive on Amazon ECS Cluster Auto Scaling, by Nick Coult, on 03 JAN 2020.
- Availability
- Amazon ECS availability best practices, by Malcolm Featonby, on 08 NOV 2019.
- Containers
- Deploy applications on Amazon ECS using Docker Compose, by Massimo Re Ferre, on 19 NOV 2020.
- How Amazon ECS manages CPU and memory resources, by Massimo Re Ferre and Samuel Karp, on 21 OCT 2019.
- Deployment
- Speeding up Amazon ECS container deployments, by Nathan Peck, on 19 OCT 2020.
- Load balancer healthchecks
- Default settings (Target group health check settings):
- HealthCheckIntervalSeconds: 30 seconds
- HealthyThresholdCount: 5
- Recommended settings (Target group health check settings):
- HealthCheckIntervalSeconds: 5 seconds
- HealthyThresholdCount: 2
- Default settings (Target group health check settings):
- Load balancer connection draining
- Default settings (Target group attributes):
- deregistration_delay.timeout_seconds: 300 seconds
- Recommended settings (Target group attributes):
- deregistration_delay.timeout_seconds: 5 seconds
- Default settings (Target group attributes):
- SIGTERM responsiveness
- Default setting (ECS agent setting):
- ECS_CONTAINER_STOP_TIMEOUT: 30 seconds
- Recommended setting (ECS agent setting):
- ECS_CONTAINER_STOP_TIMEOUT: 2 seconds
- Default setting (ECS agent setting):
- Container image pull behavior
- Default setting (ECS agent setting):
- ECS_IMAGE_PULL_BEHAVIOR:
default
- ECS_IMAGE_PULL_BEHAVIOR:
- Recommended setting (ECS agent setting):
- ECS_IMAGE_PULL_BEHAVIOR:
once
or alternativelyprefer-cached
- ECS_IMAGE_PULL_BEHAVIOR:
- Default setting (ECS agent setting):
- Deploy “steps”
- Default settings (ECS Service Deployment setting):
- minimumHealthyPercent: 100%
- maximumPercent: 200%
- Recommended setting (ECS Service Deployment setting):
- minimumHealthyPercent: 50%
- maximumPercent: 200%
- Default settings (ECS Service Deployment setting):
- Load balancer healthchecks
- Speeding up Amazon ECS container deployments, by Nathan Peck, on 19 OCT 2020.
- ECS Tasks
- Deep dive on load balanced ECS Service deployments with CloudFormation, by Philipp Garbe (AWS Hero), on 04 MAR 2020.
- Clearly organized and concise ECS Task Lifecycle Chart, Click here to enlarge view. The state relationship among
ECS Service
,ECS Task
, andALB
has been simplified.
- Clearly organized and concise ECS Task Lifecycle Chart, Click here to enlarge view. The state relationship among
- Deep dive on load balanced ECS Service deployments with CloudFormation, by Philipp Garbe (AWS Hero), on 04 MAR 2020.
Reference
Awesome Lists
- nathanpeck/awesome-ecs, 2021-01-01, by Nathan Peck (Developer Advocate, AWS)
Getting Started
- AWS Elastic Container Service 101, 2020-07-08, by Matt Gowie, at AWS Meetup Group in Denver
- GitHub repo: ecs-101-demo
Examples
- Disney+ is sharing some awesome stats about their usage of Amazon ECS, 2021-01-14, by Nathan Peck (Developer Advocate, AWS)
- Over 330k deployments since 2017; 700 unique applications; 40k ECS tasks deployed across clusters.
Articles & Talks
- How to use Multiple load balancer Target Group Support for Amazon ECS to access internal and external service endpoint using the same DNS name, 2019-12-12, by Vijay Menon
- The role of AWS Fargate in the container world, 2020-02-25, by Massimo Re Ferre (Principal Technologist at AWS)
- New look for Amazon ECS in the AWS Management Console, 2021-01-25, by Adam Keller (Developer Advocate on the AWS Container Services)
- 5 Steps: Using Amazon ECS Exec to pass through Fargate/ECS into containers, 2021-03-16, by Ernest Chiang (AWS Community Hero)
- AWS ECS Exec to access your containers, 2021-05-15, by MR. 沙先生 (shazi)
- Tool: aws-containers/amazon-ecs-exec-checker
- Building an Amazon ECS Anywhere home lab with Amazon VPC network connectivity, 2021-05-27, by Nathan Peck (Developer Advocate, AWS) (Amazon ECS GA)
- Under the hood: Amazon Elastic Container Service and AWS Fargate increase task launch rates, 2022-04-13, by Nathan Peck (Developer Advocate, AWS)
Comparison
- Scaling containers on AWS in 2020, 2020-04-15, by Vlad Ionescu (AWS Container Hero) (Reading time: about 20 minutes)
- Technical Selection: Amazon ECS Launch Types: EC2 vs. Fargate, 2020-12-04, by Ernest Chiang (AWS Community Hero), at AWS DEV DAY TAIPEI 2020
- Scaling containers on AWS in 2021, 2021-02-15, by Vlad Ionescu (AWS Container Hero) (Watching time: about 30 minutes)
- No Kubernetes Needed: Amazon ECS Anywhere, 2021-09-10, by Janakiram MSV
- Amazon ECS was launched in 2014 — a year before Kubernetes became available — as a managed container orchestration platform for AWS customers. It was modeled after Docker Compose, the tool that enabled multiple containers to run as a single workload. At re:Invent 2020, Amazon announced ECS Anywhere, the service that extends ECS to on-prem and other cloud environments. What this means is that ECS got an additional execution environment beyond EC2 and Fargate.
- Scaling containers on AWS in 2022, 2022-04-15, by Vlad Ionescu (AWS Container Hero) (Reading time: about 45 minutes. 6-month research.)