Slide 1

Slide 1 text

LET’S SHOW YOU THE REAL POWER OF SERVERLESS…!! ݟͤͯ΍Ζ͏…!! SERVERLESSͷຊ౰ͷྗΛ…!! MASASHI TERUI @ JAWS DAYS 2019

Slide 2

Slide 2 text

SERVERWORKS CO.,LTD. + FREELANCER • @marcy_terui • JAWS Days 2015,2017,2018,2019 speaker • Serverlessconf Tokyo 2016,2017,2018 speaker • Remote worker (in Sapporo-shi, Hokkaido) • The best Serverless Architect in Japan !!(Ͱ͋Γ͍ͨʣ MASASHI TERUI ARCHITECT / DEVELOPER

Slide 3

Slide 3 text

SERVERLESS × EVENT DRIVEN ͦͷؔ܎͸ʁ

Slide 4

Slide 4 text

SERVERLESS ARCHITECTURES (MARTINFOWLER.COM) “In the original version, all flow, control, and security was managed by the central server application. In the Serverless version there is no central arbiter of these concerns. Instead we see a preference for choreography over orchestration, with each component playing a more architecturally aware role—an idea also common in a microservices approach.” https://martinfowler.com/articles/serverless.html

Slide 5

Slide 5 text

• ϝοηʔδϯά • ಉظ/ඇಉظ • Interactive/PubSub • σʔλετΞ • εέʔϦϯά • σʔλΞΫηε • ࣮ߦํ๏ • ฒྻ/௚ྻ • ܾఆత/ඇܾఆత ໨తΛՌͨͨ͢Ίͷ࠷దղ͸ҟͳΔ

Slide 6

Slide 6 text

• ಉظ • API Gateway • ඇಉظ • ௚ྻ • Kinesis Streams • ฒྻ • SNS • SQS • ͦͷଞ • Step Functions ͲͷΑ͏ʹॲཧ͢΂͖͔ʁ

Slide 7

Slide 7 text

EVENT DRIVEN ARCHITECTURE https://www.slideshare.net/AmazonWebServices/ building-massively-parallel-eventdriven- architectures-srv373r1-aws-reinvent-2018

Slide 8

Slide 8 text

Event Source + Function = Microservice ʓʓ͕ى͖ͨΒ☓☓͢Δɺશͯ͸ͦͷ૊Έ߹Θͤ

Slide 9

Slide 9 text

• ґଘؔ܎ͷ޲͖Λἧ͑Δ • Event SourceΛू໿఺ɾ෼ذ఺ͱ͢Δ • ෳࡶԽͷݪҼ͸େ఍σʔλΞΫηεʹ͋Δ • ॻ͖ࠐΈͱࢀরؔ܎ͷෳࡶԽ • σʔλͷॴ༗ؔ܎ • CQRS, Materialized View ෳࡶԽͤ͞ͳ͍ͨΊʹ

Slide 10

Slide 10 text

• ॻ͖ࠐΈͱಡΈࠐΈͰಉ͡σʔλΛѻ͏ඞཁ͸ͳ͍ • ॻ͖ࠐΈͷݪ୯ҐΛߟ͑ɺΞΠςϜʹ·ͱΊΔ͜ͱͰ੔߹ੑΛकΔ • DynamoDB Transactionͷొ৔Ͱ͍ͩͿָʹͳͬͨ • ಡΈࠐΈ͸݁Ռ੔߹Λड͚ೖΕͯޮ཰ͷྑ͍σʔλΛੜ੒͍ͯ͘͠ • Ͱ͖ΔݶΓҰͭͷFunction͕ѻ͏΂͖σʔλΛҰͭͱ͢Δ • Write͸ൺֱత؆୯ • Read͸CQRS, Materialized ViewΛ্ख͘࢖͏ Data Modeling

Slide 11

Slide 11 text

DATA ATOMICITY MicroserviesతͳΠϝʔδͰ͸͜ͷݪ୯Ґ͕ॏཁ σʔλετΞɾςʔϒϧͷ෼͚ํͰ͸ͳ͍ ލ͕͍ͤͨͳΒMaterialized ViewΛ࡞Δ User Profile User Status Name Email Read/Write Search Read/Write

Slide 12

Slide 12 text

Ͳ͏ઃܭ͢Ε͹ྑ͍ͷ͔ʁ ͜͏͍ͬͨ͜ͱΛ্ख͘΍ΔͨΊʹ

Slide 13

Slide 13 text

ඇಉظΛϕʔεʹߟ͑Δ ࢦࣔͨ͠ΒऴΘΔ·ͰԿ΋ͤͣʹ଴ͬͯΔͳΒࣗ෼(MONOLITH)Ͱ΍Ε͹ྑ͍ͷͰ͸ʁ

Slide 14

Slide 14 text

EVENT ROUTING https://www.slideshare.net/AmazonWebServices/ building-massively-parallel-eventdriven- architectures-srv373r1-aws-reinvent-2018

Slide 15

Slide 15 text

• Request <-> Responseͱ͍͏ґଘؔ܎Λ੾Γ཭ͤΔ • ಠཱੑ͕ߴ·Δ • ґଘؔ܎ͷ޲͖͕ἧ͑΍͘͢ͳΔ • εϧʔϓοτΛίϯτϩʔϧ͠΍͘͢ͳΔ • ݁Ռతʹอकੑɾӡ༻ੑ͕ߴ·Δ ඇಉظॲཧͷԿ͕خ͍͔͠

Slide 16

Slide 16 text

• ͭ·ΔॴΤϥʔϋϯυϦϯά • ϦτϥΠՄೳͳΤϥʔ͸ϦτϥΠ͢Δ • ϦτϥΠ͠΍͍͢ͷ͸ඇಉظͷར఺Ͱ͸͋Δ • ϦτϥΠͰ͖ͳ͍ΤϥʔΛͲ͏͢Δʁʁ • ͋ͱϞχλϦϯάɾτϨʔγϯά • ඞཁͳ৘ใ͸ू໿͢Δ • ࠓ೔͸จ຺ζϨΔͷͰ͓·͚ʢ͕࣌ؒ͋ͬͨΒʣ ඇಉظॲཧʹ͓͚Δෆ҆

Slide 17

Slide 17 text

DEMO https://github.com/marcy-terui/jawsdays-2019-demo

Slide 18

Slide 18 text

ࠓ·Ͱᶃ ಉظAPIͰαʔϏε෼ׂ ͭΒ͍ ஫จॲཧ ܾࡁαʔϏε ࡏݿαʔϏε ϝʔϧαʔϏε

Slide 19

Slide 19 text

ࠓ·Ͱᶄ ඇಉظ + ϙʔϦϯάͰؤுΔ ۀ຿ϩδοΫ͸γϯϓϧʹͳΔ൓໘ΞʔΩςΫνϟ͕ෳࡶ ஫จॲཧ ܾࡁαʔϏε ࡏݿαʔϏε ϝʔϧαʔϏε ݁ՌΛू໿ ݁Ռ֬ೝ

Slide 20

Slide 20 text

͜Ε͔Β ཧ૝తʹγϯϓϧͳඇಉظॲཧʹΑΔ αʔϏε෼ׂ ݁ՌΛͦΕͧΕ͕ ௚઀ΫϥΠΞϯτ΁ฦ͢

Slide 21

Slide 21 text

WebSocket API Gateway͸ ͨͩͷManaged WebSocket EndpointͰ͸ͳ͍

Slide 22

Slide 22 text

• ઀ଓʹରͯ͠ҰҙͷConnection ID͕ৼΒΕΔ • ͜ͷIDΛ࢖ͬͯ؅ཧAPIʹσʔλΛ౤͛Δͱ
 Ͳ͔͜ΒͰ΋೚ҙͷΫϥΠΞϯτʹσʔλΛ౤͛ΒΕΔ • ඇಉظͷEvent࿈ܞͰConnection IDΛҾ͖ճͤ͹
 ్தͰམͪͯ΋ClientʹΤϥʔΛฦͤΔ WebSocket API Gateway

Slide 23

Slide 23 text

Τϥʔॲཧ͚ͩ͡Όͳ͍

Slide 24

Slide 24 text

͜͏͍͏ͷ΋ ෳ਺ͷαʔϏε͔ΒσʔλΛ ͔͖ूΊͯ͘Δ΍ʔͭ

Slide 25

Slide 25 text

͜͏Ͱ͖Δ ͦΕͧΕͷαʔϏε͔Β ௚઀σʔλΛฦͤ͞Δ

Slide 26

Slide 26 text

͞ΒʹAppSyncΛՃ͑Δͱ

Slide 27

Slide 27 text

࡞Εͦ͏ͳؾ͕͢Δ ཧ૝తͳEvent Sourcing, CQRSͳ Microservices Architecture ΫϥΠΞϯτ΁݁ՌΛฦ͢ॴ͸লུ ʢਤ͕ෳࡶʹͳΔͷͰʣ

Slide 28

Slide 28 text

• Lambda͔Β࢖͍ͮΒ͍ • AmplifyͷAppSync ClientͷServer Side޲͚ʢͱଞݴޠ൛ʣ΄͍͠ • ೝূΛUser Pool΍OIDCʢͱҰԠAPI Keyʣʹͯ͠΋
 Lambda͔Β͸IAMͰೝূͤͯ͞΄͍͠ • Amplify CLI͔ΒDynamoDB Table࡞Δͱςʔϒϧ໊͕ಛఆͰ͖ͳ͍ • AppSync௨ͤͬͯ͜ͱͳΜͩΖ͏͚ͲͦΕͳΒLambda͔Βʢ͈́ • DynamoDBͷมߋΛࣗಈͰΩϟϓνϟͯ͠SubscriptionൃՐͯ͠΄͍͠ Ͱ΋AppSyncૉఢ͚ͩͲͪΐͬͱ଍Γͳ͍

Slide 29

Slide 29 text

ϞχλϦϯάɾτϨʔγϯά(͓·͚)

Slide 30

Slide 30 text

• ࣮ࡍʹ໰୊͕ى͖ͨ(ى͖ͦ͏)͜ͱΛ؂ࢹ͢Δ • Τϥʔͷൃੜ΍஗ԆΛ؂ࢹ͢Δ • API Gateway: Latency, 5XX Response • Lambda: Duration, Errors, Throttling, DeadLetterErrors • DynamoDB: Consumed Capacity, Throttling, Latency, Errors
 •Ұ൪େ੾ͳͷ͸ΞϓϦέʔγϣϯͷϩά ϞχλϦϯά

Slide 31

Slide 31 text

• DeadLetterErrors • ͿͬͪΌ͚LambdaͷىಈError͸ى͖Δ࣌͸ͪΐ͍ͪΐ͍ى͖Δ • ࠶࣮ߦͰ্ख͘ݴͬͯΔέʔε͕΄ͱΜͲ • ࠶࣮ߦ΋ࣦഊͯ͠औΓ͜΅ͨ͠Error͸͜ΕΛݟͳ͍ͱ෼͔Βͳ͍(ཁઃఆ) • Throttling • SDK͸Throttlingͯ͠΋಺෦Ͱউखʹ࠶࣮ߦ͢Δ • Τϥʔ͕ى͖ͯͳ͍͔ΒThrottling͕ى͖ͯͳ͍ͱ͸ݶΒͳ͍ • ͜ΕΛݟΔͱൃੜঢ়گ͕෼͔ΔˠCapacity௥Ճ ؂ࢹ߲໨ྫ

Slide 32

Slide 32 text

• ෼ࢄͨ͠FaaS؀ڥͰ͸͍͔ʹू໿ͯ͠ޮ཰Α͘ݟΒΕΔΑ͏ʹ͢Δ͔͕େࣄ • ·ͣू໿͢Δͷ͸େલఏ • CloudWatch Logs͸ͨͩͷόοΫΞοϓ • Kinesis Firehose -> Elasticsearch • Datadog LogsΦεεϝ • https://github.com/marcy-terui/ddlogs • Trace IDͷड͚౉͠ํΛܾΊͯԣ۲ͰݕࡧͰ͖ΔΑ͏ʹ͢Δ τϨʔγϯά

Slide 33

Slide 33 text

LOGS WITH TRACE ID Datadog Logsͷ࣮ࡍͷը໘Ͱ͢

Slide 34

Slide 34 text

• Serverless͸Event Drivenͱ૬ੑ͕ྑ͍ • ඇಉظओମʹઃܭ͢Δ͜ͱͰґଘੑͱಠཱੑΛߴΊΒΕΔ • ඇಉظॲཧΛ্ख͘੔ཧ͢Δͷʹ΋Event Drivenͱ͍͏ߟ͑ํ͕༗ޮ • Serverlessͳඇಉظॲཧʹ͓͚Δෆ҆ཁૉ͸෷১͞Εͨ • WebSocket API Gateway͸
 ͨͩͷManaged WebSocket EndpointͰ͸ͳ͍ • AppSync͸ະདྷʢ͋ͱ΋͏ͪΐͬͱɾɾɾʂʣ • ཧ૝ͷΞʔΩςΫνϟ΁ͷಓ͕ݟ͖͑ͯͨ SUMMARY

Slide 35

Slide 35 text

2019೥͸SERVERLESSͷ೥ͩʂʂ THANKS!!