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.3k
今こそはじめよう! 実践!サーバレスアーキテクチャ/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
81
What is Serverless. Why is Serverless.
horike37
1
59
aws-with-functional-saas
horike37
2
160
serverless-with-oss
horike37
0
110
slsconftokyo
horike37
0
5.3k
slsconfworkshop
horike37
3
2.5k
Test Driven Development For Lambda
horike37
2
300
Other Decks in Programming
See All in Programming
14 Years of iOS: Lessons and Key Points
seyfoyun
1
770
Effective Signals in Angular 19+: Rules and Helpers @ngbe2024
manfredsteyer
PRO
0
130
ドメインイベント増えすぎ問題
h0r15h0
1
230
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
4
230
Symfony Mapper Component
soyuka
2
730
第5回日本眼科AI学会総会_AIコンテスト_3位解法
neilsaw
0
170
17年周年のWebアプリケーションにTanStack Queryを導入する / Implementing TanStack Query in a 17th Anniversary Web Application
saitolume
0
250
テスト自動化失敗から再挑戦しチームにオーナーシップを委譲した話/STAC2024 macho
ma_cho29
1
1.3k
短期間での新規プロダクト開発における「コスパの良い」Goのテスト戦略」 / kamakura.go
n3xem
2
170
わたしの星のままで一番星になる ~ 出産を機にSIerからEC事業会社に転職した話 ~
kimura_m_29
0
180
CSC305 Lecture 25
javiergs
PRO
0
130
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
110
Featured
See All Featured
Automating Front-end Workflow
addyosmani
1366
200k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Optimizing for Happiness
mojombo
376
70k
GitHub's CSS Performance
jonrohan
1030
460k
Visualization
eitanlees
146
15k
The Cult of Friendly URLs
andyhume
78
6.1k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Imperfection Machines: The Place of Print at Facebook
scottboms
266
13k
Bash Introduction
62gerente
608
210k
GraphQLとの向き合い方2022年版
quramy
44
13k
Speed Design
sergeychernyshev
25
670
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! ࠓͦ͜͡ΊΑ͏ʂ ࣮ફʂαʔόϨεΞʔΩςΫνϟ