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
430
Serverless Frameworkの基礎と開発手法
堀家隆宏
June 11, 2017
Tweet
Share
More Decks by 堀家隆宏
See All by 堀家隆宏
オープンソースコミュニティで加速するサーバーレスの未来/serverless will be
horike37
4
700
auth0-meetup.pdf
horike37
1
250
What’s happening with Serverless Framework, and it lives with AWS SAM.
horike37
0
81
What is Serverless. Why is Serverless.
horike37
1
60
aws-with-functional-saas
horike37
2
160
serverless-with-oss
horike37
0
110
slsconftokyo
horike37
0
5.3k
slsconfworkshop
horike37
3
2.5k
Test Driven Development For Lambda
horike37
2
300
Other Decks in Programming
See All in Programming
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
3
480
Spatial Rendering for Apple Vision Pro
warrenm
0
110
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
290
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
140
採用事例の少ないSvelteを選んだ理由と それを正解にするためにやっていること
oekazuma
2
1k
命名をリントする
chiroruxx
1
420
Beyond ORM
77web
7
960
PSR-15 はあなたのための ものではない? - phpcon2024
myamagishi
0
140
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
260
nekko cloudにおけるProxmox VE利用事例
irumaru
3
440
Monixと常駐プログラムの勘どころ / Scalaわいわい勉強会 #4
stoneream
0
280
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
160
Featured
See All Featured
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Unsuck your backbone
ammeep
669
57k
Statistics for Hackers
jakevdp
796
220k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.4k
Documentation Writing (for coders)
carmenintech
66
4.5k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
Building Adaptive Systems
keathley
38
2.3k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
28
900
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
247
1.3M
Rails Girls Zürich Keynote
gr2m
94
13k
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 ֤ϓϩόΠμʔͷϥϯλΠϜڥʹ߹Θͤͨ ελʔλʔςϯϓϨʔτΛࣗಈͰ࡞ͯ͘͠ΕΔ
ରԠ͍ͯ͠Δϥ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ߦͷରԠঢ়گ "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
͓ΘΓ