Amazon EventBridgeを利用して StripeのWebhookを処理する / stripe-with-eventbridge

Amazon EventBridgeを利用して StripeのWebhookを処理する / stripe-with-eventbridge

JP_Stripes (Stripe ユーザーグループ)in 大阪 Vol.5

75486cbfd37125f121cf4a6c5614601c?s=128

Hidetaka Okamoto

January 27, 2020
Tweet

Transcript

  1. Amazon EventBridgeΛར༻ͯ͠ StripeͷWebhookΛॲཧ͢Δ JP_Stripes (Stripe Ϣʔβʔάϧʔϓʣin େࡕ Vol.̑ #JP_Stripes

  2. About: Hidetaka Okamoto גࣜձࣾσδλϧΩϡʔϒ "MFYB$IBNQJPOT 3FBDU5ZQF4DSJQU"84 #JP_Stripes

  3. About: Hidetaka Okamoto גࣜձࣾσδλϧΩϡʔϒ "MFYB$IBNQJPOT 3FBDU5ZQF4DSJQU"84 #JP_Stripes

  4. #JP_Stripes

  5. Agenda ࢼͨ͜͠ͱɿ4USJQFͷ8FCIPPLΛ"NB[PO&WFOU#SJEHFͰॲཧ ࢼͨ͠ཧ༝ɿ8FCIPPLͷ؅ཧΛޮ཰Խ͔ͨͬͨ͠ ࢼͨ͠ํ๏ɿ"84$%,Ͱ8FCIPPLΛίʔυ؅ཧ ࢼͨ݁͠Ռɿ$'/UFSSBGPSNݣ͍ʹ͸Αͦ͞͏ #JP_Stripes

  6. Agenda ࢼͨ͜͠ͱɿ4USJQFͷ8FCIPPLΛ"NB[PO&WFOU#SJEHFͰॲཧ ࢼͨ͠ཧ༝ɿ8FCIPPLͷ؅ཧΛޮ཰Խ͔ͨͬͨ͠ ࢼͨ͠ํ๏ɿ"84$%,Ͱ8FCIPPLΛίʔυ؅ཧ ࢼͨ݁͠Ռɿ$'/UFSSBGPSNݣ͍ʹ͸Αͦ͞͏ #JP_Stripes

  7. StripeͷWebhookΛAWS΁ 4USJQFͷ8FCIPPL؅ཧ͸(6*࡞ۀ͕Ұൠత "84ʹ͸ΠϕϯτΛ%JTQBUDI͢ΔαʔϏε͕͋Δ "NB[PO&WFOU#SJEHF$MPVE8BUDI&WFOUϕʔεͷ౷߹αʔϏε "NB[PO&WFOU#SJEHFͰ4USJQF"84ͷ8FCIPPLܥΛू໿؅ཧ #JP_Stripes

  8. Agenda ࢼͨ͜͠ͱɿ4USJQFͷ8FCIPPLΛ"NB[PO&WFOU#SJEHFͰॲཧ ࢼͨ͠ཧ༝ɿ8FCIPPLͷ؅ཧΛޮ཰Խ͔ͨͬͨ͠ ࢼͨ͠ํ๏ɿ"84$%,Ͱ8FCIPPLΛίʔυ؅ཧ ࢼͨ݁͠Ռɿ$'/UFSSBGPSNݣ͍ʹ͸Αͦ͞͏ #JP_Stripes

  9. StripeͷWebhook؅ཧΛָ͍ͨ͠ (6*Ͱ8FCIPPLΛͭͭొ࿥ͯͨ͠ ଞͷ4BB4ͱͷσʔλ࿈ܞͳͲɺ8FCIPPLͰͭͳ͙΋ͷ͕૿͖͑ͯͨ Ͳͷ8FCIPPLͰԿΛ͍͔͕ͯͨ࣍͠ୈʹΘ͔Βͳ͘ͳΔ 8FCIPPLͷ؅ཧΛָʹ͍ͨ͠ #JP_Stripes

  10. Amazon EventBridge HTTPS://AWS.AMAZON.COM/JP/EVENTBRIDGE/ #JP_Stripes

  11. "NB[PO&WFOU#SJEHF͸ɺಠࣗͷΞϓϦέʔγϣϯɺ౷߹ 4PGUXBSFBTB4FSWJDF 4BB4 ΞϓϦέʔγϣϯɺ͓Αͼ"84ͷ αʔϏε͔ΒͷσʔλΛ࢖༻ͯ͠ɺΞϓϦέʔγϣϯΛ؆୯ʹ઀ଓ ͢Δ͜ͱΛՄೳʹ͢ΔαʔόʔϨεΠϕϯτόεͰ͢ɻ &WFOU#SJEHF͸ɺ;FOEFTLɺ%BUBEPHɺ1BHFSEVUZͳͲͷΠϕϯ τιʔε͔ΒϦΞϧλΠϜσʔλͷετϦʔϜΛ഑৴͠ɺͦͷσʔλ Λ"84-BNCEBͳͲͷλʔήοτʹϧʔςΟϯά͠·͢ɻ IUUQTBXTBNB[PODPNKQFWFOUCSJEHF

  12. EventBridgeͰͰ͖Δ͜ͱ $MPVE8BUDI&WFOU͕αʔϏεͱͯ͠ಠཱͨ͠Α͏ͳΠϝʔδ "84্ΧελϜͷΠϕϯτΛ؂ࢹ Πϕϯτ͕དྷΔͱɺఆٛ͞ΕͨαʔϏεʢ-BNCEBͳͲʣΛ࣮ߦ λʔήοτΠϕϯτͱݺͼग़͠ઌ͸ϧʔϧͰఆٛՄೳ #JP_Stripes

  13. ΠϕϯτύλʔϯͰ StripeͷΠϕϯτΛ ࢦఆ͢Δ #JP_Stripes

  14. TargetͰ࣮ߦ͢ΔॲཧΛࢦఆ͢Δ ɾϧʔϧͷ൑ఆ΍௥Ճύϥϝλ΋ࢦఆՄೳ ɾෳ਺ొ࿥Մೳɺϧʔϧͷઃఆ΋ݸผ #JP_Stripes

  15. StripeͰEventBridge ΧελϜΠϕϯτͱͯ͠࢖༻͢Δ 4USJQF8FCIPPL"1*(8-BNCEB&WFOU#SJEHF 4USJQFʹ͸8FCIPPL͚ͭͩొ࿥ʢର৅Πϕϯτશͯૹ৴ʣ &WFOU#SJEHFଆͰΠϕϯτλΠϓΛ൑ผͯ͠ॲཧܥΛىಈ͢Δ #JP_Stripes

  16. ͪͳΈʹ

  17. terraformͰ Stripe͸؅ཧ Ͱ͖ΔΒ͍͠ #JP_Stripes ޙ͔Β஌ͬͨ

  18. WEBHOOKҎ֎΋؅ཧՄೳʢͷ༷ࢠʢͩΕ͔ࢼͯ͠ʢ࣍ճ஻ͬͯʣʣʣ HTTPS://GITHUB.COM/FRANCKVERROT/TERRAFORM-PROVIDER-STRIPE #JP_Stripes

  19. Agenda ࢼͨ͜͠ͱɿ4USJQFͷ8FCIPPLΛ"NB[PO&WFOU#SJEHFͰॲཧ ࢼͨ͠ཧ༝ɿ8FCIPPLͷ؅ཧΛޮ཰Խ͔ͨͬͨ͠ ࢼͨ͠ํ๏ɿ"84$%,Ͱ8FCIPPLΛίʔυ؅ཧ ࢼͨ݁͠Ռɿ$'/UFSSBGPSNݣ͍ʹ͸Αͦ͞͏ #JP_Stripes

  20. AWS CDK - εΫϦϓτݴޠͰϦιʔε؅ཧ 5ZQF4DSJQU+BWBͳͲ $MPVE'PSNBUJPOͷ:".-ΛεΫϦϓτͰهड़͢Δ ܕ෇ݴޠΛ࢖͑͹*%&Ͱೖྗิ׬͕͋Δ ॻ͖ํʹࣗ৴ͷͳ͍ϦιʔεΛ࢖͏ͳΒ$%,͕ೖ໳͠΍͍͢ #JP_Stripes

  21. ΠϕϯτύλʔϯͰ StripeͷΠϕϯτΛ ࢦఆ͢Δ #JP_Stripes

  22. None
  23. None
  24. • @aws-cdk/aws-events • CfnEventBusͰ౤ೖଆ • CfnRuleͰDispatchϧʔϧ • eventPatter.detail-typeʹ StripeͷΠϕϯτΛྻڍ •

    targetsʹݺͼग़͠ઌ
  25. Stripe Webhook͔Β EventBridge΁౤ೖ #JP_Stripes

  26. None
  27. • EventBusName / Source͸ CDKͷఆٛͱἧ͑Δ • DetailTypeʹ WebhookͷTypeΛ౉͢ • DetailʹຊମΛ౉͢

  28. ͪͳΈʹ

  29. ࢖ͬͯ·͔͢ɺॺ໊γʔΫϨοτ

  30. Stripe͔Βͷ ϦΫΤετ͔Λ ݕূ͢Δ #JP_Stripes https://stripe.com/docs/webhooks/signatures

  31. ॲཧલʹconstructEventͰݕূΛ AWS Secret ManagerΛ࢖͏ͱΑΓ҆શ https://wp-kyoto.net/verify-stripe-webhook-signature

  32. ͓͞Β͍ ೖΓޱɿ4USJQF"1*(BUFXBZ-BNCEB&WFOU#SJEHF ࣮ॲཧɿ&WFOU#SJEHF-BNCEB'JSFIPTFFUDʜ 4USJQF8FCIPPLΛ͏͚Δ"1*͸ϦΫΤετͷݕূΛ "84$%,΍4FSWFSMFTT'8ͳͲͰ࣮ॲཧܥΛίʔυ؅ཧ͠Α͏ Πϕϯτͷ௥Ճ΍EFWQSPEͷৼΓ෼͚΋ίʔυ (JUͰ҆શ؅ཧʂ #JP_Stripes

  33. Agenda ࢼͨ͜͠ͱɿ4USJQFͷ8FCIPPLΛ"NB[PO&WFOU#SJEHFͰॲཧ ࢼͨ͠ཧ༝ɿ8FCIPPLͷ؅ཧΛޮ཰Խ͔ͨͬͨ͠ ࢼͨ͠ํ๏ɿ"84$%,Ͱ8FCIPPLΛίʔυ؅ཧ ࢼͨ݁͠Ռɿ$'/UFSSBGPSNݣ͍ʹ͸Αͦ͞͏ #JP_Stripes

  34. AWSͰ؅ཧ or StripeͰ؅ཧ 8FCIPPLͷ؅ཧΛ4USJQF͔Β"84ʹҠ͚ͨͩ͠ $'/UFSSBGPSNͳͲͰͷ؅ཧͱ-BNCEBͱͷ౷߹ָ͕ 4USJQF8FCIPPLͷҟৗݕ஌ܥͳͲ͕࢖͑ͳ͘ͳΔ Ͳͷಓ؅ཧ͠ͳ͍ͱ͍͚ͳ͍ͷ͸มΘΒͳ͍ "84Ͱίʔυ؅ཧ͠ͳ͍ͳΒ͋·ΓϝϦοτ͸ͳͦ͞͏ #JP_Stripes

  35. એ఻

  36. ڈ೥ʢJP_Stripes Connect 2019ʣ HTTPS://CONNECT2019.JPSTRIPES.COM/ #JP_Stripes

  37. ࠓ೥ʢJP_Stripes Connect 2020ʣ HTTPS://CONNECT2020.JPSTRIPES.COM/ #JP_Stripes

  38. JP_STRIPES CONNECT 2020 @ೆ੨ࢁ IN 4/18(SAT) SAVE THE DATE !