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
330
TSX First な Zero-Runtime SSG potato4d/dodai とその仕組み / owned static site generator #kyotojs
potato4d
1
2.1k
Vue.js with TSX - From Vue 2.x to Vue 3 #v_tokyo11
potato4d
9
4.8k
終わりゆく 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
Effective Signals in Angular 19+: Rules and Helpers @ngbe2024
manfredsteyer
PRO
0
130
103 Early Hints
sugi_0000
1
230
Refactor your code - refactor yourself
xosofox
1
260
複雑な仕様に立ち向かうアーキテクチャ
myohei
0
170
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
190
PHPで学ぶプログラミングの教訓 / Lessons in Programming Learned through PHP
nrslib
2
220
From Translations to Multi Dimension Entities
alexanderschranz
2
130
情報漏洩させないための設計
kubotak
0
100
fs2-io を試してたらバグを見つけて直した話
chencmd
0
230
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
Stackless и stackful? Корутины и асинхронность в Go
lamodatech
0
740
DevFest Tokyo 2025 - Flutter のアプリアーキテクチャ現在地点
wasabeef
5
900
Featured
See All Featured
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
BBQ
matthewcrist
85
9.4k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Side Projects
sachag
452
42k
Being A Developer After 40
akosma
87
590k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Mobile First: as difficult as doing things right
swwweet
222
9k
Facilitating Awesome Meetings
lara
50
6.1k
How to Think Like a Performance Engineer
csswizardry
22
1.2k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
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
ご清聴ありがとうございま し . た .