サーバーレス失敗談 - DynamoDB編 / Serverless Fails

サーバーレス失敗談 - DynamoDB編 / Serverless Fails

Serverless Meetup Tokyo #11 での発表で使用したスライドです。

外部リンク:
Serverless Meetup Tokyo #11
https://serverless.connpass.com/event/119559/

HiCustomer
https://hicustomer.jp

ServerlessなサービスのBlue/Greenデプロイメントの現実 | HiCustomer Tech Blog
https://tech.hicustomer.jp/posts/blue-green-deployment-in-serverless/

サーバーレス失敗談 - テーブル設計編 | HiCustomer Tech Blog
https://tech.hicustomer.jp/posts/serverless-fails/

1cf6e2aa4d9be4d8ab8ec45598ee3f1c?s=128

Yosuke Hizen

March 06, 2019
Tweet

Transcript

  1. αʔόʔϨεࣦഊஊ %ZOBNP%#ฤ  )J$VTUPNFSJODංલ༸༎!IJ[FOZ

  2. w ංલ༸༎ w !IJ[FOZ w ΤϯδχΞBU)J$VTUPNFSJOD w ࢁͳͲΛ૸Γ·͢

  3. ໨࣍  ϓϩμΫτͱνʔϜ  ΞϓϦέʔγϣϯߏ੒  %ZOBNP%#ࣦഊஊ  ςʔϒϧઃܭ 

    %ZOBNP%#ࣦഊஊ  σϓϩΠ
  4. ϓϩμΫτͱνʔϜ ͳʹͯ͠Δձࣾʁ

  5. ϢʔβʔΛʮϑΝϯʯʹม͑Δ ΧελϚʔαΫηε؅ཧϓϥοτϑΥʔϜ ͬͯʁ

  6. ͬͯʁ w #UP# 4BB4ϓϩμΫτͷӡӦاۀ޲͚αʔϏε w 4BB4ͷར༻ঢ়گΛ෼ੳՄࢹԽ͢ΔҰछͷ؂ࢹαʔϏε w 4BB4ͷΧελϚʔαΫηε୲౰ͷํ͕ϝΠϯϢʔβʔ

  7. νʔϜ ϓϩδΣΫτΦʔφʔ υϝΠϯΤΩεύʔτ σβΠφʔ ΤϯδχΞ *DPONBEFCZ'SFFQJLGSPNXXXqBUJDPODPN ʜϑϧλΠϜ ʜύʔτλΠϜ #&'& αϙʔτ

    '& ୅දླ໦ $4ߴڮ
  8. ։ൃख๏ ݴޠ (P5ZQF4DSJQU ΞʔΩςΫνϟ w αʔόʔϨε "1*(BUFXBZ-BNCEB%ZOBNP%#  w 41"

    7VFKT7VFY  ϓϩδΣΫτ؅ཧ εΫϥϜ ;FO)VC/PUJPO
  9. ΞϓϦέʔγϣϯߏ੒

  10. ॲཧͷྲྀΕ w ֤ࣾͷ4BB4ϓϩμΫτ͔ΒૹΒΕͯ͘ΔΧελϚʔͷߦಈϩάΛऩू͢Δ w ʮ௚ۙO೔ؒͰΠϕϯτ"͕NճҎ্ߦΘΕͨʯʮܖ໿ߋ৽೔·ͰO೔Ҏ಺ʯͳͲͷϧʔϧʹج͖ͮΧελϚʔͷ
 εςʔλε είΞεςʔδ Λࢉग़͢Δ w ΧελϚʔͷεςʔλεΛμογϡϘʔυͰՄࢹԽ͢Δ

  11. ٕज़తಛ௃ͱ՝୊ w ΠϕϯτυϦϒϯͳγεςϜ w σʔλͷ౤ೖΛى఺ʹείΞܭࢉ΍௨஌Πϕϯτ͕࿈࠯తʹ૸Δ w ߴස౓ʹॻ͖ࠐΈ͕ൃੜ͢Δ1VCMJD"1* w ӡ༻தͷϓϩμΫτ͔ΒΧελϚʔͷߦಈϩά͕શͯૹ৴͞ΕΔ w

    8SJUFͷΈ w ແఀࢭӡ༻ w ಋೖઌͷϓϩμΫτͷن໛ʹΑΓτϥϑΟοΫͷٸ૿͕ߟ͑ΒΕΔ w ௿ස౓͕ͩෳࡶͳΫΤϦ͕ൃੜ͢Δ1SJWBUF"1* w μογϡϘʔυͷΞϓϦέʔγϣϯ͔Βݺͼग़͞ΕΔ w 3FBE͕ϝΠϯ w සൟʹσϓϩΠ͍ͨ͠
  12. ΞʔΩςΫνϟ

  13. ΞʔΩςΫνϟ ߴස౓ʹॻ͖ࠐΈ͕ൃੜ͢Δ1VCMJD"1* w "1*(BUFXBZ -BNCEBͰ࣮૷ w ࠷௿ݶͷ࣮૷ͰՄ༻ੑͷߴ͍"1*Λӡ༻Ͱ͖Δ w εέʔϦϯάͷ໘Ͱؾʹ͢Δඞཁ͕͋Δͷ͸%#΁ͷॻ͖ࠐΈͱ-BNCEBͷಉ࣮࣌ߦ਺͘Β͍

  14. ΞʔΩςΫνϟ ΠϕϯτυϦϒϯͳγεςϜ w %ZOBNP%#4USFBNʹΑΓσʔλͷมߋΛϑοΫʹ-BNCEBΛ࣮ߦͰ͖Δ w Ұ෦$MPVE8BUDI&WFOU͔Βىಈ͞ΕΔ-BNCEB΋͋Δ

  15. ΞʔΩςΫνϟ ௿ස౓͕ͩෳࡶͳΫΤϦ͕ൃੜ͢Δ1SJWBUF"1* w 1VCMJD"1*ͱಉ༷ͷߏ੒ w "1*(BUFXBZͷ$VTUPN"VUIPSJ[FSͰ+85Λݕূ͠ϦΫΤετΛೝՄ w ೝূαʔόʔ͕ผͰଘࡏ͢Δ

  16. ࣦഊ  ςʔϒϧઃܭ %ZOBNP%#ͷෆద੾ͳςʔϒϧ෼ׂ͕ෛ࠴Խ

  17. ݁࿦ w %ZOBNP%#ͷςʔϒϧ͸ՄೳͳݶΓগͳ͘͢΂͖ w 3%#ͷΑ͏ʹͱΓ͋͑ͣਖ਼نԽ͸ѱख w ߋ৽ܥͱࢀরܥͰςʔϒϧ෼ׂ͢Δͱมߋʹڧ͍

  18. σʔλϞσϧ w ϩάσʔλ͸ԼهͷΑ͏ͳϞσϧ w ϞσϧͷϓϩύςΟ͸ސ٬͕೚ҙʹઃܭͰ͖Δ

  19. ςʔϒϧઃܭ ॻ͖ࠐΈͱಡΈऔΓͰςʔϒϧΛ෼཭ $234  w ΠϕϯτιʔγϯάͳΞϓϦέʔγϣϯͰ͸ৗ౟खஈ w *OTFSUʹൺ΂ͯ6QEBUF͸ߴίετ w εϩοτϦϯά͠ͳ͕Βߴίετͳߋ৽ॲཧΛ࣮ߦͰ͖Δ

    w ߋ৽ॲཧʹࣦഊͯ͠΋Πϕϯτςʔϒϧʹσʔλ͕࢒͍ͬͯΔͷͰϩʔϧϑΥϫʔυͰ͖Δ
  20. ݱঢ়ͷςʔϒϧઃܭ γεςϜͷத৺ͱͳΔσʔλ͸ެ։"1*ܦ༝Ͱߴස౓Ͱॻ͖׵͑ΒΕΔͨΊɺ $234ͷߟ͑ํΛऔΓೖΕߋ৽ܥͱࢀরܥͰςʔϒϧΛ෼཭͢Δ

  21. ى͖ͨ໰୊ w ύϑΥʔϚϯεͷ௿Լ w ར༻ස౓ͷ௿͍ςʔϒϧͰεϩοτϦϯά͕සൟʹൃੜ͢Δ w ඞཁͷͳ͍ύʔςΟγϣχϯάʹΑΓίʔϧυελʔτ͕ൃੜ w ΩϟύγςΟϢχοτ࠷దԽͷ؍఺Ͱ΋ෆར w

    σʔλϞσϧͷ௥Ճมߋίετ͕ߴ͍ w %ZOBNP%#4USFBNΛଟ༻͍ͯ͠ΔͨΊςʔϒϧ௥ՃʹՃ͑ετϦʔϜΛϋ ϯυϦϯά͢Δ-BNCEBͷ௥Ճ΋ඞཁ w ؅ཧ͕൥ࡶʹ
  22. Ͳ͏͔ͨ͠ w ෳ਺ʹ෼ࢄͨ͠ςʔϒϧΛ·ͱΊ͍ͯ͘ w σʔλͷछྨ͝ͱʹςʔϒϧΛ෼͚Δҙຯ͸ͳ͍ w ෼ׂʹΑΓςʔϒϧ͋ͨΓͷΞΫηεස౓͕Լ͕ΔͱίʔϧυελʔτΛ ট͍ͯΉ͠Ζඇޮ཰ w ࣌ܥྻσʔλ͸೔࣌͝ͱʹςʔϒϧΛ෼͚Δ

    w େ༰ྔͷσʔλΛѻ͍ɺύʔςΟγϣϯΩʔ͕೔࣌ʹґଘ͢Δ৔߹ w ΩϟύγςΟϢχοτͷرബԽΛ๷͙໨త
  23. ެࣜυΩϡϝϯτʹΑΔͱ lෳ਺ͷςʔϒϧΛ࢖༻͢Δಛఆͷཧ༝͕ͳ͍ݶΓɺ ༏ΕͨઃܭͷΞϓϦέʔγϣϯͰ ඞཁͳςʔϒϧ͸ҰͭͷΈͰ͢z ग़యIUUQTEPDTBXTBNB[PODPNKB@KQBNB[POEZOBNPECMBUFTUEFWFMPQFSHVJEFCQHFOFSBMOPTRMEFTJHOIUNM

  24. มߋޙͷςʔϒϧઃܭ γεςϜͷத৺ͱͳΔσʔλ͸ެ։"1*ܦ༝Ͱߴස౓Ͱॻ͖׵͑ΒΕΔͨΊɺ $234ͷߟ͑ํΛऔΓೖΕߋ৽ܥͱࢀরܥͰςʔϒϧΛ෼཭͢Δ

  25. ݁࿦ w %ZOBNP%#ͷςʔϒϧ͸ՄೳͳݶΓগͳ͘͢΂͖ w 3%#ͷΑ͏ʹͱΓ͋͑ͣਖ਼نԽ͸ѱख w ߋ৽ܥࢀরܥͰςʔϒϧ෼ׂ͢Δͱมߋʹڧ͍

  26. ࣦഊ  σϓϩΠ %ZOBNP%#पลͷ$'OԽʹۤઓ

  27. ݁࿦ w %ZOBNP%#पΓ͸ಛʹ͸͡Ί͔Β$'OʹΑΔ؅ཧ͕ແ೉ w ແఀࢭͰ$'OԽ͢Δͷ͸͔ͳΓखؒ w ςʔϒϧ͚ͩͰͳ͘&WFOU4PVSDF.BQQJOH΋஫ҙ͕ඞཁ

  28. ΞʔΩςΫνϟ ΠϕϯτυϦϒϯͳγεςϜ w %ZOBNP%#4USFBNʹΑΓσʔλͷมߋΛϑοΫʹ-BNCEBΛ࣮ߦͰ͖Δ w Ұ෦$MPVE8BUDI&WFOU͔Βىಈ͞ΕΔ-BNCEB΋͋Δ

  29. ΞʔΩςΫνϟ w %ZOBNP%#4USFBN͸σʔλߋ৽࣌ͷ$IBOHF4FUͷγʔέϯε w &WFOU4PVSDF.BQQJOHͰ4USFBNͱ-BNCEBΛඥ͚ͮΔ w -BNCEB͸4USFBNΛϙʔϦϯά͠ɺ$IBOHF4FUΛೖྗʹ'VODUJPOΛ࣮ߦ͢Δ w &WFOU4PVSDF.BQQJOH͕γʔέϯε൪߸Λอ࣋͠ɺͲ͜·ͰϙʔϦϯά͔ͨ͠Λ؅ཧ

  30. ౰ॳͷσϓϩΠख๏ w %ZOBNP%#ͷςʔϒϧJOEFY͸खಈ$-*Ͱ࡞੒ w มߋස౓͕ߴ͘ͳ͚Ε͹બ୒ࢶͱͯ͠͸͋Γ w ελοΫߋ৽࣌ͷ3FQMBDFNFOU*OUFSSVQUJPO͕ڐ༰Ͱ͖ͳ͍έʔεͳͲ w -BNCEB͸$PEF#VJMEͰ*O1MBDFʹσϓϩΠ w

    *O1MBDFͳσϓϩΠͳͷͰ"3/͸มΘΒͣɺ&WFOU4PVSDF.BQQJOHͷม ߋ͸ҙࣝ͢Δඞཁ͕ͳ͍ w ਺ݸͷ-BNCEBͳΒ$'ΑΓγϯϓϧ͕ͩεέʔϧ͠ͳ͍
  31. ΍Ζ͏ͱͨ͜͠ͱ w खͰ࡞ͬͨελοΫΛ$'OʹΑͬͯ؅ཧ͍ͨ͠ w #MVF(SFFOσϓϩΠΛՄೳʹ w $'OԽͷ࡞ۀࣗମ΋#MVF(SFFOʹ͚͍ۙͮͨ

  32. ໰୊ w 4USFBNؚΊແఀࢭͷҠߦ͕ඞਢ͕ͩ$'OԽʹ͸࠶ߏங͕ඞཁ w ͲͷϨΠϠʔ·ͰΛ$'OԽ͢Δ͔ʹΑΓҠߦӡ༻ίετ͕ܾ·Δ

  33. Ͳ͏͔ͨ͠ w ςʔϒϧ͸$'O؅ཧ֎ʹ w ϏϡʔςʔϒϧͷΈ$'OԽ΋ݕ౼͕ͨ͠ख͕ճΒͣҰ୴อཹ w มߋ͕ඞཁͳ৔߹͸$-*ܦ༝Ͱ w ͨͩ͠1SPEVDUJPOͷΈɺ%FW͸$'OԽ w

    &WFOU4PVSDF.BQQJOH͸ύλʔϯΛൺֱݕ౼ w &WFOU4PVSDF.BQQJOHΛ$'O͔Β֎͢ύλʔϯؚΊΔύλʔϯ
  34. &WFOU4PVSDF.BQQJOH ํ๏&WFOU4PVSDF.BQQJOH·Ͱ$'OԽ͢Δύλʔϯ

  35. &WFOU4PVSDF.BQQJOH ํ๏&WFOU4PVSDF.BQQJOH·Ͱ$'OԽ͢Δύλʔϯ

  36. &WFOU4PVSDF.BQQJOH ํ๏&WFOU4PVSDF.BQQJOH·Ͱ$'OԽ͢Δύλʔϯ w ໰୊ w Ͳͷγʔέϯε·Ͱॲཧ͔ͨ͠͸&WFOU4PVSDF.BQQJOHͷ؅ཧ w &YBDUMZ0ODFͳॲཧͰ͸#MVF͕࠷ޙʹॲཧͨ͠γʔέϯε൪߸Λ
 (SFFOʹ௨஌͢ΔػߏΛΞϓϦଆͰ࣋ͭඞཁ͕͋Δ

  37. &WFOU4PVSDF.BQQJOH ํ๏&WFOU4PVSDF.BQQJOH͸$'O͔Β֎͢ύλʔϯ

  38. &WFOU4PVSDF.BQQJOH ํ๏&WFOU4PVSDF.BQQJOH͸$'O͔Β֎͢ύλʔϯ

  39. &WFOU4PVSDF.BQQJOH ํ๏&WFOU4PVSDF.BQQJOH͸$'O͔Β֎͢ύλʔϯ You can update an event source mapping. This

    is useful if you want to change the parameters of the existing mapping without losing your position in the stream. You can change which function will receive the stream records, but to change the stream itself, you must create a new mapping. If you disable the event source mapping, AWS Lambda stops polling. If you enable again, it will resume polling from the time it had stopped polling, so you don’t lose processing of any records. However, if you delete event source mapping and create it again, it will reset. NBOʹΑΔͱ  EJTBCMF  DIBOHFGVODUJPO  FOBCMF ͷॱʹૢ࡞Λ͢Ε͹ϙδγϣϯΛࣦΘͣʹॲཧΛ࠶։Ͱ͖Δ
  40. ݁࿦ w %ZOBNP%#पΓ͸ಛʹ͸͡Ί͔Β$'OʹΑΔ؅ཧ͕ແ೉ w ແఀࢭͰ$'OԽ͢Δͷ͸͔ͳΓखؒ w ςʔϒϧ͚ͩͰͳ͘&WFOU4PVSDF.BQQJOH΋஫ҙ͕ඞཁ

  41. IUUQTUFDIIJDVTUPNFSKQ αʔόʔϨεࣦഊஊςʔϒϧઃܭฤ 4FSWFSMFTTͳαʔϏεͷ#MVF(SFFOσϓϩΠϝϯτͷݱ࣮ (Pʹ͓͚Δ(SBQI2-ϥΠϒϥϦେԣஅ +85Λ࢖ͬͨࠓͲ͖ͷ41"ͷೝূʹ͍ͭͯ ςοΫϒϩάʹ΋͍Ζ͍Ζॻ͍ͯ·͢

  42. ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠  )J$VTUPNFSJODංલ༸༎!IJ[FOZ