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

サーバーレス開発をより豊富にするAppSyncのUse caseのご紹介 - AKIBA.AW...

Taewoo Kim
January 15, 2020

サーバーレス開発をより豊富にするAppSyncのUse caseのご紹介 - AKIBA.AWS #15

Akiba.awsというクラスメソッド株式会社のAWS勉強会で登壇しました。

https://dev.classmethod.jp/cloud/aws/appsync-for-real…ion-akiba-aws-15/

Taewoo Kim

January 15, 2020
Tweet

More Decks by Taewoo Kim

Other Decks in Programming

Transcript

  1. ࣗݾ঺հ • Taewoo KimʢΩϜ ς΢ʣɺؖࠃਓͰ͢ • AWSࣄۀຊ෦ίϯαϧςΟϯά෦ॴଐɺ2019೥6݄ೖࣾ • ओʹαʔόʔϨεɺML /

    DLɺΧΦεΤϯδχΞϦϯά౳ʹڵຯ͕ ਂ͍ • ΞϓϦ։ൃɺ΢Σϒ։ൃɺػցֶश։ൃ౳ͷόοΫάϥ΢ϯυ • ೔ຊޠμϝͳͷʹ೔ຊޠͰొஃਃ͠ࠐΜͰΈΔ͜ͱ͕झຯ 2
  2. αʔόʔϨεͰͷϦΞϧλΠϜ௨৴͸ʁ • Ұൠతʹ͸ WebSocket ΍ PubSub • LambdaࣗମͰ͸྆ํͰ͖ͳ͍ • API

    Gateway ͷ websocket αϙʔτ • Ͱ΋ɺ௨৴ͷͨΊσʔλετϥΫνϟʔΛܾΊͳ͖Ό͍͚ͳ͍ • ετϥΫδϟʔʹΑͬͯσʔλόϦσʔγϣϯ΋ඞཁʹͳΔ • όοΫΤϯυଆͱϑϩϯτΤϯυଆͷ྆ํ։ൃ͕ඞཁ 10
  3. DynamoDB Streams → Lambda • యܕతͳαʔόʔϨεετϦʔϛϯάߏ੒ • DynamoDB Streams ͔Β

    Lambda ΛτϦΨʔ͢Δ͚ͩͰɺ௒؆୯ʹετϦʔϜͷ ύΠϓϥΠϯͷߏங͕Ͱ͖Δ • εέʔϥϒϧɾϦϥΠΞϒϧɾඅ༻తʹ͍҆ • DynamoDB Streams ଆ͔Β Lambda Ҏ֎ͷଞͷαʔϏεʹ࿈ܞ͢Δ͜ͱ΋Ͱ͖Δ • ݫີͳϦΞϧλΠϜཁ͕݅͋Δ৔߹͸ Kinesis ͕͓͢͢Ί 18
  4. RDS → DMS → Kinesis → Lambda • RDSΛ࢖ͬͨ৔߹Ͱ΋ετϦʔϛϯά͕Ͱ͖Δ •

    DMS͸ιʔεଆͷΠϯελϯεͷύϑΥʔϚϯεʹ΄΅ӨڹΛ༩͑ͳ͍ • Kinesis Data Streams ͸ γϟʔυ਺Λద੾ʹίϯτϩʔϧ͢ΔεΩϧ͕ඞཁ • Kinesis ଆ͔Β Lambda Ҏ֎ͷଞͷαʔϏεʹ࿈ܞ͢Δ͜ͱ΋Ͱ͖Δ • DB (MySQL, PostgreSQL ౳) ͔Β௚઀ Lambda Λݺͼग़͢͜ͱ΋Ͱ͖Δ 20
  5. SQS → Lambda ౳ • SQS ͔Β Lambda ʹܨ͕Δύλʔϯ •

    Kinesis ͔Β Lambda ʹܨ͕Δύλʔϯ • API Gateway ͔Β Lambda ʹܨ͕Δύλʔϯ • CloudWatch Alarms ͔Β Lambda ʹܨ͕Δύλʔϯ • CloudWatch Events ͔Β Lambda ʹܨ͕Δύλʔϯ 22
  6. ஫จαʔϏε • API Gateway → Lambda → DynamoDB ͷߏ੒ •

    ஫จαʔϏεͰͷτϥϯβΫγϣϯ͸ߟྀର৅͔Β֎͢
 → ͍͔ͭผͷػձʹొஃ͍͖ͤͯͨͩ͞·͢ʢসʣ • Ұ൪ଟ͘࢖ΘΕΔAPIόοΫΤϯυͷͨΊͷαʔόʔϨεߏஙύλʔϯ 29
  7. ϦΞϧλΠϜ௨৴ͷͨΊͷAppSync • AppSync ߏங࣌ʹ͸ Serverless Framework ͕͓͢͢Ί • Subscription ͷͨΊͷ

    schema Λ௥Ճ͢Δ͚ͩͰΫϥΠΞϯτଆͰ Subscription ͕ Ͱ͖ΔɻʢόοΫΤϯυଆͷ޻਺͸θϩʣ • ඞཁͳΞΫγϣϯ͸ Mutation ͱ Subscription ͚ͩͳͷͰ͕͢ɺQuery Λొ࿥͍ͯ͠ ͳ͚Ε͹ GraphQL schema ΤϥʔʹͳͬͪΌ͏ʢgetOrderΛαΫοͱ࡞੒͠·ͨ͠) • Mutation͢ΔͨΊͷDynamoDBΛσʔλιʔεͱͯ͠࡞ͬͯɺTTL (Time-To-Live) Λ ઃఆ͢ΔʢexpiresAt Λ AWSTimestamp λΠϓͰએݴ͢Δʣ 32
  8. DynamoDB Streams → Lambda • DynamoDB Streams ͸࠷େ24࣌ؒͷσʔλอଘɺσʔλมߋͷॱ൪͕อূͰ͖ ΔαʔϏε •

    ΑΓݫີͳSLAཁ͕݅͋Ε͹ɺҰ୴Lambda͔ΒKinesis Data Streamsʹ౤͛ͯ ͔ͦ͜Β·ͨLambdaΛτϦΨʔͯ͠ॲཧ͢ΔʢͱࢥΘΕΔ͔΋஌Ε·ͤΜ͕ɺ ϦΞϧλΠϜཁ݅ͳͷͰɺ24࣌ؒΛա͗ͪΌͬͨΒ΋͏ϦΞϧλΠϜͰ͸ͳ͍ʣ • ฒྻ౓Λ্͛ΔͨΊʹ͸όοναΠζΛίϯτϩʔϧ͢Δ͜ͱ΋Ͱ͖Δ 35
  9. Lambda → AppSync • ຊ൪༻ͰϦϦʔζ͞Εͨ AppSync Client SDK ͸ javascript

    ༻ͷΈ • ͦͷͨΊ AppSync Λݺͼग़͢ Lambda ؔ਺ͷίʔυ࡞੒͸ TypeScript ͋Δ͍͸ Javascript Ͱ • AppSync Client SDK Λ Lambda ্Ͱಈ͔ͤΔͨΊʹ͸͍͔ͭ͘஫ҙ͢Δ͜ͱ͕͋Δ • ismorphic-fetch ΛΠϯϙʔτ͢Δ͜ͱ • disableOffline Λ true ʹ͢Δ͜ͱ 36
  10. AppSync WebSockets ࢓༷ 40 MQTT over WebSockets WebSockets (NEW) Payload

    Size 128Kb 240Kb CloudWatch Metrics X O Selection Set Filtering X O Enhanced Connection Rates X O Enhanced Broadcast Rates X O
  11. 42

  12. AppSync ஌Γ͍ͨʂͱࢥͬͨΒ • AWS࠶ೖ໳ϒϩάϦϨʔAppSyncฤ
 https://dev.classmethod.jp/cloud/aws/relay-re-introduction-2019-appsync/ • ʲϨϙʔτʳServerless/AppSync ʹΑΔϞόΠϧ։ൃͷࠓ #AWSSummit
 https://dev.classmethod.jp/etc/awssummit-appsync-mobile/

    • AWS AppSyncͰෳ਺ͷೝূϞʔυ͕αϙʔτ͞Ε·ͨ͠ʂ
 https://dev.classmethod.jp/cloud/aws/appsync-updates-19-5-15/ • [AWS AppSync] Lambda͔ΒGraphQLͷΫΤϦΛૹͬͯΈΔ
 https://dev.classmethod.jp/cloud/aws-appsync-lambda-mutation/ 44