©2016,AmazonWebServices,Inc.oritsAffiliates.Allrightsreserved.
AbbyFuller,Sr TechnicalEvangelist,AWSPeterWong,Travelex
June28,2017
DeepDiveonMicroservices andECS
Agenda
• Whataremicroservices?• LightningECSoverview• Let’sgetfeaturespecific• FlexibleorchestrationandECS• Containerlifecyclewithecs-cli• Customerusecase:Travelex
Whataremicroservices?
”Serviceorientedarchitecturecomposedoflooselycoupledelementsthathaveboundedcontexts.”
- AdrianCockroft
Monolithvs.Microservices
webserver
.package
OrderUI
OrderService
InventoryService
ShippingService
OrderUI
ShippingService
OrderService
InventoryService
CharacteristicsofMicroserviceArchitectures
DoonethingwellIndependent
Decentralized
Blackbox
Polyglot
Youbuildit,yourunit
AmazonEC2ContainerService
AmazonEC2ContainerService(ECS)
Highlyscalable,highperformancecontainermanagementsystem.
Eliminatestheneedtoinstall,operate,andscaleyourowncontainermanagementinfrastructure.
AmazonEC2ContainerService(ECS)
ECSprovidesamanagedplatformfor:
Containerorchestration
DeepAWSintegration
Clustermanagement
HowdoesECSmaptotraditionalworkloads?
Instances:standardEC2boxes.OnceregisteredtoaCluster,yourTasksrunhere
Services:layerthatmanagesandplacesTasks
Tasks:containerwrapperandconfigurationaroundprocessesrunningontheinstance
WhoisusingECS?
…andmanymore!
WhyECS?
• Fullymanaged• Sharedstateoptimistic
scheduling• NativeCloudwatch integrationfor
monitoringandlogging• NativeintegrationwithCode*
servicesforCI/CD
ChooseyourownScheduler
BatchJobs
• ECStaskscheduler• Runtasksonce• Batchjobs• RunTask (random)StartTask(placed)
Long-RunningApps
ECSserviceschedulerHealthmanagementScale-upandscale-downAZawareGroupedcontainers
Let’sget(feature)specific
AmazonECSTaskPlacement
• Ataskplacementstrategyisanalgorithmforselectinginstancesfortaskplacement,ortasksfortermination
• Ataskplacementconstraintisaruletakenintoconsiderationduringtaskplacement
• Strategiesandconstraintscanbeusedtogether
Howcanstrategiesandpoliciesbeused?
Name Example
AMIID attribute:ecs.ami-id==ami-eca289fb
AvailabilityZone attribute:ecs.availability-zone==us-east-1a
InstanceType attribute:ecs.instance-type==t2.small
DistinctInstances type=“distinctInstances”
Custom attribute:stack==prod
Multiplestrategiesaresupported
???
Binpacking Random Spread
Howitworks
ClusterConstraints SatisfyCPU,memory,andportrequirements
Filterforlocation,instance-type,AMI,orcustomattributeconstraintsIdentifyinstancesthatmeetspreadorbinpackplacementstrategy
Selectfinalcontainerinstancesforplacement
CustomConstraints
PlacementStrategies
Applyfilter
AmazonECSEventStreamforCloudwatchLogs• Receivenearreal-timeupdatesaboutboththecurrentstateofboththecontainerinstanceswithintheECSCluster,andthecurrentstateofalltasksrunningonthosecontainerinstances.• Canbeusedtobuildcustomschedulers,ortomonitorclusterstateandhandlethosestatechangesbyconsumingeventswithotherAWSservices,suchasLambda.
FlexibleorchestrationandECS
Flexibilityisaboutchoices
Orchestrationplatformsshouldhave:
• Sensibledefaults• Theabilitytoextendandcustomize
Pickone,oracombinationofboth.
Firstoff:youhaveoptions
Spoileralert:Iliketheconsole
Whytheconsole?• JSON• Quickertotestandgetstarted• Visualfeedback• JSON
Buttheconsoleisnotforeveryone
Ifyou’recustomizingorautomating,theCLImightbeabetterchoice.
Enterecs-cli:• Opensource• TakesDockercomposefiles• UsedtomanagecontainerlifecyclesfromstarttofinishonECS
I<3CLIs
Containerlifecyclewithecs-cli
Firststop:creatingacluster
$ aws ecs create-cluster --cluster-name ”summit"
Shouldreturnsomethinglike:
{
"cluster": {
"status": "ACTIVE",
"clusterName": ”summit",
"registeredContainerInstancesCount": 0,
"pendingTasksCount": 0,
"runningTasksCount": 0,
"activeServicesCount": 0,
}
}
Then,createatask
$ aws ecs register-task-definition --cli-input-jsonfile://path/summit.json
YoucanalsouseaJSONstring:
$ aws ecs register-task-definition --family summit --container-definitions "[{\"name\":\”summit\",\"image\":\”alpine\",\"cpu\":10,\"command\":[\"sleep\",\"360\"],\"memory\":10,\"essential\":true}]"
Next,useourtasktocreateaservice
$ aws ecs create-service --service-name summit--task-definition summit --desired-count 2
Youcanaddmoreparametershere,suchasplacementstrategy.YoucanalsoregisteryournewservicewithanELB/ALB.
Summitsareprettypopular.Let’sscaleup.
$ aws ecs update-service --service summit --desired-count 4
Wecouldusethissamecommandtoscaledown(whichwe’lllookatnext),butalsotoupdatethetaskdefinition.Effectively,deployanewversion!
Wedon’twanttowasteresourcesthough,solet’sscalebackdown
$ aws ecs update-service --service my-http-service --desired-count 2
Inaproductionenvironment,thisissomethingwemightwanttohandleinresponsetootherevents:autoscaling!
Wecanalsoquerystate
$ aws ecs describe-services --service summit
ThisreturnsATONofinformationaboutourservice:mostimportantly,itshowsusourcurrentdeployment,andwhateventsarehappeninginourcluster:
"events": [{
"message": "(service summit) has reached a steady state."
ByeLondon!
$ aws ecs delete-cluster --cluster summit
Importanttonotethatwehavetoscaleourservicedownto0,andremovetheservicebeforerunningthis:justincase!
$ aws ecs update-service --service summit --desired-count 0
$ aws ecs delete-service --service summit
Customerusecase:TravelexPeterWong
FirstopenedinLondonin1976,Travelexisaworldleadingforeignexchangeexpertwithpresencein29countries,agrowingonlineandmobileforeignexchangeplatformandanetworkof1,000ATMsand1,500stores
Travelexataglance
Travelexataglance1980
35
1990 2000 2010
1976:FirststoreopensinSouthamptonRow,London
1982:FirstferryoutletopensontheP&O
ferryservingRotterdam
1984:Firstoverseasbranchopensinthe
Netherlands,NorthSeaterminal,Rotterdam
1986:Firstnon-bankFXprovideratHeathrowT4
1989:FirstbranchesopenedintheUSA,inJFK
airport
1990:FirstbranchesopenedinAustralia,Brisbane(Domesticterminal)
2016:40th anniversary
2015:FirstexclusiveforeignexchangeprovideratHeathrow
airport
2015:TravelexsoldtoDrShettyandMrSaeed
BinButti
2014:Travelexembarksondigital
transformationstrategy
2004:TravelexopensinChina
2003:TravelexopensinIndiaandtheMiddleEast(inOman)
2003:TravelexpartnerswiththeNationalTheatretolaunch
Travelexticketseason
2001:TravelexacquiresThomasCookFS
1999:Travelexacquires
Barclay’sFXintheUK– start
ofvault
1995:AbbeyNationalbuysa33%stakeofTravelex–takeoveroftheirFX
2017:TravelexWirelaunches
• Deliverinternationalpaymentssecurely atscale
• EngineeringChallenges:• E2EEncryption• E2EAuditability(build,test,release,deploy,runtime)– compliance• Ingressandegresssecurity• Multi-tenancy– multipleclients• ReusableAPIdrivencomponents– crossproducts• ContinuousDeployment• 24/7operations
Engineering@Travelex
36
• Singlefunction• Composable• Reducerisks• Reducetimetomarket• Increasedevelopmentflexibility• Increaseoperationalflexibility• …
Developmicro-servicesarchitecture
37
38
• Codebase• Dependencies• Config• Backingservices• Build,Release,Run• Process
• Portbinding• Concurrency• Disposability• Dev/prodparity• Logs• Adminprocess
Developmicro-servicesarchitecturefollowing12-FactorApp
39
• Codebase• Dependencies• Config• Backingservices• Build,Release,Run• Process
• Portbinding• Concurrency• Disposability• Dev/prodparity• Logs• Adminprocess
Developmicro-servicesarchitecturefollowing12-FactorAppwithAWSECS
40
• Codebase• Dependencies• Config• Backingservices• Build,Release,Run• Process• Portbinding
• Concurrency• Disposability• Dev/prodparity• Logs• Adminprocess
Developmicro-servicesarchitecturefollowing12-FactorAppwithAWSECS
41
42
• Cloudfront• ClassicELB• RDS• ECS• Route53• SES• SQS• SNS• S3• Nginx(reverseproxy)
ServiceprovisioningviaCloudformation
43
• Cloudfront toNginx• ServicetoService• ServicetoInternet
(3rd parties)• ServicetoRDS• Hashicorp Vault(PKI)
E2EIngressandEgressFlows
• Retrievearatefroma3rd party• Apply%margin• Applynumericalmethodstofixquoteside
Example:fetchingarate
44
45
Thank You
46
Thankyou!