Deep Dive on Microservices and ECS Abby Fuller, Sr Technical Evangelist, AWS Peter Wong, Travelex June 28, 2017 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Agenda What are microservices? Lightning ECS overview Let s get feature specific Flexible orchestration and ECS Container lifecycle with ecs-cli Customer use case: Travelex
What are microservices?
Service oriented architecture composed of loosely coupled elements that have bounded contexts. - Adrian Cockroft
Monolith vs. Microservices Order UI Order Service Inventory Service Shipping Service.package webserver OrderUI Inventory Service Order Service Shipping Service
Characteristics of Microservice Architectures Decentralized Polyglot Independent Do one thing well Black box You build it, you run it
Amazon EC2 Container Service
Amazon EC2 Container Service (ECS) Highly scalable, high performance container management system. Eliminates the need to install, operate, and scale your own container management infrastructure.
Amazon EC2 Container Service (ECS) ECS provides a managed platform for: Deep AWS integration Container orchestration Cluster management
How does ECS map to traditional workloads? Instances: standard EC2 boxes. Once registered to a Cluster, your Tasks run here Services: layer that manages and places Tasks Tasks: container wrapper and configuration around processes running on the instance
Who is using ECS? and many more!
Why ECS? Fully managed Shared state optimistic scheduling Native Cloudwatch integration for monitoring and logging Native integration with Code* services for CI/CD
Choose your own Scheduler Batch Jobs ECS task scheduler Run tasks once Batch jobs RunTask (random) StartTask (placed) Long-Running Apps ECS service scheduler Health management Scale-up and scale-down AZ aware Grouped containers
Let s get (feature) specific
Amazon ECS Task Placement A task placement strategy is an algorithm for selecting instances for task placement, or tasks for termination A task placement constraint is a rule taken into consideration during task placement Strategies and constraints can be used together
How can strategies and policies be used? Name AMI ID Availability Zone Instance Type Distinct Instances Custom Example attribute:ecs.ami-id == ami-eca289fb attribute:ecs.availability-zone == us-east-1a attribute:ecs.instance-type == t2.small type= distinctinstances attribute:stack == prod
Multiple strategies are supported??? Binpacking Random Spread
How it works 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
Amazon ECS Event Stream for Cloudwatch Logs Receive near real-time updates about both the current state of both the container instances within the ECS Cluster, and the current state of all tasks running on those container instances. Can be used to build custom schedulers, or to monitor cluster state and handle those state changes by consuming events with other AWS services, such as Lambda.
Flexible orchestration and ECS
Flexibility is about choices Orchestration platforms should have: Sensible defaults The ability to extend and customize Pick one, or a combination of both.
First off: you have options
Spoiler alert: I like the console Why the console? JSON Quicker to test and get started Visual feedback JSON
But the console is not for everyone If you re customizing or automating, the CLI might be a better choice. Enter ecs-cli: Open source Takes Docker compose files Used to manage container lifecycles from start to finish on ECS I <3 CLIs
Container lifecycle with ecs-cli
First stop: creating a cluster $ aws ecs create-cluster --cluster-name summit" Should return something like: { } } "cluster": { "status": "ACTIVE", "clustername": summit", "registeredcontainerinstancescount": 0, "pendingtaskscount": 0, "runningtaskscount": 0, "activeservicescount": 0,
Then, create a task $ aws ecs register-task-definition --cli-input-json file://path/summit.json You can also use a JSON string: $ aws ecs register-task-definition --family summit -- container-definitions "[{\"name\":\ summit\",\"image\":\ alpine\",\"cpu\":10,\ "command\":[\"sleep\",\"360\"],\"memory\":10,\"essential \":true}]"
Next, use our task to create a service $ aws ecs create-service --service-name summit--taskdefinition summit --desired-count 2 You can add more parameters here, such as placement strategy. You can also register your new service with an ELB/ALB.
Summits are pretty popular. Let s scale up. $ aws ecs update-service --service summit --desiredcount 4 We could use this same command to scale down (which we ll look at next), but also to update the task definition. Effectively, deploy a new version!
We don t want to waste resources though, so let s scale back down $ aws ecs update-service --service my-http-service -- desired-count 2 In a production environment, this is something we might want to handle in response to other events: autoscaling!
We can also query state $ aws ecs describe-services --service summit This returns A TON of information about our service: most importantly, it shows us our current deployment, and what events are happening in our cluster: "events": [ { "message": "(service summit) has reached a steady state."
Bye London! $ aws ecs delete-cluster --cluster summit Important to note that we have to scale our service down to 0, and remove the service before running this: just in case! $ aws ecs update-service --service summit --desiredcount 0 $ aws ecs delete-service --service summit
Customer use case: Travelex Peter Wong
Travelex at a glance First opened in London in 1976, Travelex is a world leading foreign exchange expert with presence in 29 countries, a growing online and mobile foreign exchange platform and a network of 1,000 ATMs and 1,500 stores
Travelex at a glance 1980 1990 2000 2010 1976: First store opens in Southampton Row, London 1982: First ferry outlet opens on the P&O ferry serving Rotterdam 1984: First overseas branch opens in the Netherlands, North Sea terminal, Rotterdam 1986: First non-bank FX provider at Heathrow T4 1990: First branches opened in Australia, Brisbane (Domestic terminal) 1989: First branches opened in the USA, in JFK airport 1995: Abbey National buys a 33% stake of Travelex takeover of their FX 1999: Travelex acquires Barclay s FX in the UK start of vault 2001: Travelex acquires Thomas Cook FS 2003: Travelex partners with the National Theatre to launch Travelex ticket season 2003: Travelex opens in India and the Middle East (in Oman) 2004: Travelex opens in China 2014: Travelex embarks on digital transformation strategy 2015: Travelex sold to Dr Shetty and Mr Saeed Bin Butti 2015: First exclusive foreign exchange provider at Heathrow airport 2016: 40 th anniversary 2017: Travelex Wire launches 35
Engineering @ Travelex Deliver international payments securely at scale Engineering Challenges: E2E Encryption E2E Auditability (build, test, release, deploy, runtime) compliance Ingress and egress security Multi-tenancy multiple clients Reusable API driven components cross products Continuous Deployment 24/7 operations 36
Develop micro-services architecture Single function Composable Reduce risks Reduce time to market Increase development flexibility Increase operational flexibility 37
38
Develop micro-services architecture following 12-Factor App Codebase Dependencies Config Backing services Build, Release, Run Process Port binding Concurrency Disposability Dev/prod parity Logs Admin process 39
Develop micro-services architecture following 12-Factor App with AWS ECS Codebase Dependencies Config Backing services Build, Release, Run Process Port binding Concurrency Disposability Dev/prod parity Logs Admin process 40
Develop micro-services architecture following 12-Factor App with AWS ECS Codebase Dependencies Config Backing services Build, Release, Run Process Port binding Concurrency Disposability Dev/prod parity Logs Admin process 41
Service provisioning via Cloudformation Cloudfront Classic ELB RDS ECS Route 53 SES SQS SNS S3 Nginx (reverse proxy) 42
E2E Ingress and Egress Flows Cloudfront to Nginx Service to Service Service to Internet (3 rd parties) Service to RDS Hashicorp Vault (PKI) 43
Example: fetching a rate Retrieve a rate from a 3 rd party Apply % margin Apply numerical methods to fix quote side 44
45
Thank You 46
Thank you!