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
個人開発者のためのaws-serverless-express #kyotojs
Search
potato4d(Takuma HANATANI)
March 24, 2018
Programming
9
3.7k
個人開発者のためのaws-serverless-express #kyotojs
HANATANI Takuma(@potato4d) 2018.03.23
#kyotojs
potato4d(Takuma HANATANI)
March 24, 2018
Tweet
Share
More Decks by potato4d(Takuma HANATANI)
See All by potato4d(Takuma HANATANI)
どうせキレイに書けない処理は逆にAIに書いてもらうほうが良い説 / #kyotojs 22
potato4d
3
310
TSX First な Zero-Runtime SSG potato4d/dodai とその仕組み / owned static site generator #kyotojs
potato4d
1
2k
Vue.js with TSX - From Vue 2.x to Vue 3 #v_tokyo11
potato4d
9
4.7k
終わりゆく Vue 2.x 時代の状態設計のアンサー - Vue 3 の Provider への期待 / The Last Architecture of the Vue 2.x
potato4d
25
6.8k
Web Worker を使ってブラウザ上でポケモンの画像を解析したい! / Pokemon recognition from screenshots in browser using web worker
potato4d
0
1.2k
Firebase & Google Cloud によるサーバーレス帳票管理 #FJUG / Serverless Architecture in Candy
potato4d
8
3.6k
NestJS meetup Tokyo Opening Talk / What is NestJS? #nestjs_meetup
potato4d
11
3.9k
私たちはなぜ SPA で開発するのか / Why you choose SPA
potato4d
39
26k
Amplify Console 誕生以来本番運用しつづけてわかったこと #awswakaran_tokyo
potato4d
6
3.4k
Other Decks in Programming
See All in Programming
Micro Frontends Unmasked Opportunities, Challenges, Alternatives
manfredsteyer
PRO
0
110
みんなでプロポーザルを書いてみた
yuriko1211
0
280
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
120
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
340
受け取る人から提供する人になるということ
little_rubyist
0
250
ヤプリ新卒SREの オンボーディング
masaki12
0
130
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
940
Ethereum_.pdf
nekomatu
0
470
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
480
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.2k
Featured
See All Featured
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
Side Projects
sachag
452
42k
Faster Mobile Websites
deanohume
305
30k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Code Review Best Practice
trishagee
64
17k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Done Done
chrislema
181
16k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
How STYLIGHT went responsive
nonsquared
95
5.2k
Transcript
ݸਓ։ൃऀͷͨΊͷ aws-serverless-express HANATANI Takuma(@potato4d) 2018.03.23 #kyotojs
Ξ • ࣗݾհ • ݸਓ։ൃʹ͓͚ΔΠϯϑϥෛ୲ͷਏ͞ • PaaSʹΑΔղܾ • aws-serverless-expressͷྑ͞ •
ݸਓ։ൃऀʹͱͬͯͷNode.jsͷΠϯϑϥͷͭΒ͞ • aws-serverless-expressͷ͡Ί͔ͨ
ࣗݾհ
Ί͙ΈΜ - ాਅྱ / ߴڮཥґ ߚຐͷগঁɻ13ࡀˠ14ࡀ ʢWEB൛Ͱ17ࡀલޙʣɻεϐϯΦϑʮ͜ͷૉΒ͍͠ ੈքʹരԍΛʂ ʯͷओਓެɻ
ࠇʹߚ͍ɻࠇϚϯτ ʹࠇϩʔϒɺτϯΨϦࢠΛඃΓɺࠨʹ؟ଳʢผʹ ͕ѱ͍Θ͚Ͱͳ͘ɺͨͩͷϑΝογϣϯʣΛ͚͍ͭͯ ΔɻΧζϚͱΞΫΞͷग़ͨ͠ύʔςΟʔϝϯόʔืूͷ ுΓࢴΛݟͯؒʹՃΘΔɻମ֨খฑͰࡉɺ গͳ͘ͱΧζϚ(165cm)ΑΓ͍ɻෑͰͷύ IUUQTCJUMZ;#'.;P
@potato4d • ౦ژͰϑϦʔϥϯεͬͯΔ • ͍͍ͩͨϑϩϯτΤϯυ • ࠷ۙຆͲNuxtͷ։ൃͱ͔ϑϩϯτٕज़૬ஊ • Vue.js JP
/ VueFes Staff / Vue.js translator • ͜ͷؒٱʑʹNode.jsΛੜͰॻ͍ͨΒdeep copyͷͨ Ίʹobject-rest-spreadΛͬͯCIΛམͱͨ͠ਓ
ຊ
͍͖ͳΓͰ͕͢օ͞Μʂ
ݸਓ։ൃͯ͠·͔͢ʁ
WebApp։ൃͯ͠·͔͢ʁ
ݸਓ։ൃͷʮΠϯϑϥʯ ͭΒ͘ͳ͍Ͱ͔͢ʁ
ʮϝϯςφϯεʯʹ ৽͍͜͠ͱΛΔ࣌ؒΛ ୣΘΕ͍ͯ·ͤΜ͔ʁ
ຊ࣭తͰͳ͍࡞ۀͰ ϞνϕΛԼ͍͛ͯ·ͤΜ͔ʁ
ྫ͑ʮ͜Μͳ͜ͱʯ ىͬͯ͜ͳ͍Ͱ͔͢ʁ
ݸਓ։ൃͷΠϯϑϥϝϯςͷͭΒΈ • IaaSΛआΓ͍ͯΔͱηΩϡϦςΟΞοϓσʔτͳͲʹ ࣮֬ʹΘΕͯͲ͔͜ͰରԠ͢ΔϋϝʹͳΔ • Φʔτεέʔϧͷߏʹ͠ͳ͍ͱෛՙʹରॲͰ͖ͳ ͍͚ͲɺݸਓͰΦʔτεέʔϧ͓ࡒ͕ͭΒ͍ • Կނ͔Docker͕յΕͯରԠͰझຯ։ൃͷ༹͕͚࣌ؒ Δ
• ͜ͷۤ͠Έ͕WebAppͷ͚ͩ૿͍͑ͯ͘
͋Γ͕ͪ
࡞Ε࡞Δ΄Ͳ৽͍͠ͷΛ ࡞Δ͕࣌ؒݮ͍ͬͯ͘
ϝϯςͨ͘͠ͳ͍
Ͳ͏ʹ͔ͯ͠ղܾ͍ͨ͠
ࠓ͜ΕΛղܾ͠Α͏
Α͋͘Δղܾ๏
PaaSΛ͏
None
Heroku͍͕ͪ • ݴޠΛಛʹΘͣʹ͑ΔͷͰศར • جຊແྉͩ͠༗ྉͰ24hىಈʹ͔͔ͯͨͩ͠ ݄800ԁ͙Β͍ • Let’s Encrypt ͷࣗಈߋ৽Ͱ͖Δ͠Addon
͋ͬͯࢮ͵΄Ͳศར • େମ͜ΕͰΑ͘ͳΔ
͚ͲͭΒ͍࣌͋Δ
HerokuͰͭΒ͍ͱ͖ • ϨΠςϯγ͕ΩπΠ • ݸਓ։ൃͰFastlyΛ͑ΔΘ͚͕ͳ͍ΜͩΑͳ • Naked domainͷSSLʹରԠͯ͠ͳ͍ • ϧʔτυϝΠϯͰSSL͍ͨ͠ͳΒCloudFrontט·ͤΖ
• େྔʹಈ͔ͩ͢͠ͱແྉ͕2ඵͰރׇ͢Δ • εέʔϦϯάੑೳ͕ऴ͍ྃͯ͠Δ
None
GAE Standard͍͕ͪ • Google͕͖ͳݴޠͩͱLambdaతͳ࣮ߦ࣌ؒ՝ۚͰ ΞϓϦέʔγϣϯΛಈ͔ͤΔͷͰ͍҆ • cronͱ͔͍ͭͯͯҙ֎ʹߴੑೳ • ຊϦʔδϣϯ͕͋ΔͷͰͯ͘࠷ߴͬΆ͍ •
Naked domainͷSSLରԠόονϦ • σϑΥͰΦʔτεέʔϧ͢Δ • େମ͜ΕͰΑ͘ͳΔ
͜ΕͭΒ͍͕࣌͋Δ
GAE StandardͰͭΒ͍ͱ͖ • Google͕͖ͳݴޠҎ֎ߴ͍ϓϥϯ(Flexible)͔͠ ͳ͍ • ͦͷ͖ͳݴޠPython/Go/Java͋ͨΓͰͭΒ͍ • FlexibleDockerίϯςφΛಈ͔͚ͩ͢ͳͷͰී௨ʹ ֹ݄ͰGCEͷྉ͕͔͔ۚͬͯߴͯͭ͘Β͍
• FlexibleElasticBeanstalkΈ͍ͨͳΜ
NodeͰͷ։ൃऀʹਓݖ͕ͳ͍
ͦ͜Ͱ
͏Ұͭͷղܾํ๏
FaaSʹࡌͤΔ
Lambdaͱ͔CloudFunctions
FaaS • Node.jsͰॻ͚Δ(LambdaPython/Java) • LambdaΠϕϯτͷ൚༻ੑΛɺCloudFunctions Express LikeͳI/F͕ັྗͳܗͰఏڙ͞Ε͍ͯΔ • ϨΠςϯγॳճىಈ͕ඍົ͙Β͍ •
࣮ߦ࣌ؒ՝ۚͰ͍҆ • ٯʹແݶʹϦΫΤετ͕͖ͨΒۚΛ͔͚ͯΦʔτεέʔ ϧແݶʹͯ͘͠Εͯศར
͚ͲͭΒ͋͞Δ
FaaSͷͭΒ͞ • ݁ہҰఆҎ্ಠࣗه๏ʹམͪண͘ • طଘͷNode.jsΞϓϦέʔγϣϯͷ࡞ΓํͰ࡞Δ͜ͱ ͕Ͱ͖ΔΘ͚Ͱͳ͍ • ٕज़తʹ൚༻ੑ͕ͳ͍ʢϩοΫΠϯʣ • ϩʔΧϧ࣮ߦ͕ͱʹ͔͘ΊΜͲ͍͘͞
• API Gateway͔Βͬͯ͘Δ event ͷߏ͕…… • Αͯ͘։ൃ్த͕ͭΒ͍
ͭΒ͍
FaaSͷಛΛ࣋ͬͨ GAE/SE for Node.js͕͋Ε……
ͦΜͳ࣌ͷٹੈओ
aws-serverless-express
ͱ͜ΖͰ
aws-serverless-express Λ͍ͬͯΔਓʁ
aws-serverless-express ͬͨ͜ͱ͋Δਓʁ
aws-serverless-express • Amazon͕ϊϦͰ࡞ͬͪΌͬͨ “AWS LambdaͰExpress͕ಈ͘” ϥΠϒϥϦ • طଘͷExpressΞϓϦέʔγϣϯʹMiddlewareΛՃ ͢Δ͚ͩͰԿނ͔LambdaͰಈ͘ •
αʔόʔϨεͷԸܙΛड͚ͳ͕Β׳Ε͠ΜͩExpress ه๏ͰΞϓϦέʔγϣϯΛهड़Ͱ͖Δͷ͕ັྗ
Source Code const serverlessExpress = require('aws-serverless-express/middleware') app.use(serverlessExpress.eventContext()) app.get('/', (req, res)
=> { res.json(req.apiGateway.event) })
࣮ࡍʹͬͯΔWebApp https://connpassport.com
ྑ͞
Ͳ͕͜ྑ͍ͷ͔ • ී௨ʹNode.jsͰ։ൃ͍ͯ͠ΔͷʹԿނ͔ແݶʹε έʔϧ͢Δ • ී௨ʹNode.jsͰ։ൃ͍ͯ͠ΔͷʹԿނ͔࣮ߦ࣌՝ۚ • ී௨ʹNode.jsͰ։ൃ͍ͯ͠Δͷʹͳ͔ͥϝϯςφϯ εϑϦʔ •
Naked domainͷSSLɺϦʔδϣϯʹΑΔϨΠςϯγɺ ϩοΫΠϯ……͖ͬ͞·Ͱͷશ෦ͷ՝͕ղফ
ཉ͔ͬͨ͠ͷશ෦ೖΓ
aws-serverless-express શͯΛղܾͯ͘͠ΕΔ
ͭΒ͞ͷ͓͞Β͍ • ͦͦIaaSϝϯς͕ͭΒ͍ • HerokuϨΠςϯγ͕ͭΒ͍ • GAE/SEʹͳ͍ • FaaSϩοΫΠϯ͕ͭΒ͍
ղܾͰ͖͍ͯΔ͔ • ϨΠςϯγͳ͍͔ ->ϥϯλΠϜͷॳճىಈͷ͚ͩ͞ • ϚωʔδυPaaS Likeʹ͑Δ͔ ->͑ͯ࠷ߴ • ಠࣗه๏ͳ͍͔
->શͯExpressͦͷ··
ղܾͰ͖͍ͯΔ͔ • εέʔϦϯά • ΊͪΌΊͪΌ͢Δ͠ٯʹਓ͕͍ͳ͍͓͕͔͔࣌ۚ Βͳ͍ͷͰͲͬͪͷҙຯͰ࠷ߴ • ӡ༻ίετ • جຊతʹFaaSͳͷͰօແɺূ໌ॻACM
• API GW + ACM + Route53ʹͳΔͷͰNaked OK
ૉఢʂ
͍͍ͨʂ
͡Ί͔ͨ
awslabs/aws-serverless-express ʹΞΫηε
͓ΉΖʹexampleΛΫϦοΫ
Win/Mac/LinuxରԠͷςϯϓϨ
README͕ΊͬͪΌஸೡ
طଘϓϩδΣΫτͷҠߦ
yarn add aws-serverless-express
lambda.jsΛ࡞ const awsServerlessExpress = require('aws-serverless-express') const app = require('./app') const
server = awsServerlessExpress.createServer(app) exports.handler = (event, context) => awsServerlessExpress.proxy(server, event, context)
Expressଆ(e.g. app.js)ʹه const serverlessExpress = require('aws-serverless-express/middleware') app.use(serverlessExpress.eventContext())
͜ͷ··LambdaʹσϓϩΠͰ OK
·ͱΊ
aws-serverless-express • LambdaͰExpressΛಈ͔͢ϥΠϒϥϦ • ExpressϛυϧΣΞͱͯ͠։ൃ͞Ε͓ͯΓɺ طଘϓϩδΣΫτͷಋೖՄೳ • Expressͷ͔͖৺ͰLambdaͷPros/ConsΛ Ҿ͖ܧ͙ΞϓϦέʔγϣϯΛ࡞Δ͜ͱ͕Մೳ
Α͞ • ݱঢ়ͷPaaSࣄͰຬͨͤͳ͍ཁ݅ΛຬͨͤΔ • ϨΠςϯγ • ࣮ߦ࣌ؒ՝͔ۚͭΦʔτεέʔϦϯά • Node.jsڥ͕ಈ͘ •
Naked domainͷSSLରԠ • ͷશ෦ೖΓڥ
͡ΊΔʹ • ެࣜϨϙδτϦͷexample͕ϘΠϥʔϓϨʔ τͳͷͰͦͷ··͑Δ • طଘϓϩδΣΫτͷಋೖREADMEʹ͋Δ ͱ͓ΓʹmiddlewareΛՃ͢Δ͚ͩ
͓͏
͓ΘΓʹ
None
GAE/SE for Node དྷΔΜ͚ʂ
એ
None
None
ご清聴ありがとうございま し . た .