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
短期間での新規プロダクト開発における「コスパの良い」Goのテスト戦略」 / kamakura.go
n3xem
2
170
PHPとAPI Platformで作る本格的なWeb APIアプリケーション(入門編) / phpcon 2024 Intro to API Platform
ttskch
0
260
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
460
Webエンジニア主体のモバイルチームの 生産性を高く保つためにやったこと
igreenwood
0
340
Amazon S3 NYJavaSIG 2024-12-12
sullis
0
100
testcontainers のススメ
sgash708
1
120
責務を分離するための例外設計 - PHPカンファレンス 2024
kajitack
6
1.3k
useSyncExternalStoreを使いまくる
ssssota
6
1.1k
Keeping it Ruby: Why Your Product Needs a Ruby SDK - RubyWorld 2024
envek
0
190
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
160
Stackless и stackful? Корутины и асинхронность в Go
lamodatech
0
810
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
290
Featured
See All Featured
Unsuck your backbone
ammeep
669
57k
Automating Front-end Workflow
addyosmani
1366
200k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Side Projects
sachag
452
42k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
Mobile First: as difficult as doing things right
swwweet
222
9k
Git: the NoSQL Database
bkeepers
PRO
427
64k
The Cost Of JavaScript in 2023
addyosmani
45
7k
Bash Introduction
62gerente
608
210k
Making the Leap to Tech Lead
cromwellryan
133
9k
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
ご清聴ありがとうございま し . た .