Upgrade to Pro — share decks privately, control downloads, hide ads and more …

AWS Serverless Express 入門

Nokogiri
August 03, 2018

AWS Serverless Express 入門

AWS Lambda を使って Express を 一瞬で公開する方法

Nokogiri

August 03, 2018
Tweet

More Decks by Nokogiri

Other Decks in Technology

Transcript

  1. JavaScript / Java / React / AWS / Vim ͸͡Ί·ͯ͠!

    Taiki Nishi @nkgrnkgr Nokogiri Blog nkgrnkgr.github.io WebΞϓϦέʔγϣϯΤϯδχΞ ๏ਓ޲͚άϧʔϓ΢ΣΞαʔϏεͷ։ൃ HN: Nokogiri(nkgrnkgr) Ұࣇͷ෕ʢࠓ݄ೋࣇͷ෕ʹͳΓ·͢ ʣ Speaker Deck
  2. Express ʹ aws-serverless-express ΛΠϯετʔϧ STEP1 STEP2 STEP3 STEP4 ❯ npm

    install aws-serverless-express + [email protected] updated 1 package and audited 198 packages in 2.889s found 2 low severity vulnerabilities run `npm audit fix` to fix them, or `npm audit` for details
  3. const awsServerlessExpress = require('aws-serverless-express'); const app = require('./app'); const server

    = awsServerlessExpress.createServer(app); exports.handler = (event, context) => awsServerlessExpress.proxy(server, event, context); Lambda ͔Βݺͼग़͞ΕΔ handler Λ࡞੒ STEP1 STEP2 STEP3 STEP4 index.js
  4. ࠓ౓͸ Express ͷ middleware ʹ ͜ͷϥΠϒϥϦΛ௥Ճ STEP1 STEP2 STEP3 STEP4

    const serverlessExpress = require('aws-serverless-express/middleware'); var app = express(); app.use(serverlessExpress.eventContext()); app.js
  5. ࠓ౓͸ Express ͷ middleware ʹ ͜ͷϥΠϒϥϦΛ௥Ճ STEP1 STEP2 STEP3 STEP4

    const serverlessExpress = require('aws-serverless-express/middleware'); var app = express(); app.use(serverlessExpress.eventContext()); app.js ΞϓϦέʔγϣϯͱͯ͠΍Δ͜ͱ͸Ҏ্ͰऴΘΓ
  6. Lambda ΁ͷσϓϩΠ͸ Serverless Flamework Λར༻ STEP1 STEP2 STEP3 STEP4 $

    npm install serverless -g + [email protected] updated 3 packages in 11.062s https://serverless.com/framework/
  7. σϓϩΠ༻ʹ ઃఆϑΝΠϧΛ࡞੒ STEP1 STEP2 STEP3 STEP4 service: serverless-express-example provider: name:

    aws runtime: nodejs8.10 stage: dev region: ap-northeast-1 functions: app: handler: index.handler events: - http: ANY / - http: 'ANY {proxy+}' serverless.yml
  8. ❯ sls deploy Serverless: Packaging service... Serverless: Excluding development dependencies...

    Serverless: Uploading CloudFormation file to S3... Serverless: Uploading artifacts... Serverless: Uploading service .zip file to S3 (2.16 MB)... Serverless: Validating template... Serverless: Updating Stack... Serverless: Checking Stack update progress... .............. Serverless: Stack update finished... Service Information service: serverless-express-example stage: dev region: ap-northeast-1 stack: serverless-express-example-dev api keys: None endpoints: ANY - https://u8klxp40gc.execute-api.ap-northeast-1.amazonaws.com/dev ANY - https://u8klxp40gc.execute-api.ap-northeast-1.amazonaws.com/dev/{proxy+} functions: app: serverless-express-example-dev-app APIGawayͷEndPointsͷ࡞੒͔ΒίʔυͷσϓϩΠ·Ͱશ෦΍ͬͯ͘ΕΔ STEP1 STEP2 STEP3 STEP4