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

AWSで Alexaスキル開発をスケール&ブーストする / awscommunityday-k...

AWSで Alexaスキル開発をスケール&ブーストする / awscommunityday-kanazawa-2019

AWS Community Day Kanazawa
2019年11月20日(水) ITビジネスプラザ武蔵
https://awscommunityday2019.jaws-ug.jp/#timetable

Hidetaka Okamoto

November 20, 2019
Tweet

More Decks by Hidetaka Okamoto

Other Decks in Programming

Transcript

  1. A W S Ͱ A l e x a εΩϧ

    ։ ൃ Λ εέ ʔϧ ˍ ϒʔε τ ͢ Δ A W S C o m m u n i t y D a y K a n a z a w a 2 0 1 9 #jawsug #awscommunityday
  2. H i d e t a k a O k

    a m o t o • Digitalcube Co. Ltd. • Alexa Campions • AWS Samurai 2017 in Japan • ask sdk(Node.js) Core contributor
  3. A g e n d a • AlexaΧελϜεΩϧʹ͓͚ΔLambdaͷ໾ׂ • ҰൠతͳAlexaεΩϧόοΫΤϯυʹ͍ͭͯ

    • BasicͳαʔϏεΛΑΓ࢖͍ࠐΉ • AWS ServiceͰΑΓϦονͳମݧΛ࡞Δ
  4. Ұ ൠ త ͳ Ξ ϓ Ϧ έ ʔ γ

    ϣ ϯ : Χ ε λϜ εΩϧ
  5. A l e x a εΩϧ ͷ छ ྨ •

    εϚʔτϗʔϜεΩϧɹɹɿεϚʔτϗʔϜ • ϑϥογϡχϡʔεεΩϧɿFeedهࣄಡΈ্͛ • ϏσΦεΩϧɹɹɹɹɹɹɿಈը࠶ੜ • ΧελϜεΩϧɹɹɹɹɹɿͦΕҎ֎ʢήʔϜ / Util / ങ͍෺ / etcʣ • Music Skillɹɹɹɹ(೔ຊޠະରԠ)ɹɹ ɹɹ ɿԻָͷ࠶ੜ • Baby Activity Skill (೔ຊޠະରԠ) ɹɹɹɹ ɿ͓Ήͭͷަ׵ / ৯ࣄ / ਭ຾ / ମॏͷه࿥ͳͲ • Meetingsɹɹɹɹ(೔ຊޠະରԠ)ɹɹɹɹ ɿAlexa For BussinessΛར༻ͨ͠ձٞࣨ༧໿
  6. A g e n d a • AlexaΧελϜεΩϧʹ͓͚ΔLambdaͷ໾ׂ • ҰൠతͳAlexaεΩϧόοΫΤϯυʹ͍ͭͯ

    • BasicͳαʔϏεΛΑΓ࢖͍ࠐΉ • AWS ServiceͰΑΓϦονͳମݧΛ࡞Δ
  7. A l e x a Χ ελϜ εΩϧ ͕ ཪ

    Ͱ ΍ ͬͯ ͍ Δ ͜ ͱ • Ի੠ΛςΩετʹม׵ • ςΩετΛࣗવݴޠॲཧͯ͠JSONʹม׵ • Lambda ͷ Invoke / HTTPS API ΁ͷ POSTϦΫΤετ • Lambda·ͨ͸API͕JSONΛreturn͢Δ • ϨεϙϯεͷJSONΛԻ੠ʹม׵
  8. A l e x a Χ ελϜ εΩϧ ։ ൃ

    ऀ ͕ ΍ Δ ΂ ͖ ͜ ͱ • Ի੠ΛςΩετʹม׵ • ςΩετΛࣗવݴޠॲཧͯ͠JSONʹม׵ • Lambda ͷ Invoke / HTTPS API ΁ͷ POSTϦΫΤετ • Lambda·ͨ͸API͕JSONΛreturn͢Δ • ϨεϙϯεͷJSONΛԻ੠ʹม׵
  9. A l e x a ͷ S e r v

    i c e ͕ ΍ ͬͯ͘ Ε Δ ͜ ͱ • Ի੠ΛςΩετʹม׵ • ςΩετΛࣗવݴޠॲཧͯ͠JSONʹม׵ • Lambda ͷ Invoke / HTTPS API ΁ͷ POSTϦΫΤετ • Lambda·ͨ͸API͕JSONΛreturn͢Δ • ϨεϙϯεͷJSONΛԻ੠ʹม׵
  10. A l e x a ͷ Χ ελϜ εΩϧ ։

    ൃ ≒ We b h o o k A P I ࡞ ੒ • Alexa Service͕౤͛ͯ͘ΔJSON͔ΒɺϦΫΤετ಺༰Λ೺Ѳ • Alexa͕TTS (Text To Speech)͢ΔͨΊͷJSONΛreturn͢Δ • entrypoint͸̍ͭͷΈɺJSONͷσʔλͰ಺༰Λࣝผ͢Δ • ask sdk(Node.js / Python / Java)Λ࢖͏͜ͱͰɺ؆୯ʹ࣮૷Ͱ͖Δ • ܕఆٛ΋GitHubʹެ։͞Ε͍ͯΔͨΊɺൺֱత໎͍ʹ͍͘
  11. Χ ελϜ εΩϧ ʹ ͓ ͚Δ ֎ ෦ α ʔ

    Ϗ ε ͱ ͷ ࿈ ܞ • AlexaεΩϧͷઃఆʹͯ֎෦αʔϏεͱͷ࿈ܞ͕Մೳ • ΞΧ΢ϯτͷϦϯΫ͸OAuth2ͷΈ • Ϣʔβʔ͸AlexaΞϓϦ͔Β࿈ܞઌαʔϏεͱAlexaͷ࿈ܞΛઃఆ • ΞΧ΢ϯτσʔλʢॅॴ / ϦϚΠϯμʔ / Amazon PayʣͳͲ΋ར༻Մ • ͨͩ͠ΦϓτΠϯܗࣜͳͷͰɺ໌ࣔతʹڐՄΛಘΔඞཁ͋Γ
  12. A l e x a ͸ L a m b

    d a ΍ ܕ ෇ ͖ ݴ ޠ ೖ ໳ ʹ Α ͍ ʢ ͔ ΋ ʣ • جຊతͳϢʔεέʔεͰ͋Ε͹ɺ΄΅Input / Output͕ݻఆ • API࿈ܞͳͲΛ͠ͳ͚Ε͹΄΅ดͨ͡ܗͰ࣮૷Ͱ͖Δ • LambdaͷGUIʹαϯϓϧInput͕ϓϦηοτ͞Ε͍ͯͯςετ΋؆୯ • πʔϧ΍Lambdaͷೖ໳ͱͯ͠AlexaεΩϧΛ͓୊ʹͯ͠ΈΑ͏
  13. A g e n d a • AlexaΧελϜεΩϧʹ͓͚ΔLambdaͷ໾ׂ • ҰൠతͳAlexaεΩϧόοΫΤϯυʹ͍ͭͯ

    • BasicͳαʔϏεΛΑΓ࢖͍ࠐΉ • AWS ServiceͰΑΓϦονͳମݧΛ࡞Δ
  14. Ұ ൠ త ͳ A l e x a εΩϧό

    ο Ϋ Τ ϯ υ • LambdaͰॲཧ • ϝσΟΞϑΝΠϧ͸S3 • DB͸DynamoDB • ϩά͸CloudWatch • ΞΫηε؅ཧ͸IAM
  15. A S K C L I + ख ಈ ߋ

    ৽ ͕ A l e x a ଆ ͷ ఆ ੴ • npm i -g ask-cliͰΠϯετʔϧ • ask delpoyͰAlexaεΩϧ + AWSϦιʔεΛσϓϩΠ • Lambda / IAM Role / CloudWatchͷϦιʔε͕࡞ΒΕΔ • IAMͷPolicy͸AWSLambdaBasicExecutionRole • DynamoDB / S3ͳͲΛ࢖͏৔߹͸खಈͰIAM Policyͷ௥Ճ͕ඞཁ
  16. A S K C L I ͷ Α ͍ ͱ

    ͜ Ζ • AlexaͷεΩϧ৘ใͱLambdaͷιʔεΛ·ͱΊͯ؅ཧͰ͖Δ • hook͕͋ΔͷͰɺdeployલʹTypeScriptͷϏϧυ΋࣮ߦͰ͖Δ • GitHubͷαϯϓϧίʔυΛͦͷ··࢖͑Δ • AWSͷ͜ͱΛ͋·Γҙࣝͤͣʹ࢖͑Δ
  17. A S K C L I ͷ ͭ Β ͍

    ͱ ͜ Ζ ߏ੒؅ཧͯ͘͠ΕΔΘ͚Ͱ͸ͳ͍
  18. ࡞ ͬ ͨ εΩϧ ਺ ͷ L a m b

    d a Λ ख ಈ Ͱ ߋ ৽ ͠ ͳ ͍ ͱ ͍ ͚ ͳ ͍ #jawsug #awscommunityday
  19. AW S Ϣ ʔ β ʔ ͔ Β Έ ͨ

    A S K C L I • AWSΛҙࣝͤͣʹεΩϧΛ࡞ΕΔCLIπʔϧ • ҙࣝͯ͠࢖͍͍ͨ੎ʹ͸ਖ਼௚෺଍Γͳ͍ • IAMͷϙϦγʔ؅ཧ΋खಈͳͷͰɺґଘϦιʔε͕૿͑ΔͱͭΒ͍ • Serverless FW / SAM / CDKͱ૊Έ߹ΘͤΔͷ͕ݱঢ়ϕλʔ
  20. C l o u d F o r m a

    t i o n ࢖ ͑Δ ৽ όʔ δϣ ϯ C L I ʢ b e t a ʣ
  21. C l o u d F o r m a

    t i o n ࢖ ͑Δ ৽ όʔ δϣ ϯ C L I ʢ b e t a ʣ $ npm i -g ask-cli-x 
 $ askx init $ askx new $ askx deploy
  22. A g e n d a • AlexaΧελϜεΩϧʹ͓͚ΔLambdaͷ໾ׂ • ҰൠతͳAlexaεΩϧόοΫΤϯυʹ͍ͭͯ

    • BasicͳαʔϏεΛΑΓ࢖͍ࠐΉ • AWS ServiceͰΑΓϦονͳମݧΛ࡞Δ
  23. ͦ ΋ ͦ ΋ ͳ ͥ A l e x

    a εΩϧ ։ ൃ Ͱ A W S Λ ֮ ͑Δ ඞ ཁ ͕ ͋ Δ ͷ ͔ʁ #jawsug #awscommunityday
  24. AW S ͸ A l e x a εΩϧ ։

    ൃ Λ ϒʔε τ ͢ Δ • ASK CLIΛ࢖͑͹AWSΛҙࣝͤͣʹ։ൃͰ͖Δ • ҙ͍ࣝͯ͠ͳ͍͕ɺAWS͸ͦ͜ʹ͋Δ • ҙࣝͤͣʹ࢖͑Δൣғͷػೳ͔͠࢖͍͑ͯͳ͍ • AWSΛཧղ͢Δ͜ͱͰɺΑΓΑ͍DX(Developer Experience)ʹ
  25. AW S Ͱ Ͱ ͖ Δ ͜ ͱ ͷ Ұ

    ྫ • ઐ༻ͷIAMϙϦγʔΛ࡞੒ͯ͠ݖݶ؅ཧΛΘ͔Γ΍͘͢͢Δ • CloudFormationͰߏ੒Λίʔυ؅ཧ • Systems Manager / Secret ManagerͰAPIΩʔ؅ཧ • CodeStarΛ࢖ͬͯΤσΟλ͔ΒCI / CD·ͰҰׅͰηοτΞοϓ
  26. ͤ ͬ ͔ ͘ ͳ ͷ Ͱɺ Ұ ൪ ϚΠφ

    ʔ ͦ ͏ ͳ ΋ ͷ Λ ঺ հ ͠ · ͢ • ઐ༻ͷIAMϙϦγʔΛ࡞੒ͯ͠ݖݶ؅ཧΛΘ͔Γ΍͘͢͢Δ • CloudFormationͰߏ੒Λίʔυ؅ཧ • Systems Manager / Secret ManagerͰAPIΩʔ؅ཧ • CodeStarΛ࢖ͬͯΤσΟλ͔ΒCI / CD·ͰҰׅͰηοτΞοϓ
  27. ج ຊ త ͳ α ʔ Ϗ ε Λ ͠

    ͬ ͔ Γ ࢖ ͍ ࠐ Ή #jawsug #awscommunityday
  28. Ұ ൠ త ͳ A l e x a εΩϧό

    ο Ϋ Τ ϯ υ • LambdaͰॲཧ • ϝσΟΞϑΝΠϧ͸S3 • DB͸DynamoDB • ϩά͸CloudWatch • ΞΫηε؅ཧ͸IAM
  29. ج ຊ త ͳ α ʔ Ϗ ε Λ ࢖

    ͍ ࠐ Ή • ͋͑ͯS3ΛεΩϧͷσʔλϕʔεʹ͢Δͱ͍͏બ୒ࢶ • DynamoDBΛ͔ͬ͠Γ࢖͏ • Lambdaίʔϧυελʔτରࡦ • ࢖Θͳ͍͚Ͳ࢖͑ΔAmazon Polly
  30. ج ຊ త ͳ α ʔ Ϗ ε Λ ࢖

    ͍ ࠐ Ή • ͋͑ͯS3ΛεΩϧͷσʔλϕʔεʹ͢Δͱ͍͏બ୒ࢶ • DynamoDBΛ͔ͬ͠Γ࢖͏ • Lambdaίʔϧυελʔτରࡦ • ࢖Θͳ͍͚Ͳ࢖͑ΔAmazon Polly
  31. D y n a m o D B o r

    S 3 • σϑΥϧτ͸DynamoDB • ͲͪΒ΋User IDΛΩʔʹɺObjectΛอଘ͢Δܗ • SLA͸΄΅ޡࠩ(S3: 99.9% / DynamoDB: 99.99%) • ແྉ࿮͕ແظݶͳͷ͸DynamoDB( S3͸12ϲ݄ͷΈ ) • ैྔ՝ۚͷ৳ͼํ͸S3ͷ΄͏͕Ժ΍͔( 0.023USD / GB)
  32. S D K ͷ ࢖ ͍ ํ ͩ ͱ D

    y n a m o D B ɹ ɹ ɹ ɹ ɹ ׆ ༻ ͠ ͖ Εͯ ͳ ͍ આ
  33. S D K ͸ M a p ܕ Ͱ શ

    ෦ 1 Ω ʔ ʹ ͍ Εͯ ͠ · ͏ dynamoDBDocumentClient.put({ TableName: 'TableName', Item: { [partitionKey]: userId, [attributesName]: { … } } }).promise() A S K - S D K AW S - S D K
  34. Ϋ Τ Ϧ ͱ ͔ ͠ ͨ ͘ ͳ Δ

    ͱ ɺ ͜ ͏ ͠ ͨ ͍ dynamoDBDocumentClient.put({ TableName: 'TableName', Item: { [partitionKey]: userId, [attributesName]: { … } } }).promise() dynamoDBDocumentClient.put({ TableName: 'TableName', Item: { user_Id: attributesId, last_launched: attributes.last_launched, monthly_score: attributes.monthly_score, reminderTarget: attributes.reminder_target } }).promise() A S K - S D K AW S - S D K
  35. O R Ͱ ͸ ͳ ͘ A N D ͱ

    ͍ ͏ ߟ ͑ ํ • શ݅औಘ͕ۤखͳDynamoDB • ࡉ͔͍ΫΤϦ΍੔߹ੑͷ֬อ͕ۤखͳS3 • AWS-SDKͱڞʹซ༻ͯۤ͠ख෼໺ΛΧόʔ͢Δ • ྫɿΫΤϦ͠ͳ͍σʔλʢىಈճ਺ / ࠷ޙͷηογϣϯͳͲʣ͸S3 • ྫɿτϥϯβΫγϣϯ΍ΫΤϦ͍ͨ͠σʔλ͸DynamoDB
  36. S 3 Λ Ϣ ʔ β ʔ D B ͱ

    ͯ͠ ѻ ͏ ࡍ ͷ T i p s • ask-sdk-dynamodb-persistence-adapter Λ࢖͑͹؆୯ʹಋೖՄೳ • User ID / Device ID / Person ID͸εΩϧຖʹϢχʔΫ • ./ask-user-db/{custom_prefix}/{user_id}ͷΑ͏ͳύεͰϑΝΠϧੜ੒ • prefixΛεΩϧ໊ʹઃఆ͢Δͱɺ̍όέοτʹू໿Ͱ͖Δ
  37. ج ຊ త ͳ α ʔ Ϗ ε Λ ࢖

    ͍ ࠐ Ή • ͋͑ͯS3ΛεΩϧͷσʔλϕʔεʹ͢Δͱ͍͏બ୒ࢶ • Lambdaίʔϧυελʔτରࡦ • ࢖Θͳ͍͚Ͳ࢖͑ΔAmazon Polly
  38. – h t t p s : / / d

    o c s . a w s . a m a z o n . c o m / j a _ j p / l a m b d a / l a t e s t / d g / r u n n i n g - l a m b d a - c o d e . h t m l “ʮϒʔτετϥοϓʯ͕ඞཁͳͨΊɺ Lambda ؔ਺Λݺͼग़ͨ͢ͼʹएׯͷϨΠςϯγʔ͕ൃੜ͠·͢ɻ ௨ৗɺ͜ͷ஗Ԇ͸ Lambda ؔ਺ΛॳΊͯݺͼग़ͨ͠ͱ͖ɺ ·ͨ͸ߋ৽͞Εͨͱ͖ʹൃੜ͠·͢ɻ Lambda ؔ਺Λ࿈ଓͯ͠ݺͼग़͢৔߹ɺ AWS Lambda ͸Ͱ͖ΔݶΓ࣮ߦίϯςΩετΛ࠶ར༻͠·͢ɻ” L a m b d a ʹ ͸ ί ʔ ϧ υ ελ ʔ τ ͕ ͋ Δ
  39. A l e x a Χ ελϜ εΩϧ ʹ ͓

    ͚Δ ί ʔ ϧ υ ελ ʔ τ ର ࡦ ͷ ྫ • serverless-warmup-pluginͳͲͰ΢ΥʔϜΞοϓ • ECS / EKS / ebͳͲͰ࡞ͬͨৗ࣌ՔಇAPIʹ੾Γସ͑Δ • Lambdaू໿Ͱىಈճ਺Λ૿΍͢ • ఘΊΔ
  40. A l e x a Χ ελϜ εΩϧ ʹ ͓

    ͚Δ ί ʔ ϧ υ ελ ʔ τ ର ࡦ ͷ ྫ • serverless-warmup-pluginͳͲͰ΢ΥʔϜΞοϓ • ECS / EKS / ebͳͲͰ࡞ͬͨৗ࣌ՔಇAPIʹ੾Γସ͑Δ • Lambdaू໿Ͱىಈճ਺Λ૿΍͢ • ఘΊΔ
  41. E C S / E K S / e b

    ͳ Ͳ Ͱ ࡞ ͬ ͨ ৗ ࣌ Ք ಇ A P I ʹ ੾ Γ ସ ͑Δ • ৗ࣌Քಇʹ͢Ε͹ίʔϧυελʔτ͸ͳ͘ͳΔ • ExpressͰಈ͔ͨ͢Ίͷadapter͕npmʹ͋Δʢެࣜʣ • ExpressΛಈ͔͢Node.jsͷίϯςφΛՔಇͤ͞Ε͹OK • ৗ࣌Քಇͷ৔߹ɺJavaͷํ͕ૣ͘ͳΔઆ΋ɾɾɾ
  42. A l e x a Χ ελϜ εΩϧ ʹ ͓

    ͚Δ ί ʔ ϧ υ ελ ʔ τ ର ࡦ ͷ ྫ • serverless-warmup-pluginͳͲͰ΢ΥʔϜΞοϓ • ECS / EKS / ebͳͲͰ࡞ͬͨৗ࣌ՔಇAPIʹ੾Γସ͑Δ • Lambdaू໿Ͱىಈճ਺Λ૿΍͢ • ఘΊΔ
  43. ̍ ͭ ͷ L a m b d a ʹ

    · ͱ Ί ͯ ͠ · ͏ • ෳ਺ͷεΩϧ͔Β̍ͭͷLambdaΛࢀরͤ͞Δ • ݺͼग़͠ճ਺Λ૿΍ͯ͠ɺίʔϧυελʔτ཰ΛݮΒ͢ • applicationIdΛ࢖ͬͯSkillFactoryΛΑͼΘ͚Ε͹OK • Ξοϓσʔτ / σϓϩΠͰଞͷεΩϧΛյ͢ϦεΫʹ஫ҙ • LambdaͷόʔδϣϯʢΤΠϦΞεʣΛ࢖͍͜ͳͤ͹OK͔΋
  44. ج ຊ త ͳ α ʔ Ϗ ε Λ ࢖

    ͍ ࠐ Ή • ͋͑ͯS3ΛεΩϧͷσʔλϕʔεʹ͢Δͱ͍͏બ୒ࢶ • Lambdaίʔϧυελʔτରࡦ • ࢖Θͳ͍͚Ͳ࢖͑ΔAmazon Polly
  45. A g e n d a • AlexaΧελϜεΩϧʹ͓͚ΔLambdaͷ໾ׂ • ҰൠతͳAlexaεΩϧόοΫΤϯυʹ͍ͭͯ

    • BasicͳαʔϏεΛΑΓ࢖͍ࠐΉ • AWS ServiceͰΑΓϦονͳମݧΛ࡞Δ
  46. ʮ A l e x a ͷ ֎ ʯ Ͱ

    ͷ ମ ݧ ΋ AW S ͳ Β ߏ ங Ͱ ͖ Δ
  47. A l e x a ͱ A l e x

    a ͷ ֎ Λ AW S Ͱ Ϧ ϯ Ϋ ͢ Δ • Alexa͸OAuth2ͰΞΧ΢ϯτϦϯΫʢαʔϏε࿈ܞʣͰ͖Δ • Cognito User Pools͸OAuth2ʹରԠ͍ͯ͠Δ • AWS AmplifyΛ࢖͑͹webΞϓϦͷߏங͕؆୯ʹ • Amplify SDKͰPersonalize΍RekognitionͳͲͱͷ࿈ܞ΋؆୯
  48. AW S ϒ ϩ ά ʹ C o g n

    i t o ࿈ ܞ ͷ ه ࣄ ͋ Γ · ͢ https://aws.amazon.com/jp/blogs/compute/ amazon-cognito-for-alexa-skills-user- management/
  49. · ͱ Ί • AlexaεΩϧ͸AWSͷ஌͕ࣝͳͯ͘΋࡞ΕΔ • ͨͩ͠AWSΛ࢖͍͜ͳ͢͜ͱͰɺΑΓศརʹͳΔ • CI /

    CD / ϞόΠϧ࿈ܞ / ύʔιφϥΠζ etc… • ͋ͳͨͷΞϓϦέʔγϣϯʹVUIͱ͍͏৽͍͠૭ޱΛ૿΍ͤΔ͔΋
  50. A l e x a A W S ϓ ϩ

    Ϟ ʔ γ ϣ ϯ Ϋ Ϩ δ ο τ h t t p s : / / d e v e l o p e r. a m a z o n . c o m / j a / a l e x a - s k i l l s - k i t / a l e x a - a w s - c re d i t s
  51. E C 2 ΍ S 3 ΋ Ϋ ʔϙ ϯ

    ର ৅ h t t p s : / / d e v e l o p e r. a m a z o n . c o m / j a / a l e x a - s k i l l s - k i t / a l e x a - a w s - c re d i t s
  52. H a p p y c o d i n

    g ! #jawsug #awscommunityday