Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
紙面ビューアーを支える サーバーレスアーキテクチャ / serverless architec...
Search
Taishi Ikai
October 01, 2016
Technology
43
40k
紙面ビューアーを支える サーバーレスアーキテクチャ / serverless architecture supports Nikkei's paper viewer
Taishi Ikai
October 01, 2016
Tweet
Share
More Decks by Taishi Ikai
See All by Taishi Ikai
日経電子版でApp内課金を導入した話 / Nikkei uses In-App Purchase
ikait
2
2.7k
安定的 60 fps をめざす / the way to 60 fps
ikait
19
5.5k
SwiftとCoreTextと文字組み
ikait
1
590
Typography and Fonts と日本語フォントまわり
ikait
2
3k
Other Decks in Technology
See All in Technology
社外コミュニティで学び社内に活かす共に学ぶプロジェクトの実践/backlogworld2024
nishiuma
0
250
成果を出しながら成長する、アウトプット駆動のキャッチアップ術 / Output-driven catch-up techniques to grow while producing results
aiandrox
0
180
Snowflake女子会#3 Snowpipeの良さを5分で語るよ
lana2548
0
220
KnowledgeBaseDocuments APIでベクトルインデックス管理を自動化する
iidaxs
1
250
LINEヤフーのフロントエンド組織・体制の紹介【24年12月】
lycorp_recruit_jp
0
530
生成AIをより賢く エンジニアのための RAG入門 - Oracle AI Jam Session #20
kutsushitaneko
4
210
Qiita埋め込み用スライド
naoki_0531
0
860
kargoの魅力について伝える
magisystem0408
0
200
ゼロから創る横断SREチーム 挑戦と進化の軌跡
rvirus0817
2
260
TSKaigi 2024 の登壇から広がったコミュニティ活動について
tsukuha
0
160
スタートアップで取り組んでいるAzureとMicrosoft 365のセキュリティ対策/How to Improve Azure and Microsoft 365 Security at Startup
yuj1osm
0
210
継続的にアウトカムを生み出し ビジネスにつなげる、 戦略と運営に対するタイミーのQUEST(探求)
zigorou
0
510
Featured
See All Featured
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
How to Think Like a Performance Engineer
csswizardry
22
1.2k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Adopting Sorbet at Scale
ufuk
73
9.1k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Typedesign – Prime Four
hannesfritz
40
2.4k
YesSQL, Process and Tooling at Scale
rocio
169
14k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
Mobile First: as difficult as doing things right
swwweet
222
9k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Transcript
ࢴ໘ϏϡʔΞʔΛࢧ͑Δ αʔόʔϨεΞʔΩςΫνϟ ழࣂ େࢤ ຊܦࡁ৽ฉࣾ Serverless Conf Tokyo 2016
2 About me ழࣂ େࢤ (Ikai Taishi) ຊܦࡁ৽ฉࣾͷΤϯδχΞ ࢴ໘ϏϡʔΞʔͷ։ൃΛ୲ Swift,
Python, JavaScript Github: @ikait
3 ༗ྉձһ 48ສਓ ແྉձһ 300ສਓ ඇొ 2500ສUB ܦిࢠ൛ͱ 2010
3 ݄ʹץ ݄ؒΞΫηε 3 ԯ݅ ຖ 900 ຊͷهࣄΛ৴ PCɾϞόΠϧαΠτɺ iOS, Android ΞϓϦͳͲʹରԠ
4 ࢴ໘ϏϡʔΞʔʁ
5 ܦిࢠ൛ ࢴ໘ϏϡʔΞʔ
6 ຊܦࡁ৽ฉΛɺ εϚϗŋλϒϨοτͰಡΉ iOSŋAndroid ରԠ 2016.3.15 ϦχϡʔΞϧ
7 ேŋ༦ץ ͕ಡΊΔ ຖேɺຖ༦৴͞Ε·͢ (ٳץআ͘) աڈ1िؒಡΊ·͢ ΦϓγϣϯͰɺܦ࢈ۀ৽ฉɺ ܦ MJ ͕ಡΊ·͢
8 ৽ฉͱಉ͡ϨΠΞτ ొͨ͠ΩʔϫʔυΛ ϋΠϥΠτͰ͖·͢ ݕࡧͰ͖·͢ μϯϩʔυ͓ͯ͘͠ͱ ΦϑϥΠϯͰಡΊ·͢
9 ࢴ໘ϏϡʔΞʔ ͍ͯ͠·͢ iOSɺAPIɺը૾ੜͳͲ Ϟμϯͳ։ൃϑϩʔʢ❗ʣ ϚωʔδυɾαʔϏεΛ ੵۃతʹར༻͍ͯ͘͠
10 https://twitter.com/naoya_ito/status/779241231029186561
11 https://github.com/serverless/serverless
12 API (ೝূܥ) Ͱɺ͜ͷ Microservice ࣮ߦڥΛར༻͍ͯ͠·͢ https://speakerdeck.com/yosukesuzuki/nikkei-microservice
ࢴ໘ϏϡʔΞʔΛࢧ͑Δ αʔόʔϨεΞʔΩςΫνϟ ழࣂ େࢤ ຊܦࡁ৽ฉࣾ Serverless Conf Tokyo 2016 ͱϚΠΫϩαʔϏεΞʔΩςΫνϟ
14 ࢴ໘ը૾͕ΞϓϦʹಧ͘·Ͱ
15 S3 ฤू લఏ هࣄ ϨΠΞτ ιʔε: ࢴ໘ը૾ ϝλσʔλ
XML ࠲ඪͳͲ
16 S3 SQS EC2 CloudFront Client ιʔεऔಘ ϑΝΠϧஔ ϦαΠζ ը૾ϑΟϧλʔ
هࣄը૾ۣܗΓऔΓ ࢴ໘ը૾ׂ ϝλσʔλऔಘ WebP ม JPEG ม ιʔε enqueue polling / dequeue ΞΫηε੍ݶ όονॲཧͩͱ͢Δͱ..
17 ओʹேץɺ༦ץͷ࣌ؒͷՔಇ͕ͩɺࢴ໘ߋ৽ෆఆظʹ͋Δ → ִؒͰ SQS ΛϙʔϦϯά͢Δ ɾ Πϯελϯεৗʹىಈ͓ͯ͘͠? ɾ εέʔϧΞτएׯ͕͔͔࣌ؒΔ
ॲཧ͕ଟ͍ɺը૾ม(ϦαΠζɺϑΟϧλɺWebPม) ॏΊ → ͍ܰॲཧϚϧνεϨουͰฒྻԽ → Πϯελϯεෳىಈ͢ΔͳͲ ՝
18 Lambda ͕ ʢ౦ژϦʔδϣϯʹʣ ͖ͨ 2015/06/29
19 S3 SQS EC2 CMS CloudFront Client ιʔεऔಘ ϑΝΠϧஔ ϦαΠζ
ը૾ϑΟϧλʔ هࣄը૾ۣܗΓऔΓ ࢴ໘ը૾ׂ ϝλσʔλऔಘ WebP ม JPEG ม ιʔε enqueue polling / dequeue
20 S3 SQS CMS CloudFront Client ιʔεऔಘ ϑΝΠϧஔ ϦαΠζ ը૾ϑΟϧλʔ
هࣄը૾ۣܗΓऔΓ ࢴ໘ը૾ׂ ϝλσʔλऔಘ WebP ม JPEG ม ιʔε enqueue polling / dequeue Lambda
21 S3 CMS CloudFront Client ιʔεऔಘ ϑΝΠϧஔ ϦαΠζ ը૾ϑΟϧλʔ هࣄը૾ۣܗΓऔΓ
ࢴ໘ը૾ׂ ϝλσʔλऔಘ WebP ม JPEG ม ιʔε Lambda S3 ͔ΒͷΠϕϯτͰ Lambda ͕࣮ߦ͞ΕΔ ͜Μͳײ͡ʁ
22 ࡞Γͨ͠
23 Lambda ؔͷ։ൃ
24 ϦαΠζ γϟʔϓɺίϯτϥετ هࣄը૾ۣܗΓऔΓ ࢴ໘ը૾ׂ WebP ม JPEG ม ϝλσʔλม
/ औಘ Lambda ্Ͱߦ͏͜ͱ v0.10.36
25 4000px 5296px
26 ϦαΠζ γϟʔϓɺίϯτϥετ هࣄը૾ۣܗΓऔΓ ࢴ໘ը૾ׂ WebP ม JPEG ม Lambda
্ͷ ImageMagick Λ Ͱར༻
27 ϦαΠζ γϟʔϓɺίϯτϥετ هࣄը૾ۣܗΓऔΓ ࢴ໘ը૾ׂ WebP ม JPEG ม Linux
Ͱ੩తϏϧυͨ͠ cwebp όΠφϦ ΛɺΞοϓϩʔυ͢Δ zip ʹؚΊΔ cwebp Λ node ͔Βѻ͏ͨΊͷ ϥούʔϥΠϒϥϦ install cwebp
28 όΠφϦͷύεΛίʔυͰڥมʹՃ JG GTFYJTUT4ZOD VTSMPDBMCJODXFCQ \ DPOTU-*#@%*3QBUIKPJO @@EJSOBNF MJC
QSPDFTTFOW1"5) A\-*#@%*3^A QSPDFTTFOW-%@-*#3"3:@1"5) A\-*#@%*3^A ^
29 ϩʔΧϧͰϢχοτςετ
30 Ϗϧυ / σϓϩΠ Lambda ςετ Babel ʢes6 → es5ʣ
ɺιʔεϚοϓ npm Πϯετʔϧ σϓϩΠ (node-aws-lambda) npm: source-map-support Increment Version
31 ಈ࡞ϑϩʔ (ུ֓)
32 Source S3 Dest S3 Order Regenerate Dispatch Scheduled
events Invoke Tasks Login, Get Signed URL Request Signed URL API
33 \ OBNFEJWJEF TPVSDFYZ[QOH ˑEFTUJOBUJPOYZ[@QOH EBUB\ SFDUBOHMF\ Y
Z X I ^ ^ ^ S3 PUT Λ͏͚ͯɺॲཧ༰Λॻ͍ͨϑΝΠϧΛஔ Dest S3 Dispatch Tasks Source S3
34 ֤ॲཧ୲ͷ Lambda ͕ S3 ͔Β ඞཁͳϑΝΠϧΛऔಘͯ͠ॲཧ Dest S3 Dispatch
Tasks S3 PUT Λ͏͚ͯɺॲཧ༰Λॻ͍ͨϑΝΠϧΛஔ Source S3
35 Dest S3 Dispatch Tasks S3 PUT Λ͏͚ͯɺॲཧ༰Λॻ͍ͨϑΝΠϧΛஔ ̍ΠϕϯτͰෳͷLambda
ΛىಈͰ͖ͳ͍ͨΊɺͻͱͭͷ Lambda ؔͰҰ୴ΠϕϯτΛड͚औΓɺ ϑΝΠϧ໊Λϕʔεʹͯ͠ɺଞͷ Lambda Λىಈ (S3ܦ༝)
36 Lambda ͔Βىಈ͢Δ߹ɺεϩοτϧ͢Δͱ ࣦഊ͢Δ͔͠Εͳ͍ͷͰ S3 Λܦ༝͢Δ Dest S3 Dispatch Scheduled
events Tasks
37 1 ͓͖ʹىಈ ϑΝΠϧͷଘࡏ֬ೝΛߦ͍ ഔମϦετΛߋ৽͢Δ ഔମϦετͷଘࡏΛͬͯɺ ഔମͷ४උྃΛࣔ͢ Dest S3
Scheduled events
38 API Ͱೝূ API ϢʔβʔΛೝՄͯ͠ɺ CloudFront ॺ໊͖URL Λൃߦ Private Cache
Distribution Dest S3 Login, Get Signed URL Request Signed URL API
39 Private Cache Distribution ύλʔϯ ① ೝূࡁΈϦΫΤετ GET https://api/sign ②
ॺ໊ ③ CF ॺ໊Λ͚ͭͯ ϦΫΤετ
40 Private Cache Distribution ύλʔϯ CloudFront Λҙࣝ͢Δ͜ͱͳ͘ɺ CloudFront ্ͷίϯςϯπͷऔಘ͕Մೳ ①
ೝূࡁΈϦΫΤετ ② 303 (ॺ໊͖URLͷϦμΠϨΫτ) ②’ ϦΫΤετ ॺ໊͖URL ॺ໊͖URLͷੜ
41 ӡ༻
42 ேץલ 18000 invocations/m
43 Lambda ༝དྷͷΤϥʔΊͬͨʹى͖ͳ͍
44 Slack ࿈ܞ Քಇঢ়گΛ௨ ΤϥʔͷᮢΛ͑ͨͱ͖Λ௨ Notify Log Log Alarm (when
exceeded threshold) Notify
45 Source S3 Order Regenerate Dispatch Invoke Slash commands
Ͱ API Gateway ͔Β Lambda ΛىಈɻΤϥʔ࣌ɺ QA ࣌ͳͲɺखಈͰഔମΛੜ Slack ࿈ܞ
46 Lambda ͔Β Lambda ΛݺΜͩޙʹ෮ؼͰ͖ͳ͍Τϥʔݫې ΤϥʔΛى͜͢ͱ࠷ 3 ճϦτϥΠ͞ΕΔͷͰ… < 429:
You are sending too ɹmany requests. Please relax. time dying lambda
47 API ଆͷ E2E ςετ͕Քಇ ෳճ࿈ଓࣦͯ͠ഊ͢Δͱ PagerDuty ͔Β API νʔϜʹి
Lambda ͕ࢮ͍ͯ͠Δ߹ɺखॱʹͦͬͯϩʔΧϧͰॲཧ
48 CloudFront ͕ࢮͨ͠ࡍυϝΠϯͷ͖ઌΛ S3
49 S3 ʹॻ͖ࠐ·ΕΔ CloudFront ͷϩάΛ Lambda Ͱύʔεͯ͠ Elasticsearch ೖɺ kibana
ͰՄࢹԽ Log S3 Parse
50 ϢʔβʔͷΛड͚औͬͯɺSlack ͱ Backlog ߘ API Gateway ܦ༝ͷ Lambda ىಈͷ
ϨΠςϯγʔؾʹͳΔ
51 ৼΓฦΓ
52 ։ൃɺ্ʁ Lambda ͷͨΊͷ։ൃඞཁͩͬͨ ΞϓϦʹԠͨ͡σʔλଆͷॊೈͳมߋ͕Մೳͩͬͨ αʔόʔෛՙΛؾʹ͠ͳ͍ͰΑ͘ͳͬͨʢը૾ੜɺ৴ʣ ։ൃମ੍ͷԸܙʢݱͰٕज़తͳҙࢥܾఆ͕͋Δ͜ͱʣ ӡ༻ίετݮͬͨʢ΄΅ͳ͍ʣ
53 αʔϏεɾঢ়گʹΑͬͯɺସΛҙࣝ͢Δඞཁ͋Γͦ͏ Lambda ؔɺLambda Ҏ֎ͷͲ͜Ͱಈ͔ͤͦ͏ʁ S3, CloudFront ͕མͪͨ࣌ʁ πʔϧ͕ग़ἧͬͯɺݴޠͷબࢶ૿͑ͨ Serverless,
Apex, Lamvery ͳͲ ͲͷαʔϏε҆ఆ͍ͯ͠Δ ࠓ҆৺ͯ͠৸ΒΕΔ
54 ҙ֎ʹࣗ༝͋Δ OS Amazon Linux ͳͷͰɺ͜͜Ͱಈ͘ͷେମಈ͘ Linux ༻ͷ cwebp
όΠφϦͰ WebP มͰ͖ͨ Lambda ͷͨΊͷ։ൃ͕ඞཁʹͳΔ ಛʹɺS3 ͳͲͱ࿈ܞͯ͠ΠϕϯτϕʔεͰॲཧ͢Δ߹ ΠϕϯτͷϧʔςΟϯάɺσΟεύονϟ͕ඞཁʹͳΔ߹ ϢχοτςετͰ͖Δ͕ɺࣗಈͰ݁߹ςετ͕͍͠ Lambda ʹ͍ͭͯ
55 ࡉ͔͍πʔϧΛ࡞Δʹ͔ͳΓศར Slack ͷ Slash commands ͳͲ (API Gateway ͱͷΈ߹Θͤ)
ͪΌΜͱͰ͖͍ͯΔ ΠϕϯτΛ࿙Βͨ͠Γ͠ͳ͍ ͔ͳΓ͍҆ FaaS ͷະདྷΛײ͡Δ Lambda ʹ͍ͭͯ
56 ؆୯ʹ͑Δ PaaS ج൫ͷ४උ͕͋ͬͨ Elastic Beanstalk + Docker + Python
+ Django ೝূඞਢɺ༗ྉձһݶఆͷαʔϏεͳͷͰɺݎ࿚Ͱ։ൃମ੍͕ ཱ͍֬ͯ͠Δํ͕Α͔ͬͨ API Gateway + Lambda ཧͷίετ͕͔͔Γͦ͏ɺϨΠςϯ γʔ͕େ͖͍ PaaS?
57 εςʔτϨεΛҙࣝͤ͟ΔΛಘͳ͍ ෭࡞༻ঢ়ଶอ࣋ʹཔΕͳ্͍࣮ͷ੍ ີ݁߹ͳίʔυ͕ࣗવʹݮΓɺݟ௨͕͖͘͢͠ͳΔ ϑϩϯτΤϯυͷ։ൃʹੜ͖ͨ αʔόʔϨεͰͷ։ൃΛ௨ͯ͡
58 ·ͱΊ
59 Lambda + S3 + CloudWatch Ͱࢴ໘ը૾ͷม S3 + CloudFront
Ͱը૾ͷ৴: Private cache distribution Lambda Ͱ WebP ͷมը૾ॲཧΛߦͬͨ ݁Ռͷͪ߹ΘͤΛ͢ΔͨΊʹ ɺCloudWatch Ͱ cron తʹ Lambda Λ࣮ߦ ҰͭͷΠϕϯτͰෳͷ Lambda Λىಈ͢Δ Workaround Slack, Backlog, PagerDuty ͳͲͷ SaaS ׆༻ αʔόʔϨεͰखͷ͔͔Βͳ͍ΠϯϑϥΛߴʹߏஙͰ͖ͨ
ࢴ໘ϏϡʔΞʔΛࢧ͑Δ αʔόʔϨεΞʔΩςΫνϟ ழࣂ େࢤ ຊܦࡁ৽ฉࣾ Serverless Conf Tokyo 2016