Serverless Frameworkの基礎と開発手法

Serverless Frameworkの基礎と開発手法

53c9bf20050e5457f054eac61c388a15?s=128

堀家隆宏

June 11, 2017
Tweet

Transcript

  1. 8.

    αʔόϨεΞʔΩςΫνϟͱ͸  'BB4 -BNCEB (PPHMF$MPVE'VODUJPOT "[VSF'VODUJPOTFUD ͱ
 ϚωʔδυαʔϏεΛ࢖ͬͯߏ੒͞ΕͨγεςϜ  Ϣʔεέʔεɿ


    XFC ϞόΠϧ *P5ͳͲͷ"1*ͷόοΫΤϯυ
 σʔλϓϩηογϯά  Πϕϯτۦಈܕ ϓϩηε͕ৗற͠ͳ͍   αʔό͕ແ͍ͱ͍͏͜ͱͰ͸ͳ͍ɻ
 αʔόͷ؅ཧΛΫϥ΢υϕϯμʔʹΞ΢τιʔε
  2. 11.
  3. 15.
  4. 17.
  5. 22.

    :".-ϑΝΠϧʹΑΔߏ੒؅ཧ QSPWJEFS OBNFBXT SVOUJNFOPEFKT JBN3PMF4UBUFNFOUT &⒎FDU"MMPX "DUJPO EZOBNPEC  GVODUJPOT

    DSFBUF IBOEMFSUPEPTDSFBUFDSFBUF FWFOUT IUUQ QBUIUPEPT NFUIPEQPTU DPSTUSVF ϑΝϯΫγϣϯʹΞλον͢Δ ݖݶͷઃఆ ࢖༻͢ΔΫϥ΢υϓϩόΠμʔٴͼ ϥϯλΠϜ؀ڥͷࢦఆ ϑΝϯΫγϣϯͷ࣮ߦϑΝΠϧͷ ࢦఆ ϑΝϯΫγϣϯΛ࣮ߦͤ͞Δ Πϕϯτͷࢦఆ
  6. 30.

    $SFEFOUJBMͷઃఆ &⒎FDU"MMPX  "DUJPO< JBN(FU3PMF  JBN$SFBUF3PMF  JBN%FMFUF3PMF 

    JBN1VU3PMF1PMJDZ  JBN%FMFUF3PMF1PMJDZ  JBN1BTT3PMF  MPHT   T   MBNCEB   DMPVEGPSNBUJPO   BQJHBUFXBZ  >  3FTPVSDF<   > ΦϑΟγϟϧʹ͸ެ։͞Εͯͳ͍͕ɺ࠷௿ ݶ͜ͷ͋ͨΓͷϦιʔεʹ ڐՄ͕͋Ε͹ಈ࡞͢Δ
  7. 40.

    ରԠ͍ͯ͠ΔΠϕϯτ  "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
  8. 43.

    ϩʔΧϧ։ൃΛαϙʔτ͢ΔϓϥάΠϯ΍πʔϧ 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
  9. 60.

    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
  10. 61.

    -BNCEBͰߦ͏Ϣχοτςετ class Hello { say() { return 'Your function executed

    successfully!'; } } module.exports = Hello; IFMMPDMBTTKT
  11. 62.

    -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
  12. 63.

    Ϣχοτςετʹ͓͚ΔBXTTELͷѻ͍ beforeEach(() => { awsStub = sinon.stub(aws.provider, 'request') .returns(BbPromise.resolve({})); });

     ςετ಺ͰΫϥ΢υ؀ڥʹ͸ΞΫηε͠ͳ͍  ελϒԽɻBXTTEL͸ϢχοτςετͷൣғͰ͸ͳ͍ IUUQTHJTUHJUIVCDPNIPSJLFBCECGFDGDBCFG
  13. 65.

    "1*(BUFXBZΠϕϯτͷςετͷϑϩʔ "1*(BUFXBZΠϕϯ τͷσϓϩΠ BXTTELͷ EFTDSJCF4UBDLTʹΑΓ"1* ΤϯυϙΠϯτΛऔಘ "1*ͷฦΓ஋ ΛνΣοΫ "1*ʹ IUUQϦΫΤετ

    IUUQTHJUIVCDPNIPSJLFTFSWFSMFTTBQJJOUFHSBUJPOUFTUTBNQMFCMPCNBTUFSJOUFHSBUJPOUFTUUFTUKT--
  14. 70.

    $%ύΠϓϥΠϯߏ੒ CSBODINBTUFS CSBODIEFWFMPQNFOU UBHYYY -JOU -JOU -JOU Ϣχοτς ετ Ϣχοτς

    ετ Ϣχοτς ετ ΠϯςάϨʔ γϣϯςετ ΠϯςάϨʔ γϣϯςετ
  15. 71.

    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࣌ͷΈ
 ΠϯςάϨʔγϣϯςετ͕૸Δ ੒ޭ͢Ε͹σϓϩΠεΫϦϓτ͕૸Δ
  16. 72.

    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
  17. 73.