Ruby on Lambdaで変わる大規模サービスの裏側 / Ruby on Lambda makes a change to Eight's backend

13d936e697fe0f4fa96f926d0a712f6c?s=47 Sansan
March 27, 2019

Ruby on Lambdaで変わる大規模サービスの裏側 / Ruby on Lambda makes a change to Eight's backend

AWS Serverless Tech/事例セミナー
- サーバーレスで Ruby 他、いろんな言語が使えるよ
https://pages.awscloud.com/ServerlessSeminar20190327-jp.html

■登壇概要
タイトル:Ruby on Lambdaで変わる大規模サービスの裏側

登壇者:Eight事業部 エンジニアリングマネージャー 藤井洋太郎

▼Sansan Builders Box
https://buildersbox.corp-sansan.com/

13d936e697fe0f4fa96f926d0a712f6c?s=128

Sansan

March 27, 2019
Tweet

Transcript

  1. 3VCZPO-BNCEBͰมΘΔ
 େن໛αʔϏεͷཪଆ Sansanגࣜձࣾ &JHIUࣄۀ෦1MBUGPSN6OJU6OJU-FBEFS݉&OHJOFFSJOH.BOBHFS ౻Ҫ༸ଠ࿠ "844FSWFSMFTT5FDIࣄྫηϛφʔ

  2. - ౻Ҫ༸ଠ࿠(Fujii Yotaro) - 1989೥ੜ·Ε(30ࡀ) - ɹɹɹɹɹ (ݸਓ޲໊͚ࢗΞϓϦ) - 2014೥4݄ʹ৽ଔͱͯ͠ೖࣾ

    - Platform Unit / ج൫νʔϜ - Unit Leader ݉ Engineering Manager ࣗݾ঺հ
  3. Eight ͷ঺հ

  4. ໊ࢗͰͭͳ͕ΔɺϏδωεͷͨΊͷSNS

  5. ໊ࢗͰͭͳ͕ΔɺϏδωεͷͨΊͷSNS ໊ࢗ؅ཧ ਓࣄ৘ใΛ௨஌ ؔ࿈͢Δاۀͷχϡʔε ϝοηʔδ

  6. ࠃ಺ͰߦΘΕ͍ͯΔ໊ࢗަ׵ͷ10%Ҏ্ΛσʔλԽ Ϣʔβ਺ 
 200ສਓ ࠃ಺໊ࢗަ׵ 
 10%Ҏ্

  7. ։ൃ؀ڥ(ݴޠ/ϑϨʔϜϫʔΫ/αʔϏε)

  8. Eight Ͱར༻͍ͯ͠Δ AWSαʔϏε AWS100αʔϏεͷ͏ͪͷ൒਺Ҏ্Λར༻ D I D KPI D D

    N B P P A B/ I N W D W Recommendation Feed XPSLFS
  9. ຊ୊ / ࠓ೔͓࿩͢Δ͜ͱ

  10. େن໛ͳόονॲཧΛ Ruby on LambdaͰ͍͍ײ͡ʹ͢Δ(͍ͨ͠)࿩

  11. େن໛ͳόονॲཧ?

  12. - ໊ࢗը૾ - χϡʔεϑΟʔυ্ͷը૾ - ϓϩϑΟʔϧը૾ - ը૾ϝϞ - etc…

    EightͰ͸༷ʑͳը૾Λѻ͏
  13. - αϜωΠϧը૾ - ෳ਺αΠζͷαϜωΠϧը૾Λ༻ҙ͠ɺ֤දࣔ৔ॴͰ͸ඞཁ࠷௿ݶͳα Πζͷը૾Λ࢖͏͜ͱͰɺΞϓϦͷߴ଎ԽΛਤ͍ͬͯΔ - ΅͔͠ը૾ - Ӿཡݖݶ͕ແ͍Ϣʔβؒͷ৔߹ɺ΅͔͠ը૾Λදࣔ͢ΔΑ͏ʹ -

    webpϑΥʔϚοτରԠ - JPEGͱൺֱ͠໿30%ϑΝΠϧαΠζ͕খ͘͢͞Δ͜ͱ͕Ͱ͖Δ ମݧ޲্΍ϓϥΠόγʔ؍఺ʹ͓͚Δ༷ʑͳը૾ॲཧΛߦ͏
  14. 1ຕͷ໊͔ࢗΒ࡞ΒΕΔαϜωΠϧɺ΅͔͠ը૾ 1ຕͷ໊ࢗऔΓࠐΈ αΠζ - ද×ཪ - jpeg × webp Λߟ͑Δͱ20छఔ౓ඞཁʹ

    ΦϦδφϧ(ද) ΦϦδφϧ(ཪ) αϜωΠϧ(ද) ΅͔͠αϜωΠϧ(ද) … … … … αϜωΠϧ(ཪ) ΅͔͠αϜωΠϧ(ཪ) jpeg webp
  15. ໊ࢗը૾ͷαϜωΠϧ & ΅͔͠ॲཧϑϩʔ

  16. - σΠϦʔͰ਺ेʙ਺ඦສͷը૾ॲཧδϣϒ ͕ൃੜ - ೔தʹϐʔΫ͕๚ΕΔ͕ɺ
 όονॲཧػߏͷؔ܎Ͱ༰қʹεέʔϧ͕Ͱ͖ͳ͍ - ॲཧ͕଺ཹ͠ɺαϜωΠϧը૾͕४උͰ͖͍ͯͳ͍ͱɺ
 ը૾औಘAPIͰ on-the-fly

    ʹը૾ੜ੒ΛߦΘͳ͚Ε͹ͳΒͣɺ
 ϨεϙϯεྼԽʹͭͳ͕ͬͯ͠·͏… αʔϏε֦େʹͭΕɺεέʔϥϏϦςΟͷ໰୊͕ൃੜ
  17. ը૾ॲཧΩϡʔͷ enqueue / dequeue ঢ়گͰݟͯΈΔ னա͗ͷϐʔΫ࣌ʹεέʔϧͰ͖͍ͯͳ͍ɻ εέʔϧΞ΢τ͢Δʹ͸όοναʔόʔΛ૿΍ ͠RailsϓϩηεΛ্ཱͪ͛ͳ͚Ε͹͍͚ͳ͍ ݱঢ়͸։ൃऀ͕खಈͰରԠ" ͔͠͠ɺ࣍ୈʹ࿛গ೥ঢ়ଶʹ…

    ྲྀೖ͕མͪண͍ͯ΋ɺॲཧྔ͸ߴ͍ঢ়ଶͰுΓ෇ ͍͍ͯΔɻ਺࣌ؒ଺ཹ/஗Ԇͯ͠͠·͍ͬͯΔɻ → ը૾औಘAPIͷύϑΥʔϚϯεྼԽʹͭͳ͕Δ enqueue dequeue
  18. ΠϕϯτۦಈͰॲཧ͍ͨ͠…! ref: αʔόʔϨεύλʔϯ / ܗͰߟ͑ΔαʔόʔϨεઃܭ https://aws.amazon.com/jp/serverless/patterns/serverless-pattern/

  19. - ͕ɺEight ʹͱͬͯ RubyͰॻ͚ͳ͍͜ͱ͕େ͖ͳ໰୊ Lambda ʹߦ͚Ε͹޾ͤͩͱ͍͏͜ͱ͸Θ͔͍ͬͯΔ - ໊ࢗը૾पΓͷॲཧ͸ຊମαʔϏεʹີ઀ʹඥ෇͍͍ͯΔ - ಉظతʹ໊ࢗը૾Λ৮Βͳ͍ͱ͍͚ͳ͍έʔε͕͋ΓɺϩδοΫͷଟॏ؅ཧʹ

    - Ϣʔβؒͷؔ܎ੑ΍ެ։εςʔλεʹΑ໊ͬͯࢗը૾औಘՄ൱΍݁Ռ͕ҟͳΔɻ - ը૾αʔϏε(?)ͷΑ͏ʹαʔϏεΛ੾Γग़͢ͷ͸ɺݱঢ়͔ͳΓՙ͕ॏ͍ - ͦΜͳதɺଞͷݴޠΛ࢖ͬͯͷ Lambda ࣮૷͸ϝϯςφϯεੑʹ೉͋Γ…
  20. ͦΜͳ͜ͱΛߟ͑ͳ͕Β͸΍਺೥ɺ͍ͭʹ Lambda ͕ Ruby Λαϙʔτʂ EightνʔϜ ɹɹ׻تʂ ฐࣾࢀՃϝϯόʔ͔Β଎ใ͕ʂ

  21. - ໊ࢗը૾Λѻ͏ίΞϩδοΫΛGemͳͲʹ੾Γग़͢͜ͱ͕Ͱ͖Ε͹ɺ
 ຊମαʔϏεͰ΋ར༻Ͱ͖Δ͠ɺLambda͔Β΋ར༻Ͱ͖Δ - ଟॏ؅ཧ͕ෆཁʂ Ruby on LambdaͰมΘΔ!?Eightͷඇಉظ(όον)ॲཧ ௿ίετͳରԠͰεέʔϥϏϦςΟΛ֬อͰ͖Δʂʁ

  22. [ཧ૝Πϝʔδ] ڞ௨ॲཧΛࣗલͷgemͱͯ͠੾Γग़ͤ͹͍͍ײ͡ʹʁ eight_card_image_processor gem ɾը૾ͷอଘɾߋ৽ɾ࡟আ ɾαϜωΠϧը૾ੜ੒ ɾ΅͔͠ը૾ੜ੒ ɾjpegม׵αϙʔτ ɾwebpม׵αϙʔτ ໊ࢗը૾ʹؔ͢Δ

    ڞ௨ॲཧΛࣗ࡞Gemͱͯ͠੾Γग़͢ bundle install bundle install
  23. ͱ͍͏͜ͱͰ ໊ࢗը૾ॲཧΛߦ͏LambdaΛಈ͔͢·ͰͷಓͷΓ

  24. - ᶃ gemΛ࢖ͬͨ Lambda Λ࡞Δ - ᶄ native extensionsʹґଘ͢ΔgemΛ࢖ͬͨ Lambda

    Λ࡞Δ - ᶅ ࣮ߦόΠφϦΛؚΊͨ Lambda Λ࡞Δ - ᶆ Lambda LayersΛར༻࣮ͯ͠ߦόΠφϦΛFunction͔Β੾Γ཭͢ - ᶇ FrameworkΛར༻ͨ͠ϩʔΧϧ࣮ߦ؀ڥͱσϓϩΠ؀ڥ - ᶈ CI / CD؀ڥͷߏங εςοϓ
  25. - bundle install ࣌ʹ࡞ۀσΟϨΫτϦ௚Լͷ vendor/bundle ʹΠϯετʔϧ͞ ΕΔΑ͏ʹ͠ɺlambda function(rubyίʔυ)ͱҰॹʹΞοϓϩʔυ͢Ε͹'
 - σΟϨΫτϦߏ੒ྫ

    1. Ruby on Lambda Ͱ Gem Λར༻͢Δ bundle install --path vendor/bundle
  26. - workσΟϨΫτϦ௚Լͷ vendor/bundle Ͱಈ͘ཧ༝
 Lambda࣮ߦ؀ڥͷ؀ڥม਺(GEM_PATH)ʹσϑΥϧτͰ௥Ճ͞Ε͍ͯΔͨΊ 1. Ruby on Lambda Ͱ

    Gem Λར༻͢Δ https://docs.aws.amazon.com/ja_jp/lambda/latest/dg/current-supported-versions.html
  27. - Lambda ͷ࣮ߦ؀ڥͱಉ౳ͷ؀ڥͰbundle(Ϗϧυ)͢Δඞཁ͕͋Δ 2. native extension ʹґଘͨ͠ gem ͷ৔߹ lambci/lambda:build-ruby2.5

    
 lambci dockerΠϝʔδΛ࢖Θͤͯ΋Β͏ https://github.com/lambci/docker-lambda lambci # rmagickͳͲnative extensionsΛඞཁͱ͢ΔgemΛGemfileʹهड़ $ vi Gemfile # docker container্Ͱbundle install. volumeϚ΢ϯτ͠ϗετ্ͷ vendor/bundle ʹΠϯετʔϧ
 $ docker run -v `pwd`:/var/task -it lambci/lambda:build-ruby2.5 bundle install --path vendor/bundle # lambda_handler.rb, vendor/bundleΛzipԽͯ͠Ξοϓϩʔυ $ zip -r zip_function ./*
  28. - Eightͷը૾ॲཧͰ͸ߴ଎ԽͷͨΊʹ webp ϑΥʔϚοτม׵Λߦ͍ͬͯΔ - ͕ɺ௨ৗͷLambda࣮ߦ؀ڥͷImageMagick͸ webp ରԠ͍ͯ͠ͳ͍…orz 3. ࣮ߦόΠφϦΛؚΊͨ

    Lambda ͷ࡞੒ ## ImageMagickͷversion֬ೝ $ convert -version
 Version: ImageMagick 6.7.8-9 2016-06-22 Q16 http://www.imagemagick.org Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC Features: OpenMP ## ରԠը૾ϑΥʔϚοτͷ֬ೝɻ $ convert -list format … VST* TGA rw- Truevision Targa image WBMP* WBMP rw- Wireless Bitmap (level 0) image WMF* WMF r-- Windows Meta File … dockerίϯςφ্ͰImageMagickΛ֬ೝ webp͕ରԠϦετʹແ͍
  29. - ࣮ߦόΠφϦΛؚΊͯLambdaؔ਺ΛύοέʔδϯάԽ͢Δͷ͕ਖ਼߈๏✅ - native extensionsΛ࢖͏ࡍͱಉ༷ɺLambdaͷDocker؀ڥͰ࣮ߦόΠφϦΛϏϧυ - Ϗϧυ͢ΔࡍͷΠϯετʔϧσΟϨΫτϦ͸஫ҙ͕ඞཁɻϥΠϒϥϦݕࡧύεΛ֬ೝ͢Δ͜ͱ - Lambda࣮ߦ؀ڥͷσϑΥϧτͷϥΠϒϥϦݕࡧύεͷ؀ڥม਺͸ҎԼ -

    ඞཁʹԠͯ͡ɺLambdaʹ؀ڥม਺Λ༩͑Δ(্ॻ͘͜ͱ΋)Մೳ 3. ࣮ߦόΠφϦΛؚΊͨ Lambda ͷ࡞੒ https://docs.aws.amazon.com/ja_jp/lambda/latest/dg/current-supported-versions.html
  30. - WebP compatibleͳImageMagickΛϏϧυ͢Δࡍͷ࣮ߦྫ 3. ࣮ߦόΠφϦΛؚΊͨ Lambda ͷ࡞੒ ## Lambdaؔ਺͕ల։͞ΕΔσΟϨΫτϦͰ࡞ۀ cd

    /var/task ## libwebpͷinstall curl -sLO https://storage.googleapis.com/downloads.webmproject.org/releases/webp/ libwebp-1.0.0.tar.gz \ && tar zxvf libwebp-1.0.0.tar.gz \ && cd libwebp-1.0.0 && ./configure --prefix=/var/task && make && make install \ && rm -rf ../libwebp-1.0.0.tar.gz ../libwebp-1.0.0 ## webp compatibleͳImageMagickͷϏϧυ curl -sLO https://www.imagemagick.org/download/releases/ImageMagick-6.9.10-34.tar.gz \ && tar zxvf ImageMagick-6.9.10-34.tar.gz \ && cd ImageMagick-6.9.10-34 && ./configure --prefix=/var/task --with-webp=yes \ && make && make install \ && rm -rf ../ImageMagick-6.9.10-34.tar.gz ../ImageMagick-6.9.10-34 - /var/task ҎԼͷϑΝΠϧ(*.rb, vendor/bundle, bin/, lib/, etc…)Λશͯύοέʔδϯά(zipԽ)͢Ε͹OK lambci dockerίϯςφ্ͰϏϧυ࡞ۀ
  31. - ͔͠͠ɺ࣮ߦόΠφϦ(ImageMagick౳)ΛؚΊͨΞοϓϩʔυ͸஍ຯʹਏ͍ ࣮ߦόΠφϦΛʮؚ·ͳ͍ʯ৔߹ (*.rb, vendor/bundle ͷΈ) ࣮ߦόΠφϦΛʮؚΉʯ৔߹ (*.rb, vendor/bundle, bin/,

    lib/, …) ໿5MB ໿50MB! - ࣮ߦόΠφϦࣗମΛߋ৽͢Δස౓͸ଟ͘ͳ͍͸͕ͣͩɺ
 ؔ਺Λमਖ਼͢Δͨͼʹຖճύοέʔδϯά & σϓϩΠ͠ͳ͚Ε͹ͳΒͳ͍ - ؅ཧ͢ΔLambda͕ҰͭͰ͋Ε͹·ͩɺͳΜͱ͔ͳΔ͔΋͠Εͳ͍͕…? ਏ͍͜ͱʹ͸มΘΒͳ͍ 3. ࣮ߦόΠφϦΛؚΊͨ Lambda ͷ࡞੒
  32. - re:Invent 2018 Ͱ Ruby Support ͱҰॹʹϦϦʔε͞ΕͨʮLambda Layersʯ 4. Lambda

    LayersΛ࢖ͬͯσϓϩΠίετΛ࡟ݮ͢Δ
  33. - Lambda Layers : ෳ਺ͷLambdaؔ਺ͰϥΠϒϥϦΛڞ༗Ͱ͖Δ࢓૊Έ
 ৄࡉ͸ https://docs.aws.amazon.com/ja_jp/lambda/latest/dg/configuration-layers.html 4. Lambda LayersΛ࢖ͬͯσϓϩΠίετΛ࡟ݮ͢Δ

    - Point - Layerͷίʔυ͸ /opt ҎԼʹల։͞ΕΔ - /opt ҎԼͷύε͸ϥΠϒϥϦݕࡧύεʹ
 σϑΥϧτͰؚ·Ε͍ͯΔ ref: https://qiita.com/t_okkan/items/394a15577bd1aad46ec3
  34. - Dockerίϯςφ্ͰWebP Compatible ImageMagick LayerΛ࡞Δ 4. Lambda LayersΛ࢖ͬͯσϓϩΠίετΛ࡟ݮ͢Δ # Lambda

    Layer͕ల։͞ΕΔ /opt ҎԼͰ࡞ۀ cd /opt ## libwebpͷinstall curl -sLO https://storage.googleapis.com/downloads.webmproject.org/releases/webp/ libwebp-1.0.0.tar.gz \ && tar zxvf libwebp-1.0.0.tar.gz \ && cd libwebp-1.0.0 && ./configure --prefix=/opt && make && make install \ && rm -rf ../libwebp-1.0.0.tar.gz ../libwebp-1.0.0 ## webp compatibleͳImageMagickͷϏϧυ curl -sLO https://www.imagemagick.org/download/releases/ImageMagick-6.9.10-34.tar.gz \ && tar zxvf ImageMagick-6.9.10-34.tar.gz \ && cd ImageMagick-6.9.10-34 && ./configure --prefix=/opt --with-webp=yes \ && make && make install \ && rm -rf ../ImageMagick-6.9.10-34.tar.gz ../ImageMagick-6.9.10-34 - /opt ҎԼͷϑΝΠϧ(bin/, lib/, etc…)Λύοέʔδϯά͠LayersʹΞοϓϩʔυ͢Ε͹OK ΠϯετʔϧσΟϨΫτϦͷࢦఆΛ /var/task ͔ΒLayer͕ల։͞ΕΔ /opt ҎԼʹมߋ
  35. 4. Lambda LayersΛ࢖ͬͯσϓϩΠίετΛ࡟ݮ͢Δ - Layerͷ࡞੒ - Lambdaʹ࡞੒ͨ͠
 LayersΛؔ࿈෇͚Δ

  36. - , ֎෦ϥΠϒϥϦΛLayersʹҠߦ͢Δ͜ͱͰɺϏδωεϩδοΫͷ։ൃʹूத͠ ΍͘͢ͳΔ - , Lambdaؔ਺ͷσϓϩΠ࣌ʹɺ֎෦ϥΠϒϥϦΛؚΉύοέʔδϯά͕ෆཁʹ ͳΓσϓϩΠίετ͕࡟ݮ - -

    ҰํͰɺLayersࣗମͷόʔδϣϯ؅ཧ΍ɺLambdaͱͷґଘؔ܎ɾඥ෇͚Λखಈ Ͱߦ͍ͬͯ͘ͷ͸ΑΓෳࡶʹ… - ϑϨʔϜϫʔΫಋೖͷػӡ 4. Lambda LayersΛ࢖ͬͯσϓϩΠίετΛ࡟ݮ͢Δ
  37. - LambdaΛؚΉServerlessΞʔΩςΫνϟͷߏ੒؅ཧɺϩʔΧϧ࣮ߦɺσϓϩΠ͕ՄೳͳϑϨʔϜϫʔΫ - AWS SAM(Serverless Application Model) - Serverless Framework

    ͷ2୒͔ 5. ϑϨʔϜϫʔΫΛར༻͠࠶ݱੑ/ܧଓੑΛߴΊΔ AWS SAM - AWSެࣜͷαʔόʔϨεΞʔΩςΫνϟʹ
 ಛԽͨ͠ϑϨʔϜϫʔΫ - CloudFormationͰ؅ཧ - ϩʔΧϧ࣮ߦ؀ڥΛ੔උ - σϓϩΠखॱ͕एׯෳࡶͳҹ৅ - AWSҎ֎ͷΫϥ΢υʹ΋ରԠ - SAMಉ༷ɺCloudFormationͰ؅ཧ - ։ൃ͕੝Μ(ͳҹ৅) - pluginͳͲ΋๛෋Ͱ͔Ώ͍ͱ͜Ζʹख͕ಧ͘ - ࠓճ͸͢ͰʹEightͰར༻࣮੷ͷ͋Δ Serverless Framework Λ࠾༻
  38. - Serverlss Framework ͱDockerΛར༻͠ɺLambdaͱLayersΛ؅ཧ͢Δ 5. ϑϨʔϜϫʔΫΛར༻͠࠶ݱੑ/ܧଓੑΛߴΊΔ ΦεεϝͷσΟϨΫτϦߏ੒Ҋ - ᶃ Layers

    ͷ؅ཧ
 Dockefileʹهड़͠ɺDocker Image಺ʹด͡ࠐΊͯ͠·͏ɻ
 Layers ʹߋ৽͕͋ͬͨ৔߹͸Docker ImageΛ࠶Ϗϧυ͢Δɻ - ᶄ Serverless Framework
 serverless΋Docker಺Ͱ࣮ߦͰ͖ΔΑ͏ʹ - ᶅ Lambdaؔ਺, serverless.yml, vendor/bundleͷ؅ཧ
 ্ड़ͷDockerίϯςφͷ্ཱͪ͛࣌ʹ /var/task ʹ࡞ۀσΟϨΫτϦΛϚ΢ϯ τ͠ɺίϚϯυ࣮ߦ͸Dockerίϯςφ্Ͱߦ͏ɻ - gemͷ௥Ճ/ߋ৽͸͠͹͠͹͋ΔͨΊvendor/bundle͸
 docker imageʹ͸ؚΊͳ͍ & όʔδϣϯ؅ཧ΋͠ͳ͍(.gitignore)
  39. - Layers͸ Dockerfile Ͱ؅ཧͯ͠͠·͏ͷ͕٢ 5. ϑϨʔϜϫʔΫΛར༻͠࠶ݱੑ/ܧଓੑΛߴΊΔ LambdaͷDocker ImageΛϕʔεͱͨ͠ ࣗલͷDocker Image༻ҙ

    FROM lambci/lambda:build-ruby2.5 # ࡞ۀ؀ڥͷߏஙʹඞཁͳ؀ڥม਺ͷఆٛ ENV PKG_CONFIG_PATH /opt/lib/pkgconfig # Lambda layer૬౰ͷ؀ڥΛ࡞੒ WORKDIR /opt ## libwebpͷinstall ... (લड़ͱಉ༷ͷॲཧ) ## webp compatibleͳImageMagickͷϏϧυ ... (લड़ͱಉ༷ͷॲཧ) # serverless frameworkͷΠϯετʔϧ RUN curl -sL https://rpm.nodesource.com/setup_6.x | bash - \ && yum -y install nodejs && yum -y clean all \ && npm install -g serverless WORKDIR /var/task/ CMD ["/bin/bash"] ᶃlambci/lambda:build-ruby2.5 Λ
 ɹϕʔεʹͨ͠Πϝʔδ ᶄ/opt ഑ԼʹAWS Layersʹ૬౰͢Δ
 ɹϥΠϒϥϦΛϏϧυ͠഑ஔ ᶅnodeΛΠϯετʔϧ͠ɺ
 ɹserverless frameworkΛΠϯετʔϧ͢Δ Dockerfileྫ
  40. - serverless.yml Ͱͷ layers, functionsͷઃఆྫ 5. ϑϨʔϜϫʔΫΛར༻͠࠶ݱੑ/ܧଓੑΛߴΊΔ … layers: webpimagemagick:

    path: copy_layers # /opt ͷγϯϘϦοΫϦϯάΛష্ͬͨͰdeploy͢Δ description: WebP compatible ImageMagick functions: func1: handler: func1.execute layers: - {Ref: WebpimagemagickLambdaLayer} events: - s3: card-images func2: handler: func2.execute Lambdaؔ਺Ͱ࢖͏LayerΛ ඥ෇͚ͯ؅ཧ͢Δ͜ͱ͕Մೳ ࢦఆͨ͠bucketʹߋ৽͕͋ͬͨࡍʹ lambda࣮ߦͤ͞Δઃఆ
  41. - Ϗϧυͨ͠Docker Imageͷίϯςφ্Ͱ։ൃ࡞ۀ - bundle install —path vendor/bundle - gemͷΠϯετʔϧ

    - bundle exec rspec - rubyίʔυͷࣗಈςετ࣮ߦ - serverless deploy - functionͱlayersͷσϓϩΠ - serverless invoke (local) -f function໊ - Lambda functionͷ(ϩʔΧϧ)࣮ߦ 5. ϑϨʔϜϫʔΫΛར༻͠࠶ݱੑ/ܧଓੑΛߴΊΔ
  42. $ sls deploy ...snip Serverless: Uploading service aws-ruby-function.zip file to

    S3 (4.02 MB)... Serverless: Uploading service webpimagemagick.zip file to S3 (47.44 MB)... ...snip api keys: None endpoints: None functions: func1: eight-image-proccessor-dev-func1 func2: eight-image-proccessor-dev-func2 layers: webpimagemagick: arn:aws:lambda:ap-northeast-1:xxxxx:layer:webpimagemagick:9 Serverless: Removing old service artifacts from S3... 5. ϑϨʔϜϫʔΫΛར༻͠࠶ݱੑ/ܧଓੑΛߴΊΔ - deployίϚϯυΛୟ͚ͩ͘Ͱɺlambdaͱlayersͷύοέʔδϯά&σϓϩΠ͕Ͱ͖Δ - serverless(sls) deploy functionͱlayer͕ͦΕͧΕύοέʔδϯά σϓϩΠ׬ྃͨ͠functionsͱlayersͷ৘ใ
  43. def hello(event:, context:) { statusCode: 200, body: JSON.generate('Go Serverless v1.0!

    Your function executed successfully!’) } end 5. ϑϨʔϜϫʔΫΛར༻͠࠶ݱੑ/ܧଓੑΛߴΊΔ - ϩʔΧϧ؀ڥͰͷlambdaͷಈ࡞֬ೝ΋Ͱ͖Δ - serverless(sls) invoke local -f function໊ $ sls invoke local -f hello {"statusCode":200,"body":"\"Go Serverless v1.0! Your function executed successfully!\""}
  44. - CircleCIͰࣗಈςετ࣮ߦ & 
 ಛఆͷϒϥϯνʹϚʔδ͞ΕͨΒɺࣗಈͰ֤AWS؀ڥʹDeployment - serverlessͷdeployίϚϯυͷstage optionΛ࢖͏͜ͱͰɺσϓϩΠͷ੾Γ෼͚͕Մೳ 6. ࠷ޙʹCI

    / CD؀ڥͷߏங
  45. ཧ૝ͱ͍ͯͨ͠ߏ੒ʹ, eight_card_image_processor gem ɾը૾ͷอଘɾߋ৽ɾ࡟আ ɾαϜωΠϧը૾ੜ੒ ɾ΅͔͠ը૾ੜ੒ ɾjpegม׵αϙʔτ ɾwebpม׵αϙʔτ ໊ࢗը૾ʹؔ͢Δڞ௨ॲཧΛ੾Γग़ͨࣗ͠࡞Gem bundle

    install bundle install deploy
  46. - gem(vendor/bundle)ɺnative extensions΍֎෦ϥΠϒϥϦͷϏϧυɺlayer ԽΛߦ͏͜ͱͰෳࡶͳཁ݅ͷLambdaؔ਺Λ࡞Δ͜ͱ͕Մೳ - Docker؀ڥ΍ϑϨʔϜϫʔΫΛ༗ޮʹ׆༻͠ɺLambda Function΍Layers Λ؅ཧ͢Δ - ϒϥϯνઓུΛ޻෉͠ɺϑϨʔϜϫʔΫͱ࿈ܞͤ͞Δ͜ͱͰCI/CDΛ༰қ

    ʹ࣮ݱՄೳʹ ͜͜·Ͱͷ੔ཧ
  47. ӡ༻໘

  48. - ݻఆͰ༻ҙ͍ͯͨ͠EC2ΠϯελϯεΛ؅ཧ͢Δඞཁ͕ͳ͘ͳͬͨ. - ໷ؒଳͷδϣϒ͕গͳ͍࣌ؒଳ͸ΞΠυϧλΠϜ͕ଟ͘ແବͳίετ͕͔ ͔͍͕ͬͯͨɺLambdaʹҠߦͨ͜͠ͱͰίετ໘Ͱ΋࠷దԽ͞Εͨ มΘͬͨ͜ͱ ΞΠυϧ࣌ؒͰ΋ෆཁͳίετ͕͔͔Βͳ͘ͳͬͨ

  49. - ϐʔΫλΠϜͰ΋ Lambda ͕ࣗಈͰεέʔϧ͠଺ཹ͕΄΅0ʹ - ͜Ε·Ͱӡ༻ऀ͕खಈͰ΍͍ͬͯͨӡ༻ίετ΋΄΅0ʹ - ຖ೔ϐʔΫ࣌ʹൃੜ͍ͯͨ͠
 Ξϥʔτ &

    εέʔϦϯάۀ຿͔Βͷ։์ . - ଺ཹ͕ͳ͘ͳΔ = APIύϑΥʔϚϯε΋޲্ - ଺ཹ࣌ʹൃੜͯ͠͠·͏ಉظతͳը૾ม׵ॲཧʹ͔͔͍ͬͯͨ
 ਺ेʙ਺ඦ ms / req ͕ൃੜ͠ͳ͘ͳͬͨ✨ มΘͬͨ͜ͱ ࣗಈͰεέʔϧΞ΢τ/Πϯ
  50. - Lambda ΍։ൃ؀ڥͷϝϯςφϯε - ࠓճͷΑ͏ͳ Ruby on Lambda ͷ։ൃ؀ڥΛҰ౓࡞ͬͯ͠·͑͹ɺ
 ࠓޙͷLambda

    Functionͷ௥Ճɾमਖ਼ɾ࡟আ͸༰қ , - εέʔϥϏϦςΟ͕ωοΫͰରԠͰ͖ͳ͔ͬͨػೳվળ΋͠΍͘͢ - ը૾ϑΥʔϚοτ΍αΠζͷ֦ு - ը૾ͷ඼࣭ͷ࠷దԽͳͲ มΘͬͨ͜ͱ
  51. - ۀ຿ͰRubyΛϝΠϯʹ৮͍ͬͯΔํ͸ Lambda ͸ͥͻ࢖͏΂͠ - ڞ௨ॲཧΛGemԽ͢Δ͜ͱͰɺඇಉظॲཧ౳Λ༰қʹLambdaʹ͍͚࣋ͬͯΔɻ - Serverless Framework ΍

    AWS SAM Λར༻͢Δ͜ͱͰίετΛॻ͚ͣʹ
 αʔόʔϨεͳ։ൃɾCI/CD؀ڥΛߏஙͰ͖Δɻ - Native extentionʹґଘ͢Δgem΍֎෦ϥΠϒϥϦΛར༻͢Δ৔߹͸ Lambda ͱಉ ౳ͷ࣮ߦ؀ڥͰϏϧυ͠σϓϩΠ͢Δɻ - `lambci/lambda` Λϕʔεʹͨ͠Docker؀ڥͷߏஙΛ͢Δ͜ͱΛΦεεϝ͠·͢ ·ͱΊ
  52. [ࢀߟ] EightͰͷ͜Ε·ͰͷServerlessࣄྫ

  53. ϦΞϧλΠϜϦίϝϯσʔγϣϯػߏ JAWS Days 2017 : https://www.slideshare.net/YotaroFujii/jaws-days-2017eight AWS Dev Day Tokyo

    2017 : https://speakerdeck.com/yas/awsgazhi-erueightrikomendesiyonenzinfalseli-ce
  54. χϡʔεϑΟʔυը૾ͷѹॖ / Ωϟογϡػߏ EightͷཪଆΛࢧ͑Δٕज़ : https://buildersbox.corp-sansan.com/entry/cto_interview_1-1

  55. ͓ΘΓ 55

  56. None