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

サーバレスアーキテクチャのアンチパターンと活用方法_20170126

shogomuranushi
January 26, 2017
1.2k

 サーバレスアーキテクチャのアンチパターンと活用方法_20170126

shogomuranushi

January 26, 2017
Tweet

More Decks by shogomuranushi

Transcript

  1. • Ϋϥ΢υͱ͍ͬͯ΋෺ཧͰಈ͍͍ͯΔ • ࢭ·Βͳ͍γεςϜ͸ଘࡏ͠ͳ͍ • SDK͸Ϋϥ΢υ͕ࢭ·ΔલఏͰϦτϥΠॲཧͱ͔͕૊Έࠐ·Ε͍ͯΔɻՄೳͳݶΓSDKΛ࢖͏ • SDKΛ࢖Θͳ͍৔߹͸ɺ૬ख͕ड͚औΕͳ͔ͬͨ৔߹Λ૝ఆͯ͠ϦτϥΠ͢Δ
 ॲཧΛೖΕΑ͏ɻϦτϥΠʹΑΓޙʹ੒ޭ͢ΔՄೳੑ͕ߴ͍ •

    ϦτϥΠॲཧͷਪ঑͸ɺΫϥΠΞϯτଆ͸ʮExponential Backoffʯ͕ਪ঑ɻ
 Lambdaʹؔͯ͠͸ʮDead Letter QueueʯΛར༻͢Δ • Exponential Backoff • σʔλૹ৴ॲཧ͕ࣦഊͯ͠࠶ૹ৴͢Δͱ͖ʹɺࣦഊճ਺͕૿͑Δʹ࿈Εͯ
 ࠶ૹ৴͢Δ·Ͱͷ଴ͪ࣌ؒΛࢦ਺ؔ਺తʹ૿΍͢࢓૊Έ
 ʢྫɿ̍ඵޙɺ̎ඵޙɺ̐ඵޙɺ̔ඵޙɺɺɺʣ • ௕ظো֐ൃੜ࣌ʹγεςϜ΁ͷෆඞཁͳෛ୲Λܰݮ • Dead Letter Queue • ࣮ߦࣦഊ࣌ (3ճϦτϥΠࣦഊ࣌) ʹSQS͔SNSʹ౤͛ΕΔػೳ • SQSʹಥͬࠐΜͩޙʹΰχϣΰχϣ͢Δ SDK͸͔͍͜͠ɻՄೳͳݶΓSDKΛ
  2. 2. ʮͱΓ͋͑ͣLambda FirstͰʯ multimedia Amazon SQS Amazon SNS AWS IoT

    AWS Lambda Amazon API Gateway mobile client AWS Lambda AWS Lambda AWS Lambda AWS Lambda AWS Lambda
  3. ՄࢹԽੑ͕௿͘ɺಉ࣮࣌ߦ΍
 ϦτϥΠॲཧͰ໰୊ग़Δ͔΋ • ಉ࣮࣌ߦ਺͕100ͳͷͰɺ1Lambdaͷॲཧ͕࣌ؒ௕͍ͱಉ࣮࣌ߦ਺Ͱ಄ଧͪ͢Δ͔΋ɻ
 1ϑΝϯΫγϣϯͷ࣮ߦ࣌ؒ͸ՄೳͳݶΓ୹͘͢Δ͜ͱ
 ʢಉ࣮࣌ߦ਺ͷ্ݶ؇࿨Մೳ͕ͩɺ࣮੷͕গͳ͍৔߹͸௨Βͳ͍͜ͱ΋͋Δͦ͏ʣ • Lambda͕ࣦഊͨ͠ࡍʹ߹ܭ3ճϦτϥΠॲཧ͞Εͯ͠·͏ͨΊɺ్த·Ͱͷॲཧ͕ෳ਺ճ࣮ ߦ͞Εͯ͠·͏͜ͱ΋͋Δɻ࣮֬ʹ1ճ͚࣮ͩߦ͍ͨ͠৔߹͸ʮcontext.done()ʯ͢Δɻ •

    όονॲཧͰ͍͏ͱ͜ΖͷϦϥϯͱ͔ɺτϥϯβΫγϣϯɾϩʔϧόοΫͱ͔ແ͍ͷͰႈ౳ ੑ͕อͨΕͨɺෳ਺ճ࣮ߦͯ͠΋͍͍ॲཧͰ࡞Βͳ͍ͱγϯυΠ͔΋ʢ΂͖࿦͗͢Δ͚Ͳʣ • StepFunctionΛ࢖͑͹ॲཧϑϩʔ΋ՄࢹԽग़དྷͯɺ؅ཧ͕ḿΔͷͰ1Lambdaʹ߆Δඞཁͳ͍ • ͨͩɺ࠶ૹ΍ׂΓࠐΈͳͲΛߟྀ͓͔ͯ͠ͳ͍ͱޙͰϝϯς͠ʹ͍͘͜ͱ΋ɻ
 ͜ͷลͷϕετϓϥΫςΟε͸·ͩ·ͩ͜Ε͔Βɻ
  4. RDS΁ͷ઀ଓͷಓ͸ࠔ೉ • Lambda͔ΒVPC಺ʢPrivate SubnetʣͷRDSʹ઀ଓ͢Δʹ͸VPC in LambdaΛ࢖͏ඞཁ͕͋ΓɺLambdaͷى ಈ͕஗͘ͳΔʢENIͷੜ੒͕஗͍ʣ • VPC in

    Lambda͸LambdaΛ࣮ߦ͢Δ͝ͱʹENIΛ࢖༻͢ΔͨΊɺSubnet͸େ͖֬͘อ͠ͳ͍ͱSubnetͷIPΛ ࢖͍੾ͬͯENI͕ੜ੒ग़དྷͣʹΤϥʔ͕ൃੜ͢Δ • Lambda in Public͸RDSʹରͯ͠ɺSecurityGroupͷϑϧ։์ʢ΋͘͠͸Ұ࣌తʹࣗIPΛ։์ʣ͕ඞཁʹͳΔ ͕ɺDBͷಛੑΛ౿·͑ΔͱηΩϡϦςΟ্ɺϑϧ։์΍Public SubnetʹRDSΛ഑ஔ͢Δͷ͸ݱ࣮తͰ͸ͳ͍ • Lambda͔ΒRDS΁ͷDBίωΫγϣϯ͸ϦΫΤετ୯ҐʹͳΔͨΊɺಉ࣌઀ଓ͕଱͑ΒΕͳ͍Մೳੑ΋ • σʔλετΞͷమଇ͸DynamoDBɻ
 DBͷ໰୊ͰͲ͏ͯ͠΋VPCΛར༻͍ͨ͠ʢPrivateʹ഑ஔ͍ͨ͠ʣ৔߹͸ɺDynamoDB StreamsʢDynamoDB Streams=>Lambda=>SQS=>RDSʣΛར༻ͨ͠ඇಉظ൓өΛݕ౼͢Δ
  5. API GatewayΛڬΉͱ޾ͤʹͳΔ ʢ͔΋ʁʣ • ੜͷAWSαʔϏεʢKinesis΍DynamoDBͳͲʣͰड͚ΔͱɺҎԼͷΑ͏ͳ໰୊͕ • ଞʹྑ͍αʔϏε͕ग़ͨΒΞϓϦଆʢσόΠεଆʣͳͲͷมߋ͕ඞཁ • Πϯϑϥଆ͔Βͨ͠ΒΞϓϦଆʢσόΠεଆʣʹɺԿ࢖ͬͯΔ͔ͱ͔αʔϏε Λҙࣝͯ͠΄͘͠ͳ͍

    • API GatewayΛؒʹڬΈRESTͰड͚ΔΑ͏ʹ͢ΔͱɺΠϯϑϥʢAWSαʔϏε ଆʣ͸ந৅Խ͞ΕΔ • ந৅Խ͓ͯ͘͠ͱɺΑΓྑ͍αʔϏε͕ग़ͨ࣌ʹΞϓϦଆʢσόΠεଆʣʹґ ଘͤͣʹॊೈʹมߋ͕Մೳ • Ұ൪࢝ΊʹSDKΛ࢖͑ɻͬͯݴ͚ͬͨͲɺԿΛॏࢹ͢Δ͔ʁͰબ୒Λ