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

Amazon Pinpointを用いてEmailやLINE通知を自動化した基盤 / Story...

Amazon Pinpointを用いてEmailやLINE通知を自動化した基盤 / Story of CRM platform using LINE by Amazon Pinpoint

【スナックミー】
Real Food(リアルフード)のみからできたおやつのパーソナライズ型サブスクリプションBOX
https://snaq.me

hayato miyoshi

October 03, 2019
Tweet

More Decks by hayato miyoshi

Other Decks in Technology

Transcript

  1. • גࣜձࣾεφοΫϛʔ • ࡾ޷ ൏ਓ co-founder & CTO • ౦ژੜ·Ε౦ژҭͪ

    • ݐஙग़਎ΤϯδχΞ • τϥΠΞεϩϯ΍ϚϥιϯΛᅂΉ @miyoshihayato
  2. Mission Vison ৽͍͓͠΍ͭମݧΛ૑଄͠ɺ ͓΍ͭͷ࣌ؒΛՁ஋ͷ͋Δ΋ͷʹ͢Δɻ ਺ඦԯԁن໛ͷ Real FoodεφοΫࢢ৔Λ૑Γɺ ͦͷࢢ৔ͷφϯόʔ1ϒϥϯυͱͳΔɻ ӫཆՁ͕ߴ͘ɺͦΕͰ͍ͯඒຯ͠͞ʹଥڠ͠ͳ͍εφοΫʹΑͬͯɺ͓΍ͭͦͷ΋ͷ࣭Λ্͛Δɻ ·ͨɺϞϊ͚ͩͰ͸ͳ͘ɺ৽͍͓͠΍ͭମݧΛσβΠϯ͠ɺ͓΍ͭͷ࣌ؒͷՁ஋Λ޲্ͤ͞Δɻ

    ͦΕʹΑͬͯɺ͓΍ͭͷ͕࣌ؒ࠼ΓͱͳΓɺ๛͔ͳੜ׆Λ࣮ݱ͢Δɻ Real FoodεφοΫͱ͸ɺܗ͋ΔReal FoodͷΈ͔Β࡞ΒΕͨεφοΫɻ ૉࡐຊདྷ͕࣋ͭӫཆͱඒຯ͠͞Λ࠷େݶʹ׆͔͠ɺਓ޻తͳݪྉ΍Խֶ෺࣭͸࢖Θͳ͍ɻ ӫཆՁ͕ߴ݈͘߁తͰɺͦΕͰ͍ͯඒຯ͠͞ʹଥڠ͸͠ͳ͍ɻ
  3. ։ൃͷओͳπʔϧ - αʔόʔαΠυ : Ruby on Rails (PHP) - ϑϩϯτΤϯυݴޠ

    : BabelɺҰ෦TypeScript - ϑϩϯτΤϯυ : React, Redux, webpack - UIίϯϙʔωϯτΧλϩά : Storybook - σʔλ෼ੳ : python - σʔλϕʔε : Aurora, DynamoDB - Πϯϑϥ : AWS - ։ൃ؀ڥ : Vagrant, Docker - ϦϙδτϦ؅ཧ : GitHub / codecommit - CI / CDͳͲ : CodePipeLine / jest / RSpec - ίϛϡχέʔγϣϯ : Qiita:Team, Slack
  4. Amazon Pinpoint Ͱemail/push௨஌ ͷϢʔεέʔε AWS Batch Amazon Simple Storage Service

    (S3) Amazon Pinpoint લॲཧ ηάϝϯτͷϢʔβʔΛ S3ʹΞοϓϩʔυ ࣌ؒࢦఆ or ଈ࣌഑৴
  5. • json΍csvϑΝΠϧ͕͋Ε͹GUI͔Βૢ࡞͢Δ͜ͱ΋Մೳ • ࣌ؒࢦఆ or ଈ࣌഑৴͕Մೳ • 1ඵؒʹ0 ~ 25,000௨·Ͱ഑৴଎౓Λม͑Β͑Δ

    • ։෧཰΍Click཰Ҏ֎ͷ෼ੳΛ਺෼Ҏ಺Ͱ෼ੳͯ͘͠ΕΔ • ϑΝωϧ෼ੳ΋Ͱ͖Δ & Amazon Personalize Amazon Pinpointͷخ͍͠ϙΠϯτ ௚ײͰ৮ΕΔ ༧໿഑৴(batchॲཧ)΍ۓٸੑͷߴ͍഑৴(଎ใχϡʔεͳͲ) ΞΫηε਺ΛίϯτϩʔϩͰ͖Δ ͨͩૹΔ͚ͩ͡Όͳ͘ɺͦͷޙͷΞΫγϣϯʹ΋ͭͳ͛ΒΕΔ ͞·͟·ͳCVRௐ͕ࠪՄೳ ϑΝωϧ෼ੳ
  6. • ϢʔβʔΞϓϦέʔγϣϯͷݺͼग़͠͸ɺPC/αʔόʔ্ͷAWS SDK·ͨ͸εϚʔτ ୺຤্ͷAWS Mobile SDKͰՄೳ • AWSͷ௨஌αʔϏεͰ͋ΔSNSͷ௨஌ઌͱͯ͠AWS LambdaΛࢦఆ͢Δ •

    S3 Cross-Region ReplicationͰAWS Lambdaؔ਺ͱಉ͡ϦʔδϣϯʹόέοτΛෳ੡ ͠ɺෳ੡όέοτʹAWS Lambda΁ͷΠϕϯτ௨஌Λઃఆ͢Δ ҟͳΔϦʔδϣϯͷAWS LambdaΛར༻͢Δํ๏ ࢀর : https://dev.classmethod.jp/cloud/trigger-lambda-on-other-regions/
  7. • ϢʔβʔΞϓϦέʔγϣϯͷݺͼग़͠͸ɺPC/αʔόʔ্ͷAWS SDK·ͨ͸εϚʔτ ୺຤্ͷAWS Mobile SDKͰՄೳ • AWSͷ௨஌αʔϏεͰ͋ΔSNSͷ௨஌ઌͱͯ͠AWS LambdaΛࢦఆ͢Δ •

    S3 Cross-Region ReplicationͰAWS Lambdaؔ਺ͱಉ͡ϦʔδϣϯʹόέοτΛෳ੡ ͠ɺෳ੡όέοτʹAWS Lambda΁ͷΠϕϯτ௨஌Λઃఆ͢Δ ҟͳΔϦʔδϣϯͷAWS LambdaΛར༻͢Δํ๏͕͋Δ ࢀর : https://dev.classmethod.jp/cloud/trigger-lambda-on-other-regions/
  8. • σʔλϕʔε͕౦ژϦʔδϣϯͷͨΊLambdaܦ༝ͰPinpointΛىಈͰ͖ͳ͍ • ഑৴ͷϫʔΫϑϩʔΛStep FunctionsΛ༻͍Δ༧ఆ͕Ϧʔδϣϯؒ͸setͰ͖ͳ͍ • ηάϝϯτͨ͠δϣϒΛΠϯϙʔτ׬ྃʹ͕͔͔࣌ؒΔ • ࠷ޙͷLINE഑৴࣌Ͱ͸഑৴ਓ਺ /

    50໊෼ͷLambda্ཱ͕͕ͪΔ • ଐੑͷίϯτϩʔϧ AWS LambdaͱࣗಈԽʹ൐͏՝୊ ΦϨΰϯͳͲಉϦʔδϣϯ಺Ͱ͋Ε͹ىಈՄೳ Pinpointͷϑϩʔ͚ͩStep FunctionsΛ༻͍ΔͳͲ Πϯϙʔτ׬ྃΛϙʔϦϯά͢Δඞཁ͕͋Δ ্ݶ؇࿨·ͨ͸ಉ࣌ʹ50,000ਓʹૹΒͳ͚Ε͹جຊ໰୊ͳ͍ ଐੑ͸40ݸ·ͰͳͷͰɺܭըతͳઃܭ͕ඞཁ
  9. AWS Step Functions Amazon S3 AWS Lambda AWS Lambda Amazon

    DynamoDB AWS Lambda AWS Lambda AWS Lambda DONE import? ഑৴ ϑϩʔ Amazon Simple Notification Service Tokyo Region (ap-northeast-1) Oregon Region (us-west-2) AWS Batch
  10. AWS Step Functions Amazon S3 AWS Lambda AWS Lambda Amazon

    DynamoDB AWS Lambda AWS Lambda AWS Lambda DONE import? ഑৴ ϑϩʔ Amazon Simple Notification Service Tokyo Region (ap-northeast-1) Oregon Region (us-west-2) AWS Batch ౦ژϦʔδϣϯ
  11. AWS Step Functions Amazon S3 AWS Lambda AWS Lambda Amazon

    DynamoDB AWS Lambda AWS Lambda AWS Lambda DONE import? ഑৴ ϑϩʔ Amazon Simple Notification Service Tokyo Region (ap-northeast-1) Oregon Region (us-west-2) AWS Batch ΦϨΰϯϦʔδϣϯ
  12. AWS Step Functions Amazon S3 AWS Lambda AWS Lambda Amazon

    DynamoDB AWS Lambda AWS Lambda AWS Lambda DONE import? ഑৴ ϑϩʔ Amazon Simple Notification Service Tokyo Region (ap-northeast-1) Oregon Region (us-west-2) AWS Batch Ϣʔβʔηάϝϯτͨ͠σʔλΛ S3ʹputͰSNSΛணՐ SNS͸Ϧʔδϣϯؒ͸ؔ܎ͳ͍ͷͰɺ Step Functions Λىಈͤ͞Δ Amazon PinpointΛ༻͍ͯ഑৴
  13. AWS Step Functions Amazon DynamoDB AWS Lambda AWS Lambda AWS

    Lambda DONE import? ഑৴ AWS Step Functions Step Functionsͷελʔτ͸ DynamoDB͔Β഑৴͢Δ pinpointͷΞϓϦέʔγϣϯΛ औಘ͢Δ import͞ΕͨJSONσʔλΛ ݩʹηάϝϯτΛ࡞੒ ഑৴͢ΔνϟωϧλΠϓ͔Β ΧελϜνϟωϧ ඪ४Λऔಘ͢Δ importޙ͸݅਺͕ଟ͘ͳΔͱ importʹ͕͔͔࣌ؒΔ(਺࣌ؒ Ͱ͸ͳ͍ͳ͍) ͦͷͨΊɺimport͕׬͔ྃͨ͠ ఆظνΣοΫ͢Δඞཁ͋Γ ׬ྃޙΩϟϯϖʔϯͷੜ੒ ΧελϜͷ৔߹͸ ΧελϜνϟωϧͰ഑৴͢Δ LambdaΛىಈͤ͞Δ
  14. AWS Step Functions Amazon DynamoDB AWS Lambda AWS Lambda AWS

    Lambda DONE import? ഑৴ AWS Step Functions Step Functionsͷελʔτ͸ DynamoDB͔Β഑৴͢Δ pinpointͷΞϓϦέʔγϣϯΛ औಘ͢Δ import͞ΕͨJSONσʔλΛ ݩʹηάϝϯτΛ࡞੒ ഑৴͢ΔνϟωϧλΠϓ͔Β ΧελϜνϟωϧ ඪ४Λऔಘ͢Δ importޙ͸݅਺͕ଟ͘ͳΔͱ importʹ͕͔͔࣌ؒΔ(਺࣌ؒ Ͱ͸ͳ͍ͳ͍) ͦͷͨΊɺimport͕׬͔ྃͨ͠ ఆظνΣοΫ͢Δඞཁ͋Γ ׬ྃޙΩϟϯϖʔϯͷੜ੒ ΧελϜͷ৔߹͸ ΧελϜνϟωϧͰ഑৴͢Δ LambdaΛىಈͤ͞Δ
  15. AWS Lambda ഑৴ AWS Step Functions ׬ྃޙΩϟϯϖʔϯͷੜ੒ ΧελϜͷ৔߹͸ ΧελϜνϟωϧͰ഑৴͢Δ LambdaΛىಈͤ͞Δ

    import os import json import boto3 def lambda_handler(event, context): s3 = boto3.client(‘s3') # ϝοηʔδ಺༰ msg = event["Message"]["smsmessage"]["body"] arr = json.loads(msg) # ΤϯυϙΠϯτҰཡ endpoints = event["Endpoints"] for item in endpoints: # ΤϯυϙΠϯτ line_id = endpoints[item][‘Address'] # ഑৴΁
  16. S3ͷߏ଄ߏ੒ json : ഑৴σʔλҰཡ email_format : ഑৴಺༰ ഑৴͢Δ্Ͱ؅ཧ͠΍͍͢ Α͏ʹઃఆ ͳͷͰɺձࣾํ਑Ͱ͓೚ͤ

    email: ϝʔϧ഑৴ line: LINE഑৴ email_line: ϝʔϧ & LINE഑৴ xxxxʹ͸ line: LINE഑৴ͷϑΥʔϚοτ html: ϝʔϧͷHTMLܕ txt: ϝʔϧςΩετܕ title: ϝʔϧλΠτϧ Amazon S3 s3:// BUCKET_NAME / format / ਌ΧςΰϦ / ϒϥϯυ໊ / ഑৴λΠϓ / ࢠΧςΰϦ_xxxx.txt s3:// BUCKET_NAME / json / ਌ΧςΰϦ / ϒϥϯυ໊ /഑৴λΠϓ / ࢠΧςΰϦ / yyyy-mm-dd.json json / format ਌ɾࢠΧςΰϦ ϒϥϯυ໊ ഑৴λΠϓ ࢠΧςΰϦʔ_xxxx.txt ηάϝϯτϑΝΠϧ໊ ഑৴ϑΝΠϧ໊
  17. AWS Lambda LINE ഑৴ AWS Lambda { "text": { "text":

    "xxxxxx" } } ςΩετ ver. ը૾ ver. ΠϝʔδϚοϓ ver. { "image": { "original_content_url": "xxx", "preview_image_url": "yyy" } } { "imagemap":{ "alt_text": "ccccccccccccccccccccc", “base_url": "https://snaq.me", "h": xxx, "w": yyyy, "actions": [ { "uri_text": "https://snaq.me", "type": "uri", "x": 0, "y": 0, "w": aaaaa, "h": bbbbb }…….. ] } }
  18. AWS Step Functions AWS Lambda AWS Lambda ΞϓϦέʔγϣϯ࡞੒ AWS Step

    Functions pinpointͷΞϓϦʔγϣϯ࡞੒ ࡞ΒΕͨΞϓϦέʔγϣϯΛ DynamoDBʹೖΕࠐΉ & ঢ়گnotificationͤ͞Δ ༗ޮޙͷঢ়گΛ Dynamoʹput & ঢ়گΛnotificationͤ͞Δ Amazon DynamoDB AWS Lambda AWS Lambda Amazon DynamoDB ΞϓϦέγϣʔϯͰ EMAILΛ༗ޮʹͤ͞Δ
  19. ௨஌ AWS Step Functions AWS Lambda AWS Lambda ΞϓϦέʔγϣϯ࡞੒ AWS

    Step Functions Amazon DynamoDB AWS Lambda AWS Lambda Amazon DynamoDB { “app_email": "[email protected]", "app_name": "xxxxxxxxxxx" }
  20. Amazon Pinpointͷ੍ݶ (ओʹ஫ҙ͕ඞཁͳpoint) Ϧιʔε σϑΥϧτͷ੍ݶ ૿Ճͷର৅ AttributesɺMetricsɺUserAttributes ύϥϝʔ λʹ·ͱΊׂͯΓ౰ͯΒΕͨଐੑ ΞϓϦ͝ͱʹ

    40 ͍͍͑ ଐੑ஋ͷ௕͞ 100 จࣈ ͍͍͑ ಉ͡Ϣʔβʔ ID Λ࣋ͭΤϯυϙΠϯτ Ϣʔβʔ ID ͝ͱʹ 10 ݸͷҰҙ ͷΤϯυϙΠϯτ ͍͍͑ ηάϝϯτͷ࡞੒ʹ࢖༻Ͱ͖ΔσΟϝϯγϣ ϯͷ࠷େ਺ ηάϝϯτ͝ͱʹ 100 ͍͍͑ ηάϝϯτ಺ʹಉҰͷΤϯυϙΠϯτ ॏෳ͸࡟আ͞ΕΔ ͍͍͑