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
80
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
290
Other Decks in Programming
See All in Programming
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
600
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
320
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
200
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
2
1.1k
距離関数を極める! / SESSIONS 2024
gam0022
0
280
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.4k
subpath importsで始めるモック生活
10tera
0
300
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
Featured
See All Featured
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
410
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
Teambox: Starting and Learning
jrom
133
8.8k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
YesSQL, Process and Tooling at Scale
rocio
169
14k
A better future with KSS
kneath
238
17k
Navigating Team Friction
lara
183
14k
It's Worth the Effort
3n
183
27k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
For a Future-Friendly Web
brad_frost
175
9.4k
Become a Pro
speakerdeck
PRO
25
5k
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! ࠓͦ͜͡ΊΑ͏ʂ ࣮ફʂαʔόϨεΞʔΩςΫνϟ