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-sendai
Search
堀家隆宏
July 29, 2016
Programming
4
1.4k
今こそはじめよう! 実践!サーバレスアーキテクチャ/serverless-sendai
堀家隆宏
July 29, 2016
Tweet
Share
More Decks by 堀家隆宏
See All by 堀家隆宏
オープンソースコミュニティで加速するサーバーレスの未来/serverless will be
horike37
4
700
auth0-meetup.pdf
horike37
1
250
What’s happening with Serverless Framework, and it lives with AWS SAM.
horike37
0
82
What is Serverless. Why is Serverless.
horike37
1
62
aws-with-functional-saas
horike37
2
160
serverless-with-oss
horike37
0
110
slsconftokyo
horike37
0
5.3k
slsconfworkshop
horike37
3
2.6k
Test Driven Development For Lambda
horike37
2
300
Other Decks in Programming
See All in Programming
AWSのLambdaで PHPを動かす選択肢
rinchoku
2
390
Scaling your build logic
antalmonori
1
100
混沌とした例外処理とエラー監視に秩序をもたらす
morihirok
13
2.3k
サーバーゆる勉強会 DBMS の仕組み編
kj455
1
300
為你自己學 Python
eddie
0
520
20241217 競争力強化とビジネス価値創出への挑戦:モノタロウのシステムモダナイズ、開発組織の進化と今後の展望
monotaro
PRO
0
290
最近のVS Codeで気になるニュース 2025/01
74th
1
100
.NETでOBS Studio操作してみたけど…… / Operating OBS Studio by .NET
skasweb
0
120
Внедряем бюджетирование, или Как сделать хорошо?
lamodatech
0
940
DevinとCursorから学ぶAIエージェントメモリーの設計とMoatの考え方
itarutomy
0
150
責務を分離するための例外設計 - PHPカンファレンス 2024
kajitack
9
2.4k
各クラウドサービスにおける.NETの対応と見解
ymd65536
0
250
Featured
See All Featured
Unsuck your backbone
ammeep
669
57k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
230
52k
Optimizing for Happiness
mojombo
376
70k
How GitHub (no longer) Works
holman
312
140k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Fireside Chat
paigeccino
34
3.1k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
500
No one is an island. Learnings from fostering a developers community.
thoeni
19
3.1k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
30
2.1k
Thoughts on Productivity
jonyablonski
68
4.4k
Transcript
ࠓͦ͜͡ΊΑ͏ʂ ࣮ફʂαʔόϨεΞʔΩςΫνϟ @Amimoto_Ami amimoto-ami.com
ࣗݾհ • ໊લɿງՈོ • ॴଐɿAMIMOTO TEAM • Githubɿhttps://github.com/horike37 • Qiitaɿhttp://qiita.com/horike37
• ಘҙͳ͜ͱɿAWS, JavaScript, WordPress
࠷ۙ։ൃͨ͠ αʔόϨεͳ OSSϓϩμΫτ
https://github.com/horike37/simple-api-gateway Simple API Gateway • API GatewayͷઃఆΛ؆୯ʹ͢Δͱ͍ ͏ίϯηϓτ • ରίϚϯυʹΑΔઃఆͷखҾ
• ϚοϐϯάςϯϓϨʔτCORSͷઃ ఆΛҙࣝ͠ͳͯ͘ྑ͍
https://github.com/horike37/serverless-command-line-event-args • Serverless FrameworkͷϓϥάΠϯ • Serverless FrameworkʹΑΔ։ൃͷޮ Խ͕Մೳʹ • Lambdaʹ͢ҾΛίϚϯυϥΠϯ
Ͱ͢͜ͱ͕͖ͰΔ Serverless CommandLine Event Args
ຊ
αʔόϨε ΞʔΩςΫνϟ ͱ
• ΫϥυͰఏڙ͞ΕΔαʔϏεར༻Λલఏʹߏங͢ΔαʔϏεٴͼΞϓϦέʔγϣϯ • ԾϚγϯΛΘͣʹΞʔΩςΫνϟΛߏ EC2
Կ͕خ͍͠ͷ͔
ຊདྷΓ͔ͨͬͨίʔυΛॻ͘͜ͱʹ ूதग़དྷΔڥΛ࡞Δ
• webαʔϏεΛ։ൃӡ༻ͯ͠ϏδωεΛޭͤ͞Δ͜ͱ • ͦͷͨΊʹΞϓϦέʔγϣϯͷίʔυΛॻ͘͜ͱ ຊདྷΓ͔ͨͬͨ͜ͱ ͔͠͠ݱ࣮ʹίʔυΛॻ͚ͩ͘Ͱແ͍
• OSωοτϫʔΫͷઃఆɾཧ • αʔόͷߏஙɾϥϯλΠϜڥͷηοτΞοϓ • ϛυϧΣΞΞϓϦέʔγϣϯͷηΩϡϦςΟΞοϓσʔτ • Πϯϑϥͷϝϯςφϯε • ΞΫηεϢʔβͷ৳ͼʹର͢ΔαʔόߏͷมߋɾΩϟύγςΟ
ཧ • ݸਓใͷཧ αʔό͕ଘࡏ͢Δ߹ʹൃੜ͢ΔλεΫ
αʔό͕ଘࡏ͢ΔwebαʔϏεͷ্ཱͪ͛ॳ ίʔυͷ࣮ αʔόϝϯςφϯε αʔόͷߏங ΩϟύγςΟϓϥϯχϯά අͤΔ࣌ؒͷׂ߹ • ଟ͘ͷ࣌ؒΛίʔυͷ࣮ʹඅͤΔ
αʔό͕ଘࡏ͢ΔwebαʔϏε͕͢Δͱ αʔόͷࢹ αʔόϝϯςφϯε ίʔυͷ࣮ ΩϟύγςΟ ϓϥϯχϯά අͤΔ࣌ؒͷׂ߹ • ૿͑ߦ͘ΞΫηεϢʔβʹର͢Δ αʔόͷߏมߋɾΩϟύγςΟϓϥ
ϯχϯά • ϞϊϦγοΫͳγεςϜʹର͢Δϝϯ ςφϯείετ • γϏΞͳݸਓใͷཧ • αʔόͷࢹͦΕʹର͢Δ24/365ͷ ରԠͷඞཁੑ ηΩϡϦςΟΞλοΫ ͷରԠ
͍ͭͷؒʹ͔ଟ͘ͷ࣌ؒΛՃՁͷੜ·ͳ͍ ॏ࿑ಇʹඅ͍ͯ͠Δ
Ͳ͏ղܾ͢Δͷ͔
αʔό͕ଘࡏ͢ΔwebαʔϏεͷظ αʔόͷࢹ αʔόϝϯςφϯε ίʔυͷ࣮ ΩϟύγςΟ ϓϥϯχϯά අͤΔ࣌ؒͷׂ߹ • ૿͑ߦ͘ΞΫηεϢʔβʹର͢Δ αʔόͷߏมߋɾΩϟύγςΟϓϥ
ϯχϯά • ϞϊϦγοΫͳγεςϜʹର͢Δϝϯ ςφϯείετ • γϏΞͳݸਓใͷཧ • αʔόͷࢹͦΕʹର͢Δ24/365ͷ ରԠඞཁੑ %%PT߈ܸͷରԠ ͯ͢ΛΫϥυαʔϏε Ξτιʔε
݁ՌͨΒ͞ΕΔϝϦοτ ϏδωεͷՃՁΛ͚ͭΔίʔυͷ࣮ʹ ଟ͘ͷ࣌ؒΛඅͤΔΑ͏ʹͳΔ
࣮ફฤ
ҰൠతͳϒϥβΞϓϦέʔγϣϯΛαʔόϨεΞʔΩςΫνϟͰ ࣮ͨ͠߹ͷߏΛݟ͍͖ͯ·͠ΐ͏
ϒϥβΞϓϦέʔγϣϯͷߏਤ
ϒϥβΞϓϦέʔγϣϯͷߏਤ CognitoʹΑΔ ೝূɾೝՄ
ϒϥβΞϓϦέʔγϣϯͷߏਤ ಈతॲཧAPI Gateway Λ௨ͯ͠LambdaͰॲཧ
ϒϥβΞϓϦέʔγϣϯͷߏਤ HTML,CSSͳͲ ੩తϦιʔεS3ʹઃஔ
Cognito User Pools ೝূɾೝՄ
Cognito User Pools • ಠࣗͷϢʔβσΟϨΫτϦΛ࡞Ͱ͖ΔϑϧϚωʔδυαʔ Ϗε • ԯϢʔβ·Ͱεέʔϧ • ೝূɾೝՄγεςϜΛεέʔϧͤ͞ɺηΩϡΞʹ͢Δͱ͍͏
ॏ࿑ಇΛͯͬͯ͘͢ΕΔαʔϏε
Cognito User Pools • جຊతʹ1ͭͷΞϓϦέʔγϣϯʹ͖ͭ1ͭͷUser Pool Λ࡞Δ • αΠϯΞοϓͷࡍͷύεϫʔυͷϙϦγʔೋஈ֊ೝূͳ ͲηΩϡϦςΟʹؔ͢ΔઃఆΛ֤User
Poolຖʹઃఆ͢Δ • αΠϯΞοϓࡁΈͷϢʔβͷҰཡϚωδϝϯτίϯιʔ ϧ͔Β֬ೝͰ͖Δ
Amazon Cognito Identity SDK for JavaScript https://github.com/aws/amazon-cognito-identity-js • User PoolͱwebαΠτͱͷ࿈ܞΛߦ͏ϥΠϒϥϦ
• αΠϯΠϯɺαΠϯΞοϓɺύεϫʔυϦϚΠϯμʔ ͳͲɺϢʔβཧΛߦ͏্Ͱඞཁͳϝιου͕શ ͯ༻ҙ͞Ε͍ͯΔ • JavaScriptͰϝιουΛهड़͢Δ͚ͩͰྑ͍ɻෳ ࡶͳϏδωεϩδοΫΛ࣮͢Δඞཁͳ͍
Customer Authorizer API Gateway Cognito User Pools • API
GatewayʹೝূೝՄͷΈΛUser PoolsΛ࣮ͬͯݱͰ͖Δ • ϩάΠϯࡁΈͰ͋ΕAPIͷॲཧΛಈ࡞͞ ͤͯɺະϩάΠϯঢ়ଶͰ͋ΕɺAPIͷॲ ཧΛ࣮ࢪͤ͞ͳ͍ͱ͍ͬͨ͜ͱ͕Մೳ
ຊϕʔλ͕औΕͯਖ਼ࣜϦϦʔε
DynamoDB ಈతॲཧ Lambda API Gateway
API Gateway • ΞϓϦέʔγϣϯͷݰؔͱͯ͠ৼΔ͏ APIΛ࡞͢Δ͜ͱ ͕Ͱ͖ΔϚωʔδυαʔϏε • APIόοΫΤϯυγεςϜʹLambdaΛઃఆͯ͠֎෦͔Βͷೖ ྗσʔλΛॲཧͤ͞Δ •
ͲͷΑ͏ͳεέʔϧͰ͋ͬͯɺ؆୯ʹ API ͷ࡞ɺɺ อकɺࢹɺอޢ͕ߦ͑Δ
Lambda • ΞϓϦέʔγϣϯίʔυΛ࣮ߦͰ͖ΔίϯϐϡʔταʔϏε • ϢʔβΞϓϦέʔγϣϯίʔυͷΈΛAWSʹΞοϓϩʔ υ͢Εྑ͍ɻϢʔβ͕Λෛ͏ͷίʔυͷΈ • αʔόɺOSɺΩϟύγςΟʔͷϓϩϏδϣχϯά͓Αͼࣗ ಈεέʔϦϯάɺίʔυͷϞχλϦϯά͓Αͼϩάه AWS͕ཧٴͼ࣮ࢪ͢Δ
DynamoDB • ϑϧϚωʔδυͳNo SQLσʔλϕʔεαʔϏε • SPOF͕ଘࡏ͠ͳ͍ɻߴՄ༻ੑ 3 x ϨϓϦέʔγϣϯ •
ετϨʔδ༰ྔ੍ݶͳ͠ • ਫฏεέʔϦϯάʹΑΔෛՙࢄ
• ͜ͷ3ͭͷαʔϏεΛΈ߹ΘͤΔ͜ͱͰɺΞϓϦέʔγϣ ϯʹඞཁͳσʔλͷೖग़ྗɺॲཧɺӬଓԽ͕ՄೳʹͳΔ αʔόϨεΞʔΩςΫνϟࡾछͷਆث
αʔόϨεΞʔΩςΫνϟͰͷ։ൃΛΑΓޮతʹ
։ൃπʔϧϑϨʔϜϫʔΫ Serverless Framework API GatewayٴͼLambdaɺͦͷଞAWSϦιʔεΛͬͨ ΞϓϦέʔγϣϯΛߏங͢ΔͨΊͷϑϨʔϜϫʔΫ APEX LambdaϑΝϯΫγϣϯΛϏϧυɺσϓϩΠɺཧ͢ΔͨΊ ͷπʔϧ chalice
Serverless FrameworkʹࣅͨϑϨʔϜϫʔΫ Lamvery LambdaͷσϓϩΠFunctionͦͷͷΛؚΊͨपลػೳͷ ઃఆɾཧΛࢧԉ͢Δπʔϧ Simple API Gateway API GatewayͷઃఆٴͼσϓϩΠΛ؆୯ʹ͢Δπʔϧ
੩తϦιʔε S3 Bucket
Simple Strage Service • Πϯλʔωοτ༻ͷετϨʔδαʔϏε • εέʔϥϒϧͰ৴པੑ͕ߴ͘ɺ͔ͭߴͰ҆Ձͳσʔλετ ϨʔδΠϯϑϥετϥΫνϟΛར༻Ͱ͖Δ • ϑϩϯτ༻ͷHTMLS3όέοτʹஔ͢Δ͜ͱͰແݶͷε
έʔϥϏϦςΟΛ࣮ݱ͢Δ
ϑϩϯτͷϒϥβͱAPIΛޮΑ͘ଓͯ͘͠ΕΔͷ͕ඞཁ
ϑϩϯτͷϒϥβͱAPIΛޮΑ͘ଓͯ͘͠ΕΔͷ͕ඞཁ Single Page ApplicationʹΑΔ ϒϥβΞϓϦέʔγϣϯͷ։ൃ
• ୯ҰϖʔδʹΑΔWebΞϓϦέʔγϣϯ • ϖʔδϋογϡͷมߋ DOM ͷૢ࡞ʹΑͬͯ ΓସΘΔ • αʔόͱͷ௨৴ Ajax
WebSocket ͳͲͰߦ͏ Single Page Applicationͱ
• APIͱϖʔδ͕શʹ͍ͯ͠ΔͨΊɺAPI ϑΝʔετͷߟ͑ํͰࣗવʹΞϓϦέʔγϣϯ͕ ΊΔ • ΫϥΠΞϯτͱAPIͦΕͧΕʹ։ൃϦιʔεΛ ׂͯ͠ΓͯΔ͜ͱ͕༰қ Single Page ApplicationͷϝϦοτ
ϓϦίϯύΠϧʹΑΔΫϥΠΞϯταΠυϨϯμϦϯά API Gateway͔Βͷσʔλऔಘ ίϯύΠϧͯ͠HTMLͷੜ ϒϥβͰͷඳը
·ͱΊ • ͜͜·Ͱʹհͨ͠αʔϏεπʔϧΛ͏͜ͱͰैདྷͷϒ ϥβΞϓϦέʔγϣϯΛαʔόϨεΞʔΩςΫνϟͰ։ൃɺ ӡ༻͢Δ͜ͱ͕ՄೳʹͳΔ
·ͱΊ http://qiita.com/horike37 ࠓհͨ͠ΞʔΩςΫνϟͷৄࡉQiitaͷํʹιʔείʔυؚΊͯॻ͍͍ͯ·͢ ڵຯ͋Δํੋඇͷ͍ͧͯΈ͍ͯͩ͘͞
αʔόϨεΞʔΩςΫνϟͰ࠷େࣄͳ͜ͱ ࠷ޙʹ
αʔόϨεΞʔΩςΫνϟͰ͍ͬͯ͘ؾ࣋ͪʂ
ࣗͨͪͰ։͠ɺࣄྫΛ࡞͍ͬͯ͘ؾ࣋ͪʂ
ͦΜͳ͍ؾ࣋ͪΛ͞ΒʹΓ্͛ͯ͘ΕΔΠϕϯτ͕͋Γ·͢ʂ
Serverless Conf Tokyo͕։࠵͞Ε·͢ʂ http://tokyo.serverlessconf.io/
@Amimoto_Ami amimoto-ami.com THANK YOU! ࠓͦ͜͡ΊΑ͏ʂ ࣮ફʂαʔόϨεΞʔΩςΫνϟ