Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
ECS Events & Lambda でカジュアルにはじめるコンテナスケジューラー / 20...
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Taro Hirose
December 12, 2017
Technology
1.5k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
ECS Events & Lambda でカジュアルにはじめるコンテナスケジューラー / 20171212_jawsug-container-lt
JAWS-UG コンテナ支部 #10 - connpass
https://jawsug-container.connpass.com/event/71130/
Taro Hirose
December 12, 2017
More Decks by Taro Hirose
See All by Taro Hirose
令和の時代におけるライブ動画サービスの作り方 / How to build your Live video streaming service in Reiwa era
uorat
0
160
Amazon IVS ROCKS!
uorat
1
400
OPENREC.tv におけるライブ動画およびメッセージ配信基盤の全貌 / 20170601_aws_devday_tokyo_openrec
uorat
4
5.2k
AWS re:Invent 2016 参加レポート / reinvent2016_report
uorat
0
2k
ライブ視聴を支える配信基盤の話をざっくりと / livestreaming-dogenzakabeerbash
uorat
2
1.6k
構成管理ツール Ansible 実践 / ansible-seminar-20160715
uorat
0
1.1k
ライブ視聴を支えるリアルタイムメッセージ配信基盤の話 / GunosyBeerBash #6
uorat
0
4.6k
Ansible 入門 #01 (初心者向け) / ansible-entry
uorat
1
270
Other Decks in Technology
See All in Technology
Code for Security プロジェクト紹介 2026年10月
yu23ki14
0
120
sue445's proposals 2026
sue445
0
130
React改造してみた
tsukina_7mochi
0
150
How to Design Configuration for Rails Applications
willnet
1
1.1k
企画を Software Factory-ready にする——開発が高速になったとき、PdMの仕事はどう変わったか
yachibit
1
130
こんにちは!SORACOM です & IoT とは【SORACOM UG 東北 in 八戸】
soracom
PRO
0
170
M5Stackで作る BLEマウス GPSログの世界
tomokusaba
PRO
0
460
AIネイティブ企業への変革。パーソルキャリアが挑む「データメッシュ×ガバナンス」のアーキテクチャ戦略
techtekt
PRO
0
120
コンテナ運用におけるネットワーク・コンテナコストの削減方法/How to Reduce Network and Container Costs in Container Operations
masakiokuda
2
370
ソフトウェア ファクトリー - 再現性のあるソフトウェアの工場づくり / Software factory
iktakahiro
7
5.3k
国際カードブランドルール変更に伴うクレジットカード決済取引仕様変更について
k1style
0
140
Browser Spec: Testing Hotwire with Ruby
takahashim
1
160
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
142
7.8k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
630
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.9k
Docker and Python
trallard
47
4.2k
Utilizing Notion as your number one productivity tool
mfonobong
4
620
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
310
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
850
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1.1k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
270
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
280
Writing Fast Ruby
sferik
630
63k
Transcript
ECS Events & Lambda ͰΧδϡΞϧʹ࢝ ΊΔίϯςφεέδϡʔϥʔ JAWS-UG Container ࢧ෦ #10
2017.12.12 (Tue) LT
whoami ኍ ଠ / Taro Hirose ▸ OPENREC.tv / CyberZ,
Inc. ▸ Backend Engineer ▸ id: @uorat ▸ http://uorat.hatenablog.com
ECS Events Introduction
ECS Event is Կ ECS Cluster Ϧιʔεͷঢ়ଶมߋʹԠͯ͡௨͞ΕΔ CloudWatch Events ▸
ҎԼͷঢ়ଶมߋΠϕϯτΛडऔՄೳ ▸ Container Instance ▸ Task ▸ 2016.11.25 ։௨ ▸ Amazon ECSΠϕϯτετϦʔϜͰɺΫϥελͷঢ়ଶΛࢹ | Amazon Web Services ϒϩά ▸ https://aws.amazon.com/jp/blogs/news/monitor-cluster-state-with-amazon-ecs-event-stream/ Amazon ECS CloudWatch Events Lambda Event Stream Events SNS Kinesis
ECS Event is Կ e.g. Task ىಈ { "version": "0",
"id": "451dda85-ca1a-9045-5121-7a12dfb9317f", "detail-type": "ECS Task State Change", "source": "aws.ecs", "account": "123456789012", "time": "2017-09-07T08:28:04Z", "region": "ap-northeast-1", "resources": [ "arn:aws:ecs:ap-northeast-1:123456789012:task/b280d725-7382-43b8-a50d-ef909a36cb80" ], "detail": { "clusterArn": "arn:aws:ecs:ap-northeast-1:123456789012:cluster/uorat-ecs-event-test", "containerInstanceArn": "arn:aws:ecs:ap-northeast-1:123456789012:container-instance/ff83c4a8-67fc-4a13-8134-897c6dd2195a", ... "desiredStatus": "RUNNING", ... "lastStatus": "PENDING", ... "taskDefinitionArn": "arn:aws:ecs:ap-northeast-1:123456789012:task-definition/uorat-ecs-event-test:35", ... } } ECS Task Event
ECS Event is Կ Կ͕Ͱ͖Δͷʁ ▸ “ECSΠϕϯτετϦʔϜͰΫϥελͷঢ়ଶΛࢹ” ΑΓҾ༻ ▸ https://aws.amazon.com/jp/blogs/news/monitor-cluster-state-with-amazon-ecs-event-stream/
▸ “͜ͷใΛͬͯɺίϯςφͷஔͱεέʔϧΛࣗಈԽ͢Δ͜ͱՄೳͰɺΫϥελΛඇৗʹਫ਼ີͳϨ ϕϧͰ”ਖ਼͍͠αΠζ”ʹ͢Δ͜ͱ͕Ͱ͖·͢ɻϓϧܕͰͳ͘ΠϕϯτۦಈͰΫϥελͷঢ়ଶͷใΛ४ ϦΞϧλΠϜͰૹ͢Δ͜ͱʹΑΓɺECSΠϕϯτετϦʔϜػೳίϯςφΠϯϑϥͷࢹͱεέʔϧ ʹରͯ͠ඇৗʹൣғͳՄೳੑΛఏڙ͍ͯ͠·͢ɻ”
ECS Event is Կ ΠϕϯτۦಈͳλεΫඋγεςϜ࿈ܞ ▸ ྫ͑ ▸ λεΫͷՔಈཤྺΛ Elasticsearch
DynamoDB ʹอଘͯ͠ղੳ༻ʹ׆༻ ▸ λεΫίϯςφΠϯελϯεͷىಈ/ఀࢭ࣌ʹԿ͔͠ΒͷॲཧΛ࣮ߦ ▸ ࢹγεςϜ࿈ܞ
ECS Event is Կ e.g. ▸ Container Scheduler for Amazon
ECS ▸ re:Invent 2016 Ͱެ։͞Εͨ golang OSS ▸ ECS Cluster ༻ͷΧελϜεέδϡʔϥΛ࣮Մೳ ▸ ECS Cluster ͷΠϕϯτݕ ▸ ECS Cluster ͷঢ়ଶ ▸ ΧελϜεέδϡʔϥʔͷ࣮ߦ ▸ REST API ͷఏڙ
OPENREC.tv Case
Case: OPENREC.tv ήʔϜʹಛԽͨ͠ಈը৴ϝσΟΞ ▸ Ԇɾߴը࣭ ▸ ίϯςϯπͷ9ׂUGC ▸ ϢʔβʔओಋͷϥΠϒ৴͕த৺ ▸
ಉ࣌৴৴࣌ؒ৴ऀ࣍ୈ ▸ ू٬ྗ৴ऀ࣍ୈ ▸ ∴ ෛՙ͕ಡΈͮΒ͍ ▸ ಉ࣌ࢹௌऀ ແ੍ݶ ▸ ͍ΘΏΔ “” ແ͍ ▸ શϢʔβʔ͘͠ϥΠϒࢹௌͰ͖Δ͜ͱ
None
Architecture of live transcoding system CloudWatch Events (scheduled/1min, ECS Event
Stream) + Lambda + API ECS Cluster Broadcaster Container Instance Task (Container) Broadcaster Container Instance Task (Container) Broadcaster Container Instance Task (Container) Container Instance Aurora LIVE API ELB EC2 RDS CloudWatch Events & Lambda ec2:RunInstances ecs:RunTask ecs:StopTask ec2:StopInstances … ECS Events
Architecture of live transcoding system ▸ EC2/ECS Auto Scaling ૬ੑ͕ѱ͍
▸ RTMP = ৗ࣌ଓ ▸ ෛՙ͕ͯ͘৴͍ͯ͠ΕॖୀͰ͖ͳ͍ ▸ “৴ঢ়گ” ͱ͍͏ಠࣗࢦඪʹج͍ͮͯ εέʔϧ ͤ͞Δεέδϡʔϥʔ͕ඞཁ ▸ Rolling Deploy ͷਏΈ ▸ ৴ऴྃϢʔβʔ࣍ୈ ▸ ৴͕ऴΘΔ·Ͱجຊతʹམͱͤͳ͍ ▸ தʹ 24 ࣌ؒ৴…
Architecture of live transcoding system Stateful application, but disposability ECS
Cluster Broadcaster Container Instance Task (Container) Broadcaster Container Instance Task (Container) Broadcaster Container Instance Task (Container) Container Instance Aurora LIVE API ELB EC2 RDS CloudWatch Events & Lambda ec2:RunInstances ecs:RunTask ecs:StopTask ec2:StopInstances … ECS Events
Architecture of live transcoding system Expire >> Drain >> Stop
Container ECS Cluster Broadcaster Container Instance Task (Container) Broadcaster Container Instance Task (Container) Container Instance Aurora LIVE API ELB EC2 RDS CloudWatch Events & Lambda ec2:RunInstances ecs:RunTask ecs:StopTask ec2:StopInstances … ECS Events Broadcaster Container Instance Task (Container)
Architecture of live transcoding system Expire >> Drain >> Stop
Container ECS Cluster Broadcaster Container Instance Task (Container) Broadcaster Container Instance Task (Container) Container Instance Aurora LIVE API ELB EC2 RDS CloudWatch Events & Lambda ec2:RunInstances ecs:RunTask ecs:StopTask ec2:StopInstances … ECS Events Container Instance Task (Container)
Architecture of live transcoding system Expire >> Drain >> Stop
Container ECS Cluster Broadcaster Container Instance Task (Container) Broadcaster Container Instance Task (Container) Container Instance Aurora LIVE API ELB EC2 RDS CloudWatch Events & Lambda ec2:RunInstances ecs:RunTask ecs:StopTask ec2:StopInstances … ECS Events Container Instance
Architecture of live transcoding system ৴/৴ෛՙʹԠͯ͡ Container Instance Λ
AutoScale ▸ ϦϦʔε `docker image push` ͢Εɺউखʹ৽Πϝʔδ͕ਁಁ͢Δ ECS Cluster Broadcaster Container Instance Task (Container) Broadcaster Container Instance Task (Container) Broadcaster Container Instance Task (Container) Container Instance Aurora LIVE API ELB EC2 RDS CloudWatch Events & Lambda ec2:RunInstances ecs:RunTask ecs:StopTask ec2:StopInstances … ECS Events
w/ ECS Events Case
Case1: Monitoring Tasks Container/Application ࢹͷࣗಈઃఆ ▸ Task ͷঢ়ଶมԽʹԠͯ͡ ࢹ ON/OFF
1. Task ։࢝ → JVM, Wowza ͷࢹ։࢝ 2. Task ਖ਼ৗఀࢭ → ࢹఀࢭ 3. Task ҟৗఀࢭ → ࢹఀࢭͤͣΞϥʔτൃ๒ ▸ ࢹγεςϜطଘ Zabbix ͍ճ͠ ▸ ্ͷ 1, 2 Ͱ Zabbix API Λίʔϧ ▸ ͋ΓͷͳͷͰ্͕҆Γ
Case1: Monitoring Tasks e.g. ecs:StopTask ࣮ߦ { "version": "0", "id":
"41f02974-8365-f955-8465-264ef8b189ca", "detail-type": "ECS Task State Change", "source": "aws.ecs", "account": "123456789012", "time": "2017-09-07T08:10:36Z", "region": "ap-northeast-1", "resources": [ “arn:aws:ecs:ap-northeast-1:123456789012:task/55a0cfde-a377-4b97-…” ], "detail": { "clusterArn": "arn:aws:ecs:ap-northeast-1:123456789012:cluster/uorat-ecs-event-test", "containerInstanceArn": "arn:aws:ecs:ap-northeast-1:123456789012:container-instance/a04...", ... "desiredStatus": "STOPPED", ... "lastStatus": “RUNNING”, ... "stoppedReason": "Task stopped by user", ... } } ECS Task Event ECS Cluster Container Instance Task (Container) Container Instance Task (Container) ecs:StopTask
Case1: Monitoring Tasks e.g. ecs:StopTask ࣮ߦ def handle(event, context): ...
if desire_status == "RUNNING" and last_status == "PENDING": logger.info("Enable monitoring by Zabbix: host=%s" % (tag_name)) zabbix_register(tag_name, private_ip) elif desire_status == "STOPPED": logger.info("Found the stopped task: task_arn=%s, last_status=%s" % ( task_arn, last_status )) stopped_reason = event["detail"]["stoppedReason"] if stopped_reason == "Task stopped by user" and last_status == "RUNNING": logger.info("Disable monitoring by Zabbix: host=%s" % (tag_name)) zabbix_disable(tag_name) elif stopped_reason != "Task stopped by user": logger.warn("Found the failed task: host=%s, task_arn=%s, stopped_reason=%s" % ( tag_name, task_arn, stopped_reason )) respawn(task_arn, ec2_instance_id) logger.warn("Respawned and locked the task: host=%s, task_id=%s" % ( tag_name, task_arn )) ECS Cluster Container Instance Task (Container) Container Instance Task (Container) ecs:StopTask Lambda function: main.py
Case2: Respawn failed tasks ҟৗऴྃͨ͠ Task Λୟ͖ى͜͢ ▸ ࣋ଓଓͷͨΊ৴தͷ Task
ཁٹग़ ▸ “StoppedReason” ͕ظ֎ͷ߹ TaskΛ Re-run ▸ ServiceTask Ͱͳ͘ RunTask Ώ͑ʹඞཁ ▸ ͦͷޙͷରԠʹඞཁͳॲཧΛ࣮ߦ ▸ ҟৗऴྃΞϥʔτཁൃ๒ɺࢹࣗಈແޮ͠ͳ͍ ▸ Өڹͷग़ͨ৴ใΛ෦͚ʹ௨ ▸ ௐࠪ/߃ٱରԠͷͨΊ Task / Instance ΛϩοΫ
Case2: Respawn failed tasks e.g. Task ҟৗऴྃ ECS Cluster Container
Instance Container Instance Task (Container) { "version": "0", "id": "faeb52d8-e2ef-a726-655a-80f2373046b9", "detail-type": "ECS Task State Change", "source": "aws.ecs", "account": "123456789012", "time": "2017-09-07T08:40:33Z", "region": "ap-northeast-1", "resources": [ "arn:aws:ecs:ap-northeast-1:123456789012:task/d56d76f1-eb2a-42e5-..." ], "detail": { "clusterArn": "arn:aws:ecs:ap-northeast-1:123456789012:cluster/uorat-ecs-event-test", "containerInstanceArn": "arn:aws:ecs:ap-northeast-1:123456789012:container-instance/a04...", ... "desiredStatus": "STOPPED", … "lastStatus": "STOPPED", ... "stoppedReason": "Essential container in task exited", ... } } ECS Task Event
Case2: Respawn failed tasks e.g. Task ҟৗऴྃ def handle(event, context):
... if desire_status == "RUNNING" and last_status == "PENDING": logger.info("Enable monitoring by Zabbix: host=%s" % (tag_name)) zabbix_register(tag_name, private_ip) elif desire_status == "STOPPED": logger.info("Found the stopped task: task_arn=%s, last_status=%s" % ( task_arn, last_status )) stopped_reason = event["detail"]["stoppedReason"] if stopped_reason == "Task stopped by user" and last_status == "RUNNING": logger.info("Disable monitoring by Zabbix: host=%s" % (tag_name)) zabbix_disable(tag_name) elif stopped_reason != "Task stopped by user": logger.warn("Found the failed task: host=%s, task_arn=%s, stopped_reason=%s" % ( tag_name, task_arn, stopped_reason )) respawn(task_arn, ec2_instance_id) logger.warn("Respawned and locked the task: host=%s, task_id=%s" % ( tag_name, task_arn )) Lambda function: main.py ECS Cluster Container Instance Container Instance Task (Container) ecs:StartTask
StoppedReason ͷछྨ Documented ▸ ఀࢭ͞ΕͨλεΫͰͷΤϥʔͷ֬ೝ ▸ docs.aws.amazon.com/ja_jp/AmazonECS/latest/ developerguide/stopped-task-errors.html
Summary
Summary ͜Μͳوํʹ ͓͢͢Ί ECS Events & Lambda ▸ ECS ඪ४ͷ
Task Placement ͩͱগ͠ Γͳ͍ ▸ k8s Blox ڇ͔ ▸ ҟৗऴྃͨ͠ Task Λٹग़͍ͨ͠ ▸ ΠϕϯτۦಈͰ͜·ΊʹϦιʔε੍ޚ͠ ͍ͨ
Summary How about Fargate ? ▸ ແࣄ Task Events ྲྀΕ·ͨ͠
AWS Fargate
None
RAGE Shadowverse World Grand Prix