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
690
auth0-meetup.pdf
horike37
1
250
What’s happening with Serverless Framework, and it lives with AWS SAM.
horike37
0
77
What is Serverless. Why is Serverless.
horike37
1
59
aws-with-functional-saas
horike37
2
160
serverless-with-oss
horike37
0
100
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
飲食業界向けマルチプロダクトを実現させる開発体制とリアルな現状
hiroya0601
1
390
gopls を改造したら開発生産性が高まった
satorunooshie
8
240
CPython 인터프리터 구조 파헤치기 - PyCon Korea 24
kennethanceyer
0
240
cXML という電子商取引の トランザクションを支える プロトコルと向きあっている話
phigasui
3
2.2k
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
210
Vitest Browser Mode への期待 / Vitest Browser Mode
odanado
PRO
2
1.7k
Android 15 でアクションバー表示時にステータスバーが白くなってしまう問題
tonionagauzzi
0
140
Amazon Neptuneで始めてみるグラフDB-OpenSearchによるグラフの全文検索-
satoshi256kbyte
4
310
外部システム連携先が10を超えるシステムでのアーキテクチャ設計・実装事例
kiwasaki
1
220
破壊せよ!データ破壊駆動で考えるドメインモデリング / data-destroy-driven
minodriven
16
4k
Jakarta Concurrencyによる並行処理プログラミングの始め方 (JJUG CCC 2024 Fall)
tnagao7
1
230
offers_20241022_imakiire.pdf
imakurusu
2
360
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Fontdeck: Realign not Redesign
paulrobertlloyd
81
5.2k
The Cult of Friendly URLs
andyhume
78
6k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Testing 201, or: Great Expectations
jmmastey
38
7k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
A Philosophy of Restraint
colly
203
16k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Code Review Best Practice
trishagee
64
17k
Agile that works and the tools we love
rasmusluckow
327
21k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
41
2.1k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.1k
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! ࠓͦ͜͡ΊΑ͏ʂ ࣮ફʂαʔόϨεΞʔΩςΫνϟ