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

NetlifyでFaaSに入門する / netlify-functions

mottox2
August 10, 2018

NetlifyでFaaSに入門する / netlify-functions

Tech Do #6で発表したNetlify Functionsの話です。

Netlify
https://www.netlify.com/

元ネタブログ
https://mottox2.com/posts/165/

参考リポジトリ(Deployボタン置いてます)
https://github.com/mottox2/netlify-functions-hello-world

mottox2

August 10, 2018
Tweet

More Decks by mottox2

Other Decks in Technology

Transcript

  1. NetlifyͰFaaSʹೖ໳͢Δ 2018.08.09 Tech Do #6 AWS Lambda, GCP Cloud FunctionsͷҰาखલ

    @mottox2
  2. Netlify • ੩తαΠτΛϗεςΟϯάͯ͘͠ΕΔαʔϏεaʢ੩తαΠτHerokuʣ • BuildίϚϯυͱެ։ϦϙδτϦΛࢦఆ͢Δͱ͍͍͔Μ͡ʹσϓϩΠͯ͘͠ΕΔɻ

  3. FaaS Πϝʔδͱͯ͠͸ؔ਺͚ͩॻ͚͹͍͍ײ͡ʹಈ͔ͯ͠ΕΔαʔϏε 'VODUJPO request response URL Call: https://example.com/hoge Status: 200

    body: Hello World Event Call: S3ʹϑΝΠϧ͕อଘ͞Εͨͱ͖ OR ͚ͩ͜͜ؾʹ͢Ε͹Α͍
  4. Netlify Functions • Netlify͸੩తαΠτϗεςΟϯάઐ༻ʹݟ͑Δ͕ɺͲΜͲΜػೳΛ૿΍͍ͯ͠Δ • ͦͷதͰFunctionsͱ͍͏ػೳ͕͋Γɺத਎͸AWS LambdaͰಈ͍͍ͯΔ • ݄ؒͰ ࣮ߦճ਺͕125,000ճҎԼ

    or ࣮ߦ͕࣌ؒ100࣌ؒҎ಺Ͱ͋Ε͹ແྉ • NetlifyͳͷͰɺϦϙδτϦͷϒϥϯνͱ࿈ಈͯ͠σϓϩΠ͞ΕΔɻ • ΫϨδοτΧʔυͷొ࿥΋ෆཁɻa • Node.js ·ͨ͸ Golang Ͱॻ͚Δɻ • ΋ͪΖΜS3΍Dynamo DBΛϑοΫʹͨ͠ىಈ͸Ͱ͖ͳ͍ɻURLͷΈɻ
  5. ͳͥNetlify Functions GitHubΞΧ΢ϯτ͕͋Ε͹ແྉͰ࢖͑Δ GitHubͱͷ࿈ܞ͕ॳظঢ়ଶͰ༻ҙ͞Ε͍ͯΔ URLͰ͔͠ىಈͰ͖ͳ͍ͷͰΘ͔Γ΍͍͢ ΫϨδοτΧʔυ΋ඞཁ͕ͳ͍ͷͰ՝ۚࣄނ΋ා͘ͳ͍ 1 2 3 4

  6. Ұ൪؆୯ͳྫ

  7. ࣮૷ͯ͠GitHubʹPush /functions/hoge.js /netlify.toml • Functionsͱͯ͠ಈ͔ͨ͠ϑΝΠϧΛؚΉ
 σΟϨΫτϦΛࢦఆ • Event͔Βrequest৘ใΛऔಘ • callbackͰresponseΛ࿔Δ

    https://github.com/mottox2/netlify-functions-hello-world
  8. NetlifyʹGitHubͷϦϙδτϦΛඥ෇͚Δ

  9. NetlifyʹGitHubͷϦϙδτϦΛඥ෇͚Δ

  10. NetlifyʹGitHubͷϦϙδτϦΛඥ෇͚Δ

  11. ಈ࡞֬ೝ Netlifyͷ؅ཧը໘ͰϑΝΠϧຖʹϩά͕ݟΕΔ

  12. ಈ࡞֬ೝ

  13. ؆୯Ͱͨ͠Ͷʁ ࢀߟϦϙδτϦ https://github.com/mottox2/netlify-functions-hello-world

  14. ΋ͬͱෳࡶͳྫ͸ʁ • ࠓճͷྫͰ͸ϥΠϒϥϦ΋࢖ΘͣBuild΋͠ͳ͔ͬͨɻ • ͪΌΜͱ΍͍ͬͯ͘ͱ͖͸ `netlify-lambda` ͱ͍͏webpackͷϥούʔϥΠϒϥϦ Λ࢖͍ͬͯ͘ɻ • https://github.com/netlify/netlify-lambda

    Ͱ • `netlify-lambda build src/` ͰϏϧυͯ͘͠ΕΔɻ
  15. Կ͕࡞ΕΔͷʁ • Netlify୯ମͰ͸֎෦αʔϏεͷWebhookΛड͚ͯɺಛఆͷαʔϏεͷAPIΛୟ͘ͱ ͍͏࢖͍ํʹͳΔͱࢥ͏ɻ • ࣗ෼͸Slack AppΛNetlify্Ͱӡ༻͍ͯ͠·͢ɻ • https://github.com/mottox2/slack-esa-preview͋ •

    Slack͔ΒϦΫΤετΛड͚ͯesa.ioͱ͍͏αʔϏεͷAPIΛୟ͍͍ͯ·͢ɻ • ࢓ࣄͰ͸಺෦ͰWordPress REST APIΛୟ͍ͯɺϑϩϯτΤϯυͷΞϓϦέʔγϣϯ ʹฦ͢ॲཧΛॻ͍͍ͯ·͢ɻ • ࣮͸WebαʔϏεͱૄ݁߹ͳՕॴΛ͚ͩ͜͜nodejs΍golangͰॻ͘ͱ͖ͳͲ
  16. Lambda΍Cloud FunctionsͰεςοϓΞοϓ • AWS͸UIͰଛ͍ͯ͠Δͱࢥ͏ͷͰNetlifyͰLambdaʹೖ໳͢Δͱ͍͍ͱࢥ͍·͢ɻ • URL͚ͩ͡Όͳͯ͘ɺAWS΍GCPͷଞαʔϏεͱ࿈ಈ͢ΔΑ͏ͳΠϕϯτͰͷىಈ ͕ՄೳʹͳΔɻ • DBͷσʔλΛݩʹͳʹ͔͢ΔɺΞοϓϩʔυ͞ΕͨϑΝΠϧΛݩʹͳʹ͔͢ΔͷΑ ͏ͳॲཧ͕Ͱ͖ΔΑ͏ʹͳΔɻ

    • ʮখ͞ͳαʔϏεͳΜ͚ͩͲExpressΛ࢖͏΄ͲͰ΋ͳ͍ʯΑ͏ͳγνϡΤʔγϣ ϯͷͱ͖ʹબ୒ࢶͱͯ͠΋͓ͬͯ͘ͱΑ͍ɻ • ৗ࣌Քಇ͓ͯ͘͠ඞཁ͕ͳ͍ͷͰઅ໿ʹ΋ͳΔ͠ɺϝϯςϑϦʔɻa
  17. FaaS͸͍͍ͧʂແྉͰ࢖͑ΔNetlify΋͍͍ͧʂ ·ͱΊ ݩωλͷϒϩάهࣄ https://mottox2.com/posts/165/

  18. @mottox2 • ReactͱRuby on RailsΛத৺ʹWebαʔϏε։ൃ͍ͯ͠·͢ • ϒϩά΍ͬͯ·͢(esa.io + note.mu +

    GatsbyJS) => mottox2.com • #ٕज़ॻయ5 ͰNetlifyͱGatsbyJSͷຊΛग़͠·͢ Freelance web engineer Yuki Takemoto ୭ʁ