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

ask-cliで加速する Alexa Skills Kit開発

ask-cliで加速する Alexa Skills Kit開発

JAWS-UG Okayama 2018/08

Hidetaka Okamoto

August 04, 2018
Tweet

More Decks by Hidetaka Okamoto

Other Decks in Technology

Transcript

  1. a s k - c l i Ͱ Ճ ଎

    ͢ Δ A l e x a S k i l l s K i t ։ ൃ J A W S - U G O k a y a m a 2 0 1 8 / 0 8
  2. H i d e t a k a O k

    a m o t o • Digitalcube Co. Ltd. • WordCamp Kyoto 2017࣮ߦҕһ௕ • Cloud Quiz Gameଞ೔ถͰෳ਺εΩϧ ެ։
  3. A A J U G : A m a z

    o n A l e x a J a p a n U G https://aajug.connpass.com/
  4. A g e n d a • What is ask-cli

    ? • ศརͳίϚϯυ • with VS Code • with Serverless FW
  5. A g e n d a • What is ask-cli

    ? • ศརͳίϚϯυ • with VS Code • with Serverless FW
  6. $ n p m i - g a s k

    - c l i https://www.npmjs.com/package/ask-cli
  7. a s k - c l i i s …

    • Alexa Skills Kit CLI • εΩϧ։ൃͷ΋Ζ΋ΖΛίϚϯυϥΠϯ͔Β࣮ߦͰ͖Δ • AWSͱAmazon DeveloperΞΧ΢ϯτ͕ඞཁ • ֤छ৘ใ͸ “~/.ask/cli_config”ʹอଘ͞ΕΔ
  8. a s k i n i t Ͱ Ξ Χ

    ΢ ϯ τ ͷ ؔ ࿈ ෇ ͚ ͕ ඞ ཁ $ n p m i - g a s k - c l i $ a s k i n i t [ - p Y O U R _ P R O F I L E _ N A M E ] # A m a z o n ։ ൃ ऀ Ξ Χ ΢ ϯ τ ͷ ࿈ ܞ ͷ ͨ Ί ͷ ϒ ϥ ΢ β ͕ ग़ Δ # ೝ ূ ੒ ޭ ͢ Δ ͱ C L I ʹ ໭ ͬͯ ର ࿩ ܗ ࣜ Ͱ η ο τΞ οϓ # AW 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 / d o c s / s m a p i / a s k - c l i - c o m m a n d - re f e re n c e . h t m l # i n i t - c o m m a n d
  9. A g e n d a • What is ask-cli

    ? • ศརͳίϚϯυ • with VS Code • with Serverless FW
  10. a s k - c l i Ͱ Ͱ ͖

    Δ ͜ ͱ • ϓϩδΣΫτͷ৽ن࡞੒ • σϓϩΠ • γϡϛϨʔτ • ςετ • σϓϩΠࡁΈεΩϧͷΠϯϙʔτ • more…
  11. a s k - c l i Ͱ Ͱ ͖

    Δ ͜ ͱ • init [options] • deploy [options] • new [options] • clone [options] • simulate [options] • validate [options] • status [options] • diff [options] • lambda • api • add • remove • util • help [cmd]
  12. ৽ ن ࡞ ੒ ͔ Β ਃ ੥ · Ͱ

    $ a s k n e w - n “ m y - s k i l l ” $ c d m y - s k i l l $ a s k d e p l o y $ a s k a p i s u b m i t - s “ Y O U R _ S K I L L _ I D ” 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 / d o c s / s m a p i / a s k - c l i - c o m m a n d - re f e re n c e . h t m l # i n i t - c o m m a n d
  13. a s k n e w ͷ σΟ Ϩ Ϋ

    τ Ϧ ߏ ੒ $ tree -L 3 . ᵓᴷᴷ lambda ᴹ ᵋᴷᴷ custom ᴹ ɹɹɹɹᵓᴷᴷ index.js ᴹ ɹɹɹɹ ᵓᴷᴷ node_modules ᴹ ɹɹɹɹ ᵋᴷᴷ package.json ᵓᴷᴷ models ᴹ ɹɹᵋᴷᴷ en-US.json ᵋᴷᴷ skill.json 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 / d o c s / s m a p i / a s k - c l i - c o m m a n d - re f e re n c e . h t m l
  14. a s k n e w ʹ ؔ ͢ Δ

    ΋ Ζ ΋ Ζ • .gitignore͕࡞੒͞Ε͍ͯͳ͍ • git؅ཧ͢Δࡍ͸ɺnode_modules/Λඞͣ.gitignore΁ • -tΦϓγϣϯͰgithub.com/alexaαϯϓϧΛΠϯϙʔτՄೳʢΒ͍͠ʣ
  15. a s k d e p l o y ʹ

    ؔ ͢ Δ ΋ Ζ ΋ Ζ • AWS Lambda͸ask initͨ͠ࡍͷϓϩϑΝΠϧΛ࢖ͬͯσϓϩΠ • IAM͸Lambda invokeͷͨΊ͚ͩͷ΋ͷ͕͚ͭΒΕΔ • DynamoDB΍AESͳͲΛ࢖͍͍ͨ࣌͸Serverless FW͔SAMਪ঑
  16. a s k - c l i ί Ϛ ϯ

    υ Λ ศ ར ʹ ࢖ ͏ • εΩϧID͸.ask/configͷʮ.deploy_settings.[PROFILE].skill_idʯʹ͋Δ • Lambdaؔ਺໊΍Invoke໊ͳͲ΋.ask/config·ͨ͸models/഑Լʹ͋Δ • cat & jqͱ૊Έ߹ΘͤΔͱɺϫϯϥΠφʔͰ͍Ζ͍ΖͰ͖Δ
  17. ͍ Ζ ͍ Ζ ΍ ͬ ͨ ྫ ͸ ͜

    ͜ ͔ Β ݟ Ε · ͢ https://wp-kyoto.net/useful-shell-commands-for-ask-cli
  18. A g e n d a • What is ask-cli

    ? • ศརͳίϚϯυ • with VS Code • with Serverless FW
  19. V S C o d e ʹ ެ ࣜ ͷ

    ϓ ϥ άΠ ϯ https://marketplace.visualstudio.com/items?itemName=ask-toolkit.alexa-skills-kit-toolkit
  20. V S C o d e ϓ ϥ άΠ ϯ

    Ͱ Ͱ ͖ Δ ͜ ͱ • IDE͔Βask-cliͷૢ࡞ • ର࿩Ϟσϧͷίʔυεχϖοτ • Node.jsεΫϦϓτͷίʔυεχϖοτ
  21. S h i f t + C o m m

    a n d + p ͯ͠ ͔ Β a s k https://wp-kyoto.net/ask-toolkit-beta
  22. ର ࿩ Ϟ σϧ J S O N Ͱ a

    s k https://wp-kyoto.net/ask-toolkit-beta
  23. a s k - s d k ͷ ί ʔ

    υ ε χ ϖ ο τ https://wp-kyoto.net/ask-toolkit-beta
  24. A g e n d a • What is ask-cli

    ? • ศརͳίϚϯυ • with VS Code • with Serverless FW
  25. L a m b d a σ ϓ ϩ Π

    ʹ a s k - c l i Λ ࢖ Θ ͳ ͍ • ask-cliʹ͸IAM·ΘΓͷઃఆػೳ͕ͳ͍ʢࠓͷͱ͜Ζʣ • DynamoDB / AESͳͲͱ࿈ܞ͍ͨ͠৔߹ɺखͰIAMઃఆ͕ඞཁ • CloudFormationΛར༻͢Δ͜ͱͰɺઃఆͷίʔυԽ͕Մೳ
  26. S e r v e r l e s s

    F W / A W S S A M
  27. S e r v e r l e s s

    . y m l ͷ α ϯ ϓϧ service: name: ask-sample provider: name: aws runtime: nodejs8.10 iamRoleStatements: - Effect: "Allow" Action: - "dynamodb:*" Resource: - "arn:aws:dynamodb:us-east-1:*:table/ASKSample" functions: alexa: handler: index.handler events: - alexaSkill
  28. D y n a m o D B ͷ ΞΫ

    η ε Λ ڐ Մ ͢ Δ provider: name: aws runtime: nodejs8.10 iamRoleStatements: - Effect: "Allow" Action: - "dynamodb:*" Resource: - "arn:aws:dynamodb:us-east-1:*:table/ASKSample"
  29. L a m b d a ͷ Πϕ ϯ τ

    τ Ϧ Ψ ʔ Λ ઃ ఆ ͢ Δ functions: alexa: handler: index.handler events: - alexaSkill
  30. s k i l l . j s o n

    ʹ L a m b d a ͷ A R N Λ ࢦ ఆ ͢ Δ { "manifest": { "publishingInformation": { }, "apis": { "custom": { "endpoint": { "uri": "arn:aws:lambda:us-east-1:9999999:function:ask-sample-dev-alexa" }, "regions": { "NA": { "endpoint": { "uri": "arn:aws:lambda:us-east-1:9999999:function:ask-sample-dev-alexa" } } } } },
  31. . a s k / c o n f i

    g ͷ e n d p o i n t ΋ A R N ʹ ม ߋ ͢ Δ { "deploy_settings": { "default": { "merge": { "manifest": { "apis": { "custom": { "endpoint": { "uri": "arn:aws:lambda:us-east-1:999999999:function:ask-sample-dev-alexa" } } } } },
  32. a s k - c l i ͕ L a

    m b d a ͷ σ ϓ ϩ Π Λ ল ུ ͢ Δ Α ͏ ʹ ͳ Δ $ a s k i n i t $ c d l a m b d a / c u s t o m $ s l s d e p l o y $ c d . . / . . / $ a s k d e p l o y
  33. ࠷ ۙ a s k - c l i Ͱ

    ΍ ͬͯ Δ ͜ ͱ
  34. m o c h a + a s k -

    c l i Ͱ ςε τ ࣗ ಈ Խ
  35. a s k s i m u l a t

    e ͷ ࢖ ͍ ॴ ͷ ྫ • Lambda͕ΤϥʔΛग़͍ͯ͠ͳ͍͔ʁ • εΩϧΧʔυ΍σΟεϓϨΠͷϚʔΫΞοϓ͕յΕ͍ͯͳ͍͔ʁ • Unhandledͳൃ࿩ʹରͯ͠ͷϋϯυϦϯά • ൃ࿩ͷ಺༰ʢԻ੠ʣʹ͍ͭͯ͸ςετͰ͖ͳ͍ • γϡϛϨʔλɾ࣮ػςετͷલʹ΍Δͱςελʔͷ৺͕ંΕͳ͍
  36. [ ൺ ֱ త ] ؆ ୯ ʹ A l

    e x a εΩϧ Λ ࡞ Δ ํ ๏
  37. [ ൺ ֱ త ] ؆ ୯ ʹ A l

    e x a εΩϧ Λ ࡞ Δ ํ ๏ ʢ ֗ Ψ Π υ ʣ $ a s k n e w - - t e m p l a t e " C i t y G u i d e " - n “ m y - s k i l l ” $ c d m y - s k i l l $ c p m o d e l s / e n - U S . j s o n m o d e l s / j a - J P. j s o n $ c o d e . / 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 / d o c s / s m a p i / a s k - c l i - c o m m a n d - re f e re n c e . h t m l # i n i t - c o m m a n d
  38. m o d e l s / j a -

    J P. j s o n Λ ೔ ຊ ޠ Խ ͢ Δ
  39. [ ൺ ֱ త ] ؆ ୯ ʹ A l

    e x a εΩϧ Λ ࡞ Δ ํ ๏
  40. s k i l l . j s o n

    Λ ೔ ຊ ޠ ର Ԡ
  41. l a m b d a / c u s

    t o m / i n d e s . j s ͷ ς Ωε τ ೔ ຊ ޠ Խ
  42. [ ൺ ֱ త ] ؆ ୯ ʹ A l

    e x a εΩϧ Λ ࡞ Δ ํ ๏ ʢ ֗ Ψ Π υ ʣ $ a s k d e p l o y - > h t t p s : / / d e v e l o p e r. a m a z o n . c o m ΁ ΞΫ η ε - > ΞΠ ί ϯ ΍ આ ໌ จ ɾ Χ ς ΰ Ϧ Λ ม ߋ - > ਃ ੥ 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 / d o c s / s m a p i / a s k - c l i - c o m m a n d - re f e re n c e . h t m l # i n i t - c o m m a n d
  43. N o d e . j s ͱ ͔ A

    S R ͱ ͔ N L U ͱ ͔ Θ ͔ Β ͳ ͘ ͯ ΋ ͱ Γ ͋ ͑ͣ େ ৎ ෉
  44. A l e x a Λ ى ఺ ͱ ͢

    Δ ৽ ͠ ͍ Ϗ δ ω ε
  45. Ի ੠ ϕ ʔε ͷ ৽ ͠ ͍ ί ϛ

    ϡ χέ ʔ γ ϣ ϯ • ʮʙ͠ͳ͕Βʯͱ͍͏Ϣʔεέʔε • ΈΜͳͰ༡΂Δίϯςϯπͷఏڙ • ࣗࣾαʔϏεͷλονϙΠϯτ֦ு • কདྷతʹ͸push΍༗ྉίϯςϯπ΋
  46. AlexaΛ༻͍ͨશ͘৽͍͠ސ٬ମݧͷఏڙʹ ௅ઓͯ͠Έ·ͤΜ͔ʁ h t t p s : / /

    w w w. d i g i t a l c u b e . j p / s e r v i c e / w e b - s e r v i c e / a m a z o n - a l e x a - s k i l l s /