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 Frameworkの基礎と開発手法
Search
堀家隆宏
June 11, 2017
Programming
1
420
Serverless Frameworkの基礎と開発手法
堀家隆宏
June 11, 2017
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
Vue SFCのtemplateでTypeScriptの型を活用しよう
tsukkee
3
1.5k
Vue3の一歩踏み込んだパフォーマンスチューニング2024
hal_spidernight
3
3.1k
PagerDuty を軸にした On-Call 構築と運用課題の解決 / PagerDuty Japan Community Meetup 4
horimislime
1
110
外部システム連携先が10を超えるシステムでのアーキテクチャ設計・実装事例
kiwasaki
1
220
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
1
290
飲食業界向けマルチプロダクトを実現させる開発体制とリアルな現状
hiroya0601
1
390
Why Spring Matters to Jakarta EE - and Vice Versa
ivargrimstad
0
950
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
150
讓數據說話:用 Python、Prometheus 和 Grafana 講故事
eddie
0
350
Universal Linksの実装方法と陥りがちな罠
kaitokudou
1
220
Nuxtベースの「WXT」でChrome拡張を作成する | Vue Fes 2024 ランチセッション
moshi1121
1
490
僕がつくった48個のWebサービス達
yusukebe
18
17k
Featured
See All Featured
Docker and Python
trallard
40
3.1k
KATA
mclloyd
29
13k
Adopting Sorbet at Scale
ufuk
73
9k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Faster Mobile Websites
deanohume
304
30k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Side Projects
sachag
452
42k
Optimizing for Happiness
mojombo
376
69k
Teambox: Starting and Learning
jrom
132
8.7k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
328
21k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Transcript
4FSWFSMFTT'SBNFXPSLͷ جૅͱ։ൃख๏
ࣗݾհ
ࣗݾհ %JHJUBM$VCF$P-UEͷΤϯδχΞ 4FSWFSMFTT'SBNFXPSL$PSF$POUSJCVUPS ओཁݴޠ /PEFKT 1)1
4FSWFSMFTT4UFQ'VODUJPOT IUUQTHJUIVCDPNIPSJLFTFSWFSMFTTTUFQGVODUJPOT
4IJGUFS IUUQTHFUTIJGUFSJP
2JJUB IUUQRJJUBDPNIPSJLF
αʔόϨεΞʔΩςΫνϟͱ
αʔόϨεΞʔΩςΫνϟͱ 'BB4 -BNCEB (PPHMF$MPVE'VODUJPOT "[VSF'VODUJPOTFUD ͱ ϚωʔδυαʔϏεΛͬͯߏ͞ΕͨγεςϜ Ϣʔεέʔεɿ
XFC ϞόΠϧ *P5ͳͲͷ"1*ͷόοΫΤϯυ σʔλϓϩηογϯά Πϕϯτۦಈܕ ϓϩηε͕ৗற͠ͳ͍ αʔό͕ແ͍ͱ͍͏͜ͱͰͳ͍ɻ αʔόͷཧΛΫϥυϕϯμʔʹΞτιʔε
ͳʹ͕͏Ε͍͠ͷ͔ʁ
ΠϕϯτυϦϒϯͰ͋Δ͜ͱ
ίετ
ϓϩηεଘࡏ͠ͳ͍
εςʔτϨε
εέʔϥϏϦςΟ
None
Ͳ͏Δͷ͔ʁ
None
4FSWFSMFTT'SBNFXPSLͷ֓ཁ
4FSWFSMFTT'SBNFXPSLͱ αʔόʔϨεΞʔΩςΫνϟʹ͓͚Δ։ൃσϓϩΠΛ αϙʔτͯ͘͠ΕΔίϚϯυϥΠϯπʔϧ ZBNMʹΑΔΞʔΩςΫνϟͷߏཧ ϚϧνΫϥυϓϩόΠμʔαϙʔτ 044ͱͯ͠(JU)VC্Ͱ։ൃ
ϓϥάΠϯʹΑΔ֦ு
࣮͞Ε͍ͯΔओͳίϚϯυ TMTDSFBUF ϓϩδΣΫτͷ࡞ TMTEFQMPZ ϩʔΧϧڥ͔ΒΫϥυͷσϓϩΠ TMTJOWPLF ϑΝϯΫγϣϯͷ࣮ߦ TMTJOGP σϓϩΠ͞ΕͨߏͷใΛදࣔ TMTMPHT
ϑΝϯΫγϣϯͷ࣮ߦϩάͷ֬ೝ TMTSFNPWF σϓϩΠ͞Εͨߏͷআ
ϓϩδΣΫτͷϑΝΠϧߏཧ /PEFKT ᵓᴷTFSWFSMFTTZNM ᵋᴷIBOEMFSKT ΞʔΩςΫνϟશମͷߏΛ ఆٛ͢ΔϑΝΠϧ ϑΝϯΫγϣϯͰ࣮ߦ͞ΕΔ ϓϩάϥϜ
:".-ϑΝΠϧʹΑΔߏཧ QSPWJEFS OBNFBXT SVOUJNFOPEFKT JBN3PMF4UBUFNFOUT &⒎FDU"MMPX "DUJPO EZOBNPEC GVODUJPOT
DSFBUF IBOEMFSUPEPTDSFBUFDSFBUF FWFOUT IUUQ QBUIUPEPT NFUIPEQPTU DPSTUSVF ϑΝϯΫγϣϯʹΞλον͢Δ ݖݶͷઃఆ ༻͢ΔΫϥυϓϩόΠμʔٴͼ ϥϯλΠϜڥͷࢦఆ ϑΝϯΫγϣϯͷ࣮ߦϑΝΠϧͷ ࢦఆ ϑΝϯΫγϣϯΛ࣮ߦͤ͞Δ Πϕϯτͷࢦఆ
ϚϧνΫϥυϓϩόΠμʔαϙʔτ QSPWJEFS OBNFBXT QSPWJEFS OBNFPQFOXIJTL QSPWJEFS OBNFB[VSF QSPWJEFS OBNFHPPHMF
044ͱͯ͠(JU)VC্Ͱ։ൃ
ϓϥάΠϯʹΑΔػೳ֦ு QMVHJOT TFSWFSMFTTTUFQGVODUJPOT TFSWFSMFTTP⒐JOF IUUQTHJUIVCDPNTFSWFSMFTTQMVHJOT
Πϯετʔϧ͔Βॳظઃఆ·Ͱ
Πϯετʔϧ OQNJOTUBMMHTFSWFSMFTT
$SFEFOUJBMͷઃఆ TMTDPOpHDSFEFOUJBMTQSPWJEFS BXTLFZZPVSLFZTFDSFUZPVSTFDSFU
$SFEFOUJBMͷઃఆ "84ͷ߹ɺ"ENJOJTUSBUPS"DDFTTͷϙϦγʔΛ BUUBDI͢Δ͜ͱ͕ެࣜυΩϡϝϯτʹهࡌ͞Ε͍ͯΔ IUUQTTFSWFSMFTTDPNGSBNFXPSLEPDTQSPWJEFSTBXTHVJEFDSFEFOUJBMT
$SFEFOUJBMͷઃఆ &⒎FDU"MMPX "DUJPO< JBN(FU3PMF JBN$SFBUF3PMF JBN%FMFUF3PMF
JBN1VU3PMF1PMJDZ JBN%FMFUF3PMF1PMJDZ JBN1BTT3PMF MPHT T MBNCEB DMPVEGPSNBUJPO BQJHBUFXBZ > 3FTPVSDF< > ΦϑΟγϟϧʹެ։͞Εͯͳ͍͕ɺ࠷ ݶ͜ͷ͋ͨΓͷϦιʔεʹ ڐՄ͕͋Εಈ࡞͢Δ
$SFEFOUJBMͷઃఆ IUUQTHJUIVCDPNTFSWFSMFTTTFSWFSMFTTJTTVFT "ENJO$SFEFOUJBMΛΘͳ͍ηοτΞοϓํ๏ݱࡏٞத
։ൃϑϩʔ
αʔϏεͷ࡞ TFSWFSMFTTZNM ͷΞʔΩςΫνϟ ఆٛ σϓϩΠ Ϋϥυ্Ͱ ͷςετ ։ൃͷϫʔΫϑϩʔ ϩʔΧϧͰͷ
GVODUJPO։ൃ
αʔϏεͷ࡞ TMTDSFBUFUFNQMBUFBXTOPEFKT ֤ϓϩόΠμʔͷϥϯλΠϜڥʹ߹Θͤͨ ελʔλʔςϯϓϨʔτΛࣗಈͰ࡞ͯ͘͠ΕΔ
ରԠ͍ͯ͠ΔϥϯλΠϜڥ "84 BXTOPEFKT BXTQZUIPO BXTKBWBHSBEMF BXTKBWBNBWFO BXTTDBMBTCU BXTDTIBSQ
"[VSF OPEFKT 0QFO8IJTL PQFOXIJTLOPEFKT
TFSWFSMFTTZNMͷΞʔΩςΫνϟఆٛ αʔϏεͷϓϩόΠμʔϥϯλΠϜڥͷఆٛ ϑΝϯΫγϣϯͱͦΕΛൃՐ͢ΔͨΊͷΠϕϯτΛఆٛ ༻͢ΔΫϥυϦιʔεͷఆٛ TFSWFSMFTTZNM͕αʔϏεશମͷઃܭਤͱͳΔ
TFSWFSMFTTZNMͷΠϕϯτఆٛ GVODUJPOT VTFS$SFBUF IBOEMFSMJCVTFS$SFBUFIBOEMFS FWFOUT IUUQ QBUIVTFST NFUIPEQPTU IUUQΠϕϯτͷఆٛ
TFSWFSMFTTZNMͷΠϕϯτఆٛ GVODUJPOT SFTJ[F IBOEMFSSFTJ[FIBOEMFS FWFOUT T CVDLFUQIPUPT FWFOUT0CKFDU$SFBUFE SVMFT
QSFpYVQMPBET TV⒏YKQH 4Πϕϯτͷఆٛ
TFSWFSMFTTZNMͷΠϕϯτఆٛ GVODUJPOT NZ4LJMM IBOEMFSNZ4LJMMIBOEMFS FWFOUT BMFYB4LJMM "MFYB4LJMMΠϕϯτͷఆٛ
ରԠ͍ͯ͠ΔΠϕϯτ "84 "1*(BUFXBZ ,JOFTJT%ZOBNP%# 4 4DIFEVMF 4/4 "MFYB4LJMM *P5
$MPVE8BUDI&WFOU "[VSF )551 5JNFS 2VFVF4UPSBHF 4FSWJDF#VT &WFOU)VCT #MPC4UPSBHF 0UIFS#JOEJOHT 0QFO8IJTL "1*(BUFXBZ 5SJHHFST 4DIFEVMF
ϩʔΧϧͰͷ։ൃ TMTJOWPLFMPDBMGVODUJPOϑΝϯΫγϣϯ໊ ϩʔΧϧڥͰ-BNCEBͷϑΝϯΫγϣϯΛ ٖࣅతʹ࣮ߦͯ͘͠ΕΔίϚϯυ
ϩʔΧϧ࣮ߦͷରԠঢ়گ "84 BXTOPEFKT BXTQZUIPO 0QFO8IJTL PQFOXIJTLOPEFKT
ϩʔΧϧ։ൃΛαϙʔτ͢ΔϓϥάΠϯπʔϧ 4FSWFSMFTT TJNVMBUJPO QMVHJO "1*(BUFXBZͱ-BNCEBΛ ϩʔΧϧͰγϡϛϨʔτ IUUQTHJUIVCDPN HFSUKWSTFSWFSMFTT QMVHJOTJNVMBUF 4FSWFSMFTT
%ZOBNPEC -PDBM %ZOBNP%#ΛϩʔΧϧͰγ ϡϛϨʔτ IUUQTHJUIVCDPN YUTFSWFSMFTT EZOBNPECMPDBM 4FSWFSMFTT 0⒐JOF "1*(BUFXBZΛϩʔΧϧͰ γϡϛϨʔτ IUUQTHJUIVCDPN EIFSBVMUTFSWFSMFTT P⒐JOF ,JOFTBMJUF ,JOFTJTΛϩʔΧͰγϡϛϨ ʔτ IUUQTHJUIVCDPN NIBSULJOFTBMJUF
ΫϥυڥͷσϓϩΠ TMTEFQMPZTUBHFεςʔδ໊WFSCPTF TFSWFSMFTTZNMͰఆٛͨ͠ΞʔΩςΫνϟ ٴͼϑΝϯΫγϣϯͷιʔεΛσϓϩΠ͢Δ
εςʔδͷΈ EFWεςʔδ ϩʔΧϧ Q SPEVDUJPOεςʔ δ ςετڥͱຊ൪ڥͱ͍͍͚͕࣮ͬͨݱͰ͖Δ ֤εςʔδޓ͍ʹӨڹΛٴ΅͠߹Θͳ͍ ඞཁͳ͚ͩεςʔδ࡞Մೳ
σϓϩΠͷॲཧͷྲྀΕ TMTEFQMPZίϚϯυͷൃߦ 4FSWFSMFTT͕TFSWFSMFTTZNM Λύʔε σϓϩΠύοέʔδ ΛTFSWFSMFTTԼʹग़ྗ ֤ϓϩόΠμʔͷํࣜʹैͬͯ σϓϩΠ "84ͳΒ$MPVE'PSNBUJPO
σϓϩΠࣦഊ࣌ͷσόοά TMTEFQMPZQBDLBHF TFSWFSMFTTԼʹσϓϩΠύοέʔδͷΈग़ྗ ͜ΕΛݩʹௐࠪՄೳ
σϓϩΠޙͷ࣮ߦ TMTJOWPLFGVODUJPOϑΝϯΫγϣϯ໊MPHT ΫϥυʹσϓϩΠࡁΈͷϑΝϯΫγϣϯͷ࣮ߦ
ϩάͷ֬ೝ TMTMPHTGVODUJPOϑΝϯΫγϣϯ໊ ϑΝϯΫγϣϯͷ࣮ߦϩάͷ֬ೝ
σϓϩΠޙमਖ਼ TMTEFQMPZGVODUJPOGVODUJPOϑΝϯΫγϣϯ໊ ϑΝϯΫγϣϯ୯ମͷσϓϩΠ͕Մೳ
σϓϩΠޙͷϩʔϧόοΫ TMTEFQMPZMJTU TMTSPMMCBDLUJNFTUBNQUJNFTUBNQ TMTEFQMPZΛલճ࣮ࢪͨ͠ঢ়ଶ·ͰϩʔϧόοΫ ͯ͘͠ΕΔ
$*$%ύΠϓϥΠϯࣗಈԽ
ͳͥɺ$*$% σϓϩΠͷଐਓԽɺϛεΛແ͘͢ 13ۦಈͷ։ൃʹ͓͚Δ࣭ͷ୲อ ςετͷࣗಈԽʹΑΔޮԽ
$*$%ύΠϓϥΠϯߏ
ܧଓతΠϯςάϨʔγϣϯ $*
$*ύΠϓϥΠϯߏ -JOUʹΑΔιʔείʔυͷ੩తղੳ Ϣχοτςετ ΠϯςάϨʔγϣϯςετ
-JOUʹΑΔιʔείʔυͷ੩తղੳ ίʔυ࣮ߦલʹγϯλοΫεΤϥʔΛݕͰ͖Δ ίʔυͷελΠϧ͕౷Ұ͞ΕΔͨΊɺ ෳਓͰͷϝϯςφϯεੑ্͕͢Δ
Ϣχοτςετ ϓϩάϥϜΛߏ͢Δݸʑͷػೳ͕ਖ਼͘͠ಈ͘͜ͱΛݕূ͢Δςετ ςετίʔυΛಡΉͱͦͷιϑτΣΞ͕Ͳ͏ಈ͖͔͘ ͦͷ༷͕Θ͔Δ ͩΕ͕ϓϧϦΫΤετΛૹͬͯಉ͡ج४Ͱࣗಈςετ͕ߦ͑Δ ɹ࣭͕୲อ͞ΕΔ
-BNCEBͰߦ͏Ϣχοτςετ ᵓᴷIBOEMFSKT ᵋᴷMJC ᵓᴷIFMMPDMBTTKT ᵋᴷIFMMPDMBTTUFTUKT -BNCEBͰ࣮ߦ͞ΕΔ ϝΠϯͷϑΝΠϧ ϏδωεϩδοΫ Ϣχοτςετͷίʔυ
const Hello = require(‘./lib/hello.class.js'); const hello = new Hello(); module.exports.hello
= (event, context, callback) => { const response = { statusCode: 200, body: JSON.stringify({ message: hello.say(), input: event, }), }; callback(null, response); }; -BNCEBͰߦ͏Ϣχοτςετ ςετ͕Γ͍͢Α͏ʹ-BNCEBΛ࣮ߦ ͢ΔϝΠϯͷϑΝΠϧ͔ΒΫϥεͰΓग़ ͯ͋͛͠Δ IBOEMFSKT
-BNCEBͰߦ͏Ϣχοτςετ class Hello { say() { return 'Your function executed
successfully!'; } } module.exports = Hello; IFMMPDMBTTKT
-BNCEBͰߦ͏Ϣχοτςετ const expect = require('chai').expect; const Hello = require('./hello.class.js'); describe('Hello',
() => { let hello; beforeEach(() => { hello = new Hello(); }); describe('say', () => { it('should return the value', () => expect(hello.say()) .to.be.equal('Your function executed successfully!')); }); }); ΫϥεͰΓग़ͨ͠ϏδωεϩδοΫ ʹରͯ͠ςετίʔυΛఆٛ IFMMPDMBTTUFTUKT
Ϣχοτςετʹ͓͚ΔBXTTELͷѻ͍ beforeEach(() => { awsStub = sinon.stub(aws.provider, 'request') .returns(BbPromise.resolve({})); });
ςετͰΫϥυڥʹΞΫηε͠ͳ͍ ελϒԽɻBXTTELϢχοτςετͷൣғͰͳ͍ IUUQTHJTUHJUIVCDPNIPSJLFBCECGFDGDBCFG
ΠϯςάϨʔγϣϯςετ TFSWFSMFTTZNMͰఆٛͨ͠ߏٴͼϑΝϯΫγϣϯΛ ࣮ࡍͷΫϥυڥσϓϩΠͯࣗ͠ಈͰ݁߹ςετΛߦ͏
"1*(BUFXBZΠϕϯτͷςετͷϑϩʔ "1*(BUFXBZΠϕϯ τͷσϓϩΠ BXTTELͷ EFTDSJCF4UBDLTʹΑΓ"1* ΤϯυϙΠϯτΛऔಘ "1*ͷฦΓ ΛνΣοΫ "1*ʹ IUUQϦΫΤετ
IUUQTHJUIVCDPNIPSJLFTFSWFSMFTTBQJJOUFHSBUJPOUFTUTBNQMFCMPCNBTUFSJOUFHSBUJPOUFTUUFTUKT--
4Πϕϯτͷςετͷϑϩʔ 4Πϕϯτͷ σϓϩΠ σϓϩΠࡁΈͷόέοτ ͷΦϒδΣΫτૢ࡞ $MPVE8BUDI-PHT ͰΠϕϯτ͕ൃՐ͔ͨ͠ νΣοΫ IUUQTHJUIVCDPNIPSJLFTFSWFSMFTTBQJJOUFHSBUJPOUFTUTBNQMFCMPCNBTUFSJOUFHSBUJPOUFTUUFTUKT--
ܧଓతσϦόϦʔ $%
$%ύΠϓϥΠϯߏ EFWFMPQNFOUϒϥϯνQVTI࣌ͷςετͷ࣮ߦ ޭ࣌ʹςετεςʔδʹσϓϩΠ NBTUFSϒϥϯνΛ࠷৽ιʔεͷूॴͱͯ͠ɺ QVTI࣌ʹςετͷΈ࣮ߦ UBHΛͬͯQVTI͢ΔͱϦϦʔε ςετ࣮ߦͯ͠ޭ͢Εຊ൪εςʔδʹσϓϩΠ
$%ύΠϓϥΠϯߏ (JU %FQMPZNFOU CSBODINBTUFS CSBODIEFWFMPQNFOU UBHYYY EFWFMPQNFOUTUBHF QSPETUBHF
$%ύΠϓϥΠϯߏ CSBODINBTUFS CSBODIEFWFMPQNFOU UBHYYY -JOU -JOU -JOU Ϣχοτς ετ Ϣχοτς
ετ Ϣχοτς ετ ΠϯςάϨʔ γϣϯςετ ΠϯςάϨʔ γϣϯςετ
language: node_js node_js: - '4.3' env: global: - AWS_REGION=us-east-1 -
SLS_DEBUG=true - secure: lSxO7tZ0….BEVm - secure: LIh0lkl….7fM= before_install: - chmod +x ./bin/deploy.sh - npm i -g serverless install: - travis_retry npm install script: - npm run lint - npm run test - if [[ $TRAVIS_BRANCH == "master" ]] || [[ $TRAVIS_TAG ]]; then npm run integration-test; fi after_success: - ./bin/deploy.sh USBWJTZNMͷઃఆ "84ͷDSFEFOUJBMΛ҉߸Խͯ͠ઃఆ 5SBWJT͔Β"84ڥଓΛՄೳͱ͍ͯ͠Δ NBTUFSϒϥϯνͱUBHͷQVTI࣌ͷΈ ΠϯςάϨʔγϣϯςετ͕Δ ޭ͢ΕσϓϩΠεΫϦϓτ͕Δ
EFQMPZTI QVTIઌʹԠͯ͡TUBHFΛઃఆ σϓϩΠޠෆཁͳOQNύοέʔδͷআ σϓϩΠ #!/bin/bash set -e if [[ $TRAVIS_TAG
]]; then STAGE="production" elif [[ $TRAVIS_BRANCH == 'dev' ]]; then STAGE="development" fi echo "Deploying from branch $BRANCH to stage $STAGE" npm prune --production #remove devDependencies sls deploy --stage $STAGE --region $AWS_REGION
͓ΘΓ