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

AWS Amplify for Serverless apps

AWS Amplify for Serverless apps

2019/7/6に開催された Hamamatsu.js #7での発表資料です。
https://connpass.com/event/132081/

jacoyutorius

July 06, 2019
Tweet

More Decks by jacoyutorius

Other Decks in Technology

Transcript

  1. Yuto Ogi Web Developper at AIRS @jacoyutorius Skill Ruby, Rails

    Javascript, Vue.js, React, AWS Alexa Skills Community Hamamatsu.rb, JAWS-UG, Hamamatsu.js
  2. why Serverless ? • Webαʔόʔཱͯͨ͘ͳ͍ • ҡ࣋අ͔͔Δ • ϝϯςφϯεΊΜͲ͏(ηΩϡϦςΟ, ߋ৽,

    etc) JavascriptͰॻ͍ͨΞϓϦέʔγϣϯΛಈ͔͢ʹ͸΄ͱΜͲͷ৔߹αʔόʔ͕ඞཁ
  3. why Serverless ? ࡢࠓͷΫϥ΢υετϨʔδʹ͸ WebαΠτΛϗεςΟϯάͰ͖Δػೳ͕෇ ͍͍ͯΔ Ϋϥ΢υετϨʔδ •Amazon S3 (AWS)

    •Azure Storage (Microsofr Azure) •CloudStorage (GCP) •Object Storage Service (Alibaba Cloud)
  4. why Serverless ? •AWS Lambda (AWS) •Azure Functions (Microsoft Azure)

    •Google Cloud Functions (GCP) •Function Compute (Alibaba Cloud) ίϯςφϕʔεͷίϯϐϡʔςΟϯάαʔϏε ϦΫΤετΛड͚ΔͱΫϥ΢υ্Ͱίϯςφ͕ىಈ͠ɺ͋Β͔͡Ίઃఆ͓͍ͯͨ͠ ίʔυ͕࣮ߦ͞ΕΔ
  5. why AWS ? αʔόʔϨεΞʔΩςΫνϟΛߏ੒͢Δཁૉͷ͏ͪɺΫϥ΢υଆͷϦιʔεߏ ங͕ߴ౓ʹ౷߹͞Ε͍ͯΔ 4BB4ͱ͔40"ͱ͔͔ͳΓੲʹฉ͍ͨݴ༿Ͱ͕͢ɺ "84ͷ֤छαʔϏε͸୯ಠͷαʔϏε &$ 4 3%4

    $MPVE'PSNBUJPO౳ ͱͦΕΒΛ ૊Έ߹ΘͤͨϚωʔδυαʔϏε &MBTUJD#FBOTUBML $MPVE "NQMJGZ ʹେผͰ͖Δɻ  ϚωʔδυαʔϏεͰ͸ରԠͰ͖ͳ͍ϫʔΫϑϩʔΛߏங͍ͨ͠৔߹ʹ͸୯ಠͷαʔϏεΛ ಠࣗʹ૊Έ߹ΘͤΔ͜ͱͰಉ༷ͷ࢓૊ΈΛߏஙͰ͖Δɻ
  6. Settings 1. install amplify 2. account setting $ npm install

    -g @aws-amplify/cli $ amplify configure
  7. S3 ? •Ϋϥ΢υετϨʔδ •Route53(DNSαʔϏε) ΍ CloudFront(CDN) ͱͷ࿈ܞ΋༰қ •Amplify ͷΦϓγϣϯͰ S3

    + CloudFront ͷߏங΋Ͱ͖Δ •Ξοϓϩʔυ͞ΕͨϑΝΠϧ͸ෳ਺ͷσʔληϯλʔʹόοΫΞοϓ͞ΕΔ •99.999999999 % ͷ଱ٱੑ •؆୯ͳWebαΠτͳΒֹ݄¥10ఔ౓Ͱӡ༻Ͱ͖Δ
  8. amplify status $ amplify status Current Environment: dev | Category

    | Resource name | Operation | Provider plugin | | ——————— | ——————————— | -------————-- | -------------—————-- | amplify Ͱ༗ޮԽ͞Ε͍ͯΔAWSϦιʔεΛ֬ೝ͢Δ
  9. initialize amplify with Vue apps $ amplify init Note: It

    is recommended to run this command from the root of your app directory ? Enter a name for the project amplify-storage ? Enter a name for the environment dev ? Choose your default editor: Visual Studio Code ? Choose the type of app that you're building javascript Please tell us about your project ? What javascript framework are you using vue ? Source Directory Path: src ? Distribution Directory Path: dist ? Build Command: yarn build ? Start Command: yarn serve
  10. hosting 1. add hosting 2. deploy $ amplify add hosting

    $ amplify publish S3ͷ”੩తαΠτϗεςΟϯά” ΦϓγϣϯΛ༗ޮԽͨ͠όέοτΛ࡞੒ yarn build Ͱੜ੒͞Εͨ HTML/JS Λ S3όέοτ ΁Ξοϓϩʔυ
  11. $ amplify status Current Environment: dev | Category | Resource

    name | Operation | Provider plugin | | Hosting | S3AndCloudFront | Create | awscloudformation | DONE Build complete. The dist directory is ready to be deployed. INFO Check out deployment instructions at https://cli.vuejs.org/guide/deployment.html ✨ Done in 11.75s. frontend build command exited with code 0 ✔ Uploaded files successfully. Your app is published successfully. http://amplify-storage-20190701225005-hostingbucket-dev.s3-website-ap- northeast-1.amazonaws.com
  12. Storage 1. add storage 2. push $ amplify add storage

    $ amplify push Ξοϓϩʔυ༻S3όέοτ͕࡞੒͞Εͯ src/ ʹઃఆϑΝΠϧ(aws-exports.js) ͕࡞੒͞ΕΔ
  13. Storage 1. deploy $ amplify publish `publish` ͸2ͭͷಈ࡞ • amplify

    init ࣌ʹఆٛͨ͠ϏϧυίϚϯυ͕࣮ߦ͞ΕΔ(ࠓճ͸`yarn build`) •yarn build Ͱ࡞੒͞Εͨ HTML/JS/CSS ͕S3΁Ξοϓϩʔυ͞ΕΔ • AWS΁ͷϦιʔεมߋ
  14. Demo Image Uploader http://amplify-storage-20190701225005-hostingbucket-dev.s3-website-ap- northeast-1.amazonaws.com/#/ Amplify + S3 + Vue

    http://amplify-appsync-chat-20190627232107-hostingbucket-dev.s3-website-ap- northeast-1.amazonaws.com/?#/ Amplify + AppSync + DynamoDB + Vue + Bulma Chat http://amplifyauth-20190616111939-hostingbucket-dev.s3-website-ap- northeast-1.amazonaws.com/#/signin?redirect=%2F Amplify + Cognite + Vue Sign In
  15. clean up 1. remove resource $ amplify <category> remove $

    amplify push `remove` ͰϩʔΧϧͷCloudFormationఆٛϑΝΠϧ͕มߋ͞Εɺ `push` ͰAWS΁ద༻ɻ