serverless-framework-workshop

 serverless-framework-workshop

53c9bf20050e5457f054eac61c388a15?s=128

堀家隆宏

March 05, 2017
Tweet

Transcript

  1. 11.

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

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

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

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

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

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

    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
  6. 50.

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

    successfully!'; } } module.exports = Hello; IFMMPDMBTTKT
  7. 51.

    -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
  8. 52.

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

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

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

    IUUQTHJUIVCDPNIPSJLFTFSWFSMFTTBQJJOUFHSBUJPOUFTUTBNQMFCMPCNBTUFS JOUFHSBUJPOUFTUUFTUKT--
  10. 59.

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

    ςετ Ϣχοτ ςετ ΠϯςάϨʔ γϣϯςετ ΠϯςάϨʔ γϣϯςετ
  11. 60.

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

    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
  13. 62.