![Page 1: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/1.jpg)
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Julien SimonPrincipal Technical Evangelist, AWS
@julsimon
Advanced Task Scheduling with Amazon ECS
![Page 2: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/2.jpg)
Docker on Amazon Web Services
Amazon EC2 Container Service (ECS)• https://aws.amazon.com/ecs/• Launched in 04/2015• No additional charge
Amazon EC2 Container Registry (ECR)• https://aws.amazon.com/ecr/• Launched in 12/2015• Free tier: 500MB / month for a year• $0.10 / GB / month + outgoing traffic
Both services are available in US, EU and APAC
![Page 3: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/3.jpg)
ECS adoption
https://www.datadoghq.com/blog/3-clear-trends-in-ecs-adoption/November 2016
![Page 4: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/4.jpg)
Companies
Selected ECS customers
![Page 5: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/5.jpg)
Container Partners
https://aws.amazon.com/containers/partners/
![Page 6: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/6.jpg)
ECS Scheduling
![Page 7: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/7.jpg)
The problem
Given a certain amount of computing power and memory,
how can we best manage an arbitrary number of apps
running in Docker containers?http://tidalseven.com
![Page 8: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/8.jpg)
Amazon ECS: Under the Hood
ALB ALB
AZ 1 AZ 2
user / scheduler
https://github.com/aws/amazon-ecs-agenthttp://www.allthingsdistributed.com/2015/07/under-the-hood-of-the-amazon-ec2-container-service.html
![Page 9: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/9.jpg)
Scheduling on ECS: two options so far
1. Let ECS handle scheduling through Services• Task Definition
• ECS transcription of the Docker Compose file• Versioning• cpu_shares, mem_limit
• Number of desired containers2. Implement a custom scheduler with the ECS API
• Describe cluster state• Select a specific ECS instance according to custom logic• Run task on this instance• Coursera use case: www.youtube.com/watch?v=a45J6xAGUvA
![Page 10: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/10.jpg)
ECS Placement Engine
![Page 11: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/11.jpg)
Placement Engine: giving developers more control
ALB ALB
AZ 1 AZ 2
user / scheduler
Placement Engine
Constraints& Strategies
![Page 12: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/12.jpg)
Placement Constraints
Name Example
AMI ID attribute:ecs.ami-id == ami-eca289fb
Availability Zone attribute:ecs.availability-zone == us-east-1a
Instance Type attribute:ecs.instance-type == t2.small
Distinct Instances type=“distinctInstance”
Custom attribute:stack == prod
![Page 13: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/13.jpg)
Example: Constraint on Instance Family/Type
![Page 14: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/14.jpg)
Example: Constraint on Availability Zone
![Page 15: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/15.jpg)
Example: Combining Multiple Constraints
![Page 16: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/16.jpg)
Placement Strategies
Binpacking Spread Affinity Distinct Instance
![Page 17: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/17.jpg)
Placement Strategy Chaining
Spread tasks across Zonesand Binpack within each Zone
![Page 18: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/18.jpg)
Placing Tasks
![Page 19: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/19.jpg)
Anatomy of Task Placement
Cluster Constraints
Custom Constraints
Placement Strategies
Apply Filter
Satisfy CPU, memory, and port requirements
Filter for location, instance-type, AMI, or custom attribute constraints
Identify instances that meet spread or binpack placement strategy
Select final container instances for placement
![Page 20: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/20.jpg)
g2.2xlarge t2.small g2.2xlarge g2.2xlarge
Placement: Targeting Instance Type
![Page 21: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/21.jpg)
g2.2xlarge t2.small t2.micro t2.medium
t2.medium t2.small g2.2xlarge
t2.small
t2.small t2.medium
us-east-1aus-east-1d
Placement: Targeting Instance Type & Zone
![Page 22: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/22.jpg)
g2.2xlarge t2.small t2.micro t2.medium
t2.medium t2.small g2.2xlarge t2.small
us-east-1aus-east-1d
g2.2xlarge t2.medium
t2.micro t2.small
us-east-1c
Placement: Availability Zone Spread
![Page 23: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/23.jpg)
g2.2xlarge t2.small t2.micro t2.medium
t2.medium t2.small g2.2xlarge t2.small
us-east-1aus-east-1d
g2.2xlarge t2.medium
t2.micro t2.small
us-east-1c
Placement: Spread across Zone and Binpack
![Page 24: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/24.jpg)
g2.2xlarge t2.small t2.micro t2.medium
t2.medium t2.small g2.2xlarge t2.small
us-east-1aus-east-1d
g2.2xlarge t2.medium
t2.micro t2.small
us-east-1c
Placement: Affinity and Anti-Affinity
![Page 25: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/25.jpg)
Running a Service
![Page 26: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/26.jpg)
t2.medium t2.small t2.small
us-east-1aus-east-1d
t2.medium t2.micro t2.small
us-east-1c
Placement: Multiple Services on a Cluster
![Page 27: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/27.jpg)
t2.medium g2.2xlarge t2.micro t2.small
t2.small t2.small g2.2xlarge t2.small
t2.small t2.small
g2.2xlarge t2.small
Placement: Services – Distinct Instances
![Page 28: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/28.jpg)
Event Stream & Blox
![Page 29: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/29.jpg)
Amazon ECS: Under the Hood
ALB ALB
AZ 1 AZ 2
user / scheduler
Placement Engine
Event Stream
![Page 30: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/30.jpg)
Consuming Real-time Events
![Page 31: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/31.jpg)
Handling ECS events with Blox
scheduler cluster state service
https://blox.github.io/
![Page 32: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/32.jpg)
Amazon ECS: Under the Hood
ALB ALB
AZ 1 AZ 2
user / scheduler
Scheduler
Cluster State Service
Placement Engine
Event Stream
![Page 33: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/33.jpg)
t2.small t2.small t2.small
Blox: Daemon Scheduler
t2.small t2.small t2.small
scheduler cluster state service
t2.small t2.small t2.small
![Page 34: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/34.jpg)
Demo: Deploying Blox on AWS
![Page 35: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/35.jpg)
Creating Clusters
Create an ECS cluster for BloxCF template: https://github.com/blox/blox/blob/dev/deploy/aws/conf/cloudformation_template.jsonà CloudWatch Event Rule + SQS queueà 3 containers: Daemon Scheduler + Cluster State Service + etcdà REST API exposing the Daemon Scheduler API
Create another ECS cluster managed by Blox$ ecs-cli configure --cluster WebCluster$ ecs-cli up --keypair admin --capability-iam --size 3 --instance-type t2.micro
Invoke the scheduler API‘demo-cli’ tool: https://github.com/blox/blox/tree/dev/deploy/demo-cli
![Page 36: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/36.jpg)
Listing Task Definitions
Grab the ARN for an nginx Task Definition, which the Daemon Scheduler will manage on ‘WebCluster’.
$ ./list-task-definitions.py --region eu-central-1
== Blox Demo CLI - List Task Definitions =={"taskDefinitionArns": ["arn:aws:ecs:eu-central-1:ACCOUNT:task-definition/BloxFramework:2","arn:aws:ecs:eu-central-1:ACCOUNT:task-definition/nginx:1","arn:aws:ecs:eu-central-1:ACCOUNT:task-definition/nginx:2"
]}
![Page 37: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/37.jpg)
Creating an Environment
$ ./blox-create-environment.py --environment WebEnvironment --cluster WebCluster --task-definition "arn:aws:ecs:eu-central-1:ACCOUNT:task-definition/nginx:2" --stack Blox --apigateway --region eu-central-1
== Blox Demo CLI - Create Blox Environment ==HTTP Response Code: 200
{"taskDefinition": "arn:aws:ecs:eu-central-1:ACCOUNT:task-definition/nginx:2","deploymentToken": "17248257-08ec-4438-888f-e0ac28397653","health": "healthy","name": "WebEnvironment","instanceGroup": {
"cluster": "arn:aws:ecs:eu-central-1:ACCOUNT:cluster/WebCluster"}
}
![Page 38: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/38.jpg)
Listing Environments$ ./blox-list-environments.py --stack Blox --apigateway --region eu-central-1
== Blox Demo CLI - List Blox Environments ==HTTP Response Code: 200
{"items": [
{"taskDefinition": "arn:aws:ecs:eu-central-1:ACCOUNT:task-definition/nginx:2","deploymentToken": "17248257-08ec-4438-888f-e0ac28397653","health": "healthy","name": "WebEnvironment","instanceGroup": {
"cluster": "arn:aws:ecs:eu-central-1:ACCOUNT:cluster/WebCluster"}
}]
}
![Page 39: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/39.jpg)
Creating a Deployment
$ ./blox-create-deployment.py --environment WebEnvironment--deployment-token "17248257-08ec-4438-888f-e0ac28397653" --stack Blox --apigateway --region eu-central-1
== Blox Demo CLI - Create Blox Deployment ==HTTP Response Code: 200
{"status": "pending","environmentName": "WebEnvironment","id": "7a05ea99-27a9-4339-a7a6-f4120065aea3","failedInstances": [],"taskDefinition": "arn:aws:ecs:eu-central-1:613904931467:task-definition/nginx:2”
}
![Page 40: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/40.jpg)
Listing Deployments$ ./blox-list-deployments.py --environment WebEnvironment --stack Blox--apigateway --region eu-central-1
== Blox Demo CLI - List Blox Deployments ==HTTP Response Code: 200
{"items": [
{"status": "completed","environmentName": "WebEnvironment","id": "7a05ea99-27a9-4339-a7a6-f4120065aea3","failedInstances": [],"taskDefinition": "arn:aws:ecs:eu-central-1:ACCOUNT:task-definition/nginx:2"
}]
}
![Page 41: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/41.jpg)
Scaling a Deployment
$ ecs-cli ps Name State Ports TaskDefinition 26313cbe-d929-49de-9cc3-873bf5f32a91/nginx RUNNING nginx:2 98442432-fd5c-434d-b93c-0737bd06aaab/nginx RUNNING nginx:2 ce9bf217-4b34-4f31-9c7b-a8c3402f1ffd/nginx RUNNING nginx:2
$ ecs-cli scale --size 4 --capability-iam
$ ecs-cli ps Name State Ports TaskDefinition 26313cbe-d929-49de-9cc3-873bf5f32a91/nginx RUNNING nginx:2 98442432-fd5c-434d-b93c-0737bd06aaab/nginx RUNNING nginx:2 c404ac9a-0948-4cc8-b5b0-2238ccdf4035/nginx RUNNING nginx:2 ce9bf217-4b34-4f31-9c7b-a8c3402f1ffd/nginx RUNNING nginx:2
![Page 42: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/42.jpg)
Additional resourcesECS customershttps://www.mapbox.com/blog/switch-to-ecs/https://segment.com/blog/rebuilding-our-infrastructure/
Tech articles by Werner Vogels, CTO, Amazon.comhttp://www.allthingsdistributed.com/2014/11/amazon-ec2-container-service.htmlhttp://www.allthingsdistributed.com/2015/04/state-management-and-scheduling-with-ecs.htmlhttp://www.allthingsdistributed.com/2015/07/under-the-hood-of-the-amazon-ec2-container-service.html
Blog articles & videoshttps://aws.amazon.com/blogs/compute/amazon-ec2-container-service-at-aws-reinvent-2016-wrap-up/https://aws.amazon.com/blogs/compute/continuous-deployment-to-amazon-ecs-using-aws-codepipeline-aws-codebuild-amazon-ecr-and-aws-cloudformation/
![Page 43: Advanced Task Scheduling with Amazon ECS - Julien Simon](https://reader031.vdocuments.net/reader031/viewer/2022022415/5a6770097f8b9a0a2e8b495f/html5/thumbnails/43.jpg)
Thank you!
Julien SimonPrincipal Technical Evangelist, AWS
@julsimon