Amplify Meetup #01

Amplify Meetup #01

AWS Amplify Meetup #01 で LT 発表したスライドです。

Acb6390b6c4b5192f40e10601b63dafc?s=128

Taewoo Kim

July 31, 2020
Tweet

Transcript

  1. AmplifyͷAPIػೳΛ࢖͏ࡍͷTips Amplify Meetup #01 LT ηογϣϯ #05

  2. ࣗݾ঺հ • Taewoo Kim (ΩϜς΢ʣɺؖࠃਓͰ͢ʂ • AWS Solutions Architect at

    • 2020 APN AWS Top Engineers ʹ౰બ • ޷͖ͳAWSαʔϏε͸ AWS AppSync ͱ AWS Amplify
  3. ຊηογϣϯͷର৅ • AWS Amplify API ػೳΛҰ౓Ͱ΋࣮ࡍʹࢼͯ͠Έͨํ • AWS Amplify νϡʔτϦΞϧΛΫϦΞʔͨ͠ํ

    • AWS Amplify Λຊ൪؀ڥͰಋೖ͍ͨ͠ͱࢥ͏ํ
  4. ૣ଎Ͱ͕͢

  5. օ͞Μ͸ Amplifyͳͥ࢖ͬͯ·͔͢ʁ

  6. AmplifyΛ࢖͏ཧ༝ • ָ͍͔͠Β • όοΫΤϯυଆͷ࣮૷΋ศརͩ͠ɺϑϩϯτଆͷ࣮૷΋ָʹͳΔ͔Β •ϏδωεΞΠσΟΞΛ۩ମԽͨ͠ॳظMVPΛ ര଎Ͱ࣮૷Ͱ͖Δ͔Βʂ

  7. AmplifyΛ࢖͏ཧ༝ • ָ͍͔͠Β • όοΫΤϯυଆͷ࣮૷΋ศརͩ͠ɺϑϩϯτଆͷ࣮૷΋ָʹͳΔ͔Β •ϏδωεΞΠσΟΞΛ۩ମԽͨ͠ॳظMVPΛ ര଎Ͱ࣮૷Ͱ͖Δ͔Βʂ

  8. AmplifyΛ࢖͏ཧ༝ • ָ͍͔͠Β • όοΫΤϯυଆͷ࣮૷΋ศརͩ͠ɺϑϩϯτଆͷ࣮૷΋ָʹͳΔ͔Β •ϏδωεΞΠσΟΞΛ۩ମԽͨ͠ॳظMVPΛ ര଎Ͱ࣮૷Ͱ͖Δ͔Βʂ ݸਓతʹ͸͜ͷཧ༝(↑)͕Ұ൪େࣄͩͱࢥ͍·͢

  9. AmplifyΛ࢖͏ཧ༝ • ָ͍͔͠Β • όοΫΤϯυଆͷ࣮૷΋ศརͩ͠ɺϑϩϯτଆͷ࣮૷΋ָʹͳΔ͔Β •ϏδωεΞΠσΟΞΛ۩ମԽͨ͠ॳظMVPΛ ര଎Ͱ࣮૷Ͱ͖Δ͔Βʂ ݸਓతʹ͸͜ͷཧ༝(↑)͕Ұ൪େࣄͩͱࢥ͍·͢ MVP࣮૷ͰAmplify͕Ұ൪໾ʹཱͭػೳ͸ API

  10. Amplify API Λ࢖͍࢝Ίͨࡍʹ ඞͣ஌͓͍ͬͯͨํ͕ྑ͍ ϊ΢ϋ΢Λڞ༗͠·͢

  11. όοΫΤϯυϓϩδΣΫτ͸ ϑϩϯτ͔Β෼཭ͨ͠ํ͕ྑ͍

  12. Ϟνϕʔγϣϯ • Amplify ެࣜυΩϡϝϯτΛݟΔͱɺϑϩϯτΤϯυϓϩδΣΫτͰ όοΫΤϯυϓϩδΣΫτΛҰॹʹ؅ཧ͢Δํ๏Λ঺հ͍ͯ͠·͢ɻ • ͭ·ΓɺϑϩϯτΤϯυϓϩδΣΫτͷதʹɺamplify/ ͱ͍͏ϑΥ ϧμʔ͕ଘࡏ͢Δͱ͍͏ܗʹͳΓ·͢ɻ •

    Ͱ͕͢ɺෳ਺ͷϓϩδΣΫτͰߏ੒͞Εͨ৔߹͸ɺ֤ϓϩδΣΫτʹ όοΫΤϯυઃఆΛೖΕΔͷ͕ਖ਼͍͠ͷ͔ɺͱ͍͏೰Έ͕͔ͪͱࢥ͍ ·͢ɻ
  13. Ϟνϕʔγϣϯ • Amplify ެࣜυΩϡϝϯτΛݟΔͱɺϑϩϯτϓϩδΣΫτͰόο ΫΤϯυϓϩδΣΫτΛҰॹʹ؅ཧ͢Δํ๏Λ঺հ͍ͯ͠·͢ɻ • ͭ·ΓɺϑϩϯτΤϯυϓϩδΣΫτͷதʹɺamplify/ ͱ͍͏ ϑΥϧμʔ͕ଘࡏ͢Δͱ͍͏ܗʹͳΓ·͢ɻ •

    Ͱ͕͢ɺෳ਺ͷϓϩδΣΫτͰߏ੒͞Εͨ৔߹͸ɺ֤ϓϩδΣΫτ ʹόοΫΤϯυઃఆΛೖΕΔͷ͕ਖ਼͍͠ͷ͔ɺͱ͍͏೰Έ͕͔ͪͱ ࢥ͍·͢ɻ ͏Μ….. όοΫΤϯυ͸ผ్Ͱ؅ཧ͠·͠ΐ͏ʂ
  14. όοΫΤϯυϓϩδΣΫτΛ෼཭͢Δ͜ͱͰಘΔϝϦοτ 1. όοΫΤϯυͱϑϩϯτͷSeparation of ConcernΛ࣮ݱ͠΍͍͢ 2. ෳ਺ͷϝϯόʔ͕Ұॹʹ࡞ۀ͠΍͘͢ͳΔ 3. কདྷతʹόοΫΤϯυϓϩδΣΫτΛϚΠάϨʔγϣϯ͢Δʹ΋ ΋ͬͱָʹͳΔ

  15. όοΫΤϯυͱϑϩϯτΤϯυ͸෼཭͠·͠ΐ͏ʂ https://dev.classmethod.jp/articles/amplify-tips-series-1/

  16. GraphQL Schemaͷ type ʹ @model Λ෇͚ͳ͔ͬͨ࣌ͷ ஫ҙ͢΂͖͜ͱ

  17. GraphQL Schemaͷ type ʹ @model Λ෇͚ͳ͔ͬͨ࣌ͷ஫ҙ͢΂͖͜ͱ https://dev.classmethod.jp/articles/amplify-tips-series-3/

  18. ͦ΋ͦ΋ @model Λͳ͚ͥͭͳ͍ΜͰ͔͢ʁʁ @model σΟϨΫςΟϒΛ͚ͭΔ͜ͱͷϝϦοτ 1. σʔλιʔε(DynamoDB) Λੜ੒͠ɺ AppSync ͱ࿈ܞͯ͘͠ΕΔɻ

    2. Create/Read/Update/Delete/List ΦϖϨʔγϣϯΛಈ࡞ͤ͞ΔͨΊͷ Query ΍ Mutation ͱɺͦΕͧΕ͕ඞཁͱ͢Δ input ౳ͷλΠϓΛࣗಈͰੜ੒ͯ͘͠ΕΔɻ 3. ੜ੒͞Εͨ Query ΍ MutationɺλΠϓϑΟʔϧυresolver౳ͷͨΊͷ Request/Response Mapping TemplatesΛࣗಈͰੜ੒ͯ͘͠ΕΔɻ 4. ͜ͷΑ͏ʹੜ੒͞Εͨ CRUD(L) API ΛɺΫϥΠΞϯτιʔείʔυଆͰ΋ΞΫηεͰ͖Δ API ϥΠϒϥϦʔΛࣗಈͰੜ੒ͯ͘͠ΕΔɻ (amplify codegen)
  19. @connection ͱ depth ͋ͨΓ • యܕతͳΞϓϦ͸σʔλεΩϚʔͰඞཁͳλΠϓ਺͕਺ेʙ਺ඦ • λΠϓ͝ͱͷؔ܎ੑΛ࡞ΔͨΊʹ @connection ͕ඞཁ

    • codegen ͷ depth ΛݮΒ͢··ҡ࣋͢ΔͨΊɺˏmodel Λফ͢ • ݁Ռతʹ @connection ແ͠Ͱ΋௚઀σʔλʹΞΫηεՄೳ
  20. @model Λ͚ͭͳ͔ͬͨࡍͷ஫ҙ఺͸ʁ • @model Λ͚ͭͳ͍ͱɺͦͷ DynamoDB ςʔϒϧ͕ੜ੒͞Εͳ͍ • ଞͷ type

    ͷςʔϒϧʹ JSON ܗࣜͰอଘ͞ΕΔ • DynamoDB ͸ JSON ಺෦ͷϑΟʔϧυʹରͯ͠ͷ Query ͸αϙʔτ͠ ͯ͘Ε͍ͯͳ͍
  21. @model Λ͚ͭͳ͔ͬͨࡍͷ஫ҙ఺͸ʁ • ͳͷͰɺdepth ͋ͨΓͷ೰ΈͰ ˏmodel Λ͚ͭͨ͘ͳ͍ͳΒ͹ɺ
 depth ઃఆ͸ؾʹͤͣɺ௚઀ query

    ίʔυΛ࡞੒͢Ε͹ྑ͍
 
 
 
 
 
 
 
 
 
 https://dev.classmethod.jp/articles/amplify-tips-series-4/
  22. Custom Resolver ͷ໋໊نଇΛ ઌʹܾΊΑ͏

  23. Custom Resolver ͕ඞཁͷ৔߹ͬͯʁ • ECαΠτͷ஫จAPIɿ
 - ܾࡁαʔϏεͱ஫จαʔϏεͷ࿈ܞ
 - ঎඼৘ใαʔϏεͱσϦόϦʔαʔϏε
 -

    શͯΛ߹ΘͤͯτϥϯβΫγϣϯॲཧ • SNSͷྑ͍Ͷʂɿ
 - ୭͔ྑ͍Ͷʂ͔ͨ͠ʢϢʔβʔςʔϒϧʣ
 - ྑ͍Ͷʂͷτʔλϧ਺
 - ౤ߘσʔλςʔϒϧ
 - શͯ߹ΘͤͯτϥϯβΫγϣϯॲཧ
  24. schema.graphql

  25. custom_resolver.yaml 1 2 3

  26. custom_resolver.yaml

  27. custom_resolver.yaml

  28. custom_resolver.yaml

  29. VTL ϑΝΠϧ Query.myCustomLambdaExecution.req.vtl

  30. Custom Resolver ʹ͍ͭͯͷࢲͷߟ͑ • ϓϩδΣΫτ಺Ͱඞཁͳ Custom Resolver ͕਺ݸఔ౓ͳΒ໰୊ແ͠ • ϓϩδΣΫτ಺Ͱඞཁͳ

    Custom Resolver ͕਺ेݸҎ্ͳΒɺ
 Custom Resolver ͷ؅ཧίετ΍։ൃίετ͕ߴ͘ͳΔ • ΋ͬͱָʹ͢Δʹ͸ Serverless Framework ͷ serverless-appsync- plugin Λར༻ͯ͠ AppSync Λߏங͢Δ
 → amplify codegen ΋Ͱ͖Δ͠ɺcustom resolver ͷ࣮૷΋ָʹͳΔ
 → Ͱ΋ɺAmplify ͷ σΟϨΫςΟϒ͸࢖͑ͳ͍
  31. ϒϩά΋ಡΜͰΈ͍ͯͩ͘͞ :D

  32. https://dev.classmethod.jp/tag/aws-amplify/

  33. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ