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

CodePipeline+CodeBuildで Serverless Frameworkのデプ...

CodePipeline+CodeBuildで Serverless Frameworkのデプロイを楽にする

Serverless Meetup Osaka vol.2 LT

Hidetaka Okamoto

January 27, 2017
Tweet

More Decks by Hidetaka Okamoto

Other Decks in Technology

Transcript

  1. C o d e P i p e l i

    n e + C o d e B u i l d Ͱ S e r v e r l e s s F r a m e w o r k ͷ σ ϓ ϩ Π Λ ָ ʹ ͢ Δ S e r v e r l e s s M e e t u p O s a k a v o l . 2 LT
  2. · ͱ Ί • AWS Code BuildͰServerless FrameworkͷσϓϩΠ͕ࣗಈԽͰ͖Δ • AWS

    CodePipeline΋࢖͑͹ঝೝϑϩʔ·Ͱ࡞੒Մೳ • खॱॻͷཁΔ࡞ۀ͸ͲΜͲΜࣗಈԽ΍͍ͬͯ͜͏
  3. H i d e t a k a O k

    a m o t o • AMIMOTO / Shifter • WordBenchKyoto • SAAϦϕϯδ੒ޭ
  4. A P I ͸ S e r v e r

    l e s s F W Ͱ σ ϓ ϩ Πɺ ϑ ϩ ϯ τ ͸ S 3 Ͱ ϗ ε τ ͠ Α ͏
  5. $ s l s d e p l o y

    $ s 3 s y n c . s 3 : / / s o m e - b u c k e t
  6. ։ ൃ ͱ ຊ ൪ Ͱ ؀ ڥ Θ ͚Α

    ͏ ɻ σ ϓ ϩ Π ࣌ ͸ ཁ ஫ ҙ Ͷ ɻ
  7. $ s l s d e p l o y

    - - s t a g e d e v $ s 3 s y n c . s 3 : / / d e v - s o m e - b u c k e t $ s l s d e p l o y - - s t a g e p ro d $ s 3 s y n c . s 3 : / / p ro d - s o m e - b u c k e t
  8. n p m ͷ ύ ο έ ʔ δ Λ

    ͍ ͭ͘ ͔ ಉ ࠝ ͠ ͨ ͍
  9. $ n p m p r u n e -

    - p ro d u c t i o n $ s l s d e p l o y - - s t a g e d e v $ s 3 s y n c . s 3 : / / d e v - s o m e - b u c k e t $ s l s d e p l o y - - s t a g e p ro d $ s 3 s y n c . s 3 : / / p ro d - s o m e - b u c k e t $ n p m i n s t a l l
  10. σ ϓ ϩ Π લ ʹ ςε τ ΍ ߏ

    จ ν Σ ο Ϋ ΋ ͠ Α ͏
  11. $ n p m t e s t $ n

    p m r u n l i n t $ n p m p r u n e - - p ro d u c t i o n $ s l s d e p l o y - - s t a g e d e v $ s 3 s y n c . s 3 : / / d e v - s o m e - b u c k e t $ s l s d e p l o y - - s t a g e p ro d $ s 3 s y n c . s 3 : / / p ro d - s o m e - b u c k e t $ n p m i n s t a l l
  12. C D N ͭ ͚ ͨ ͷ Ͱɺ Ω ϟ

    ο γ ϡ ΋ ফ ͠ · ͠ ΐ ͏
  13. $ n p m t e s t $ n

    p m r u n l i n t $ n p m p r u n e - - p ro d u c t i o n $ s l s d e p l o y - - s t a g e d e v $ s 3 s y n c . s 3 : / / d e v - s o m e - b u c k e t $ s l s d e p l o y - - s t a g e p ro d $ s 3 s y n c . s 3 : / / p ro d - s o m e - b u c k e t $ a w s c l o u d f ro n t c re a t e - i n v a l i d a t i o n - - p a t h " / * " $ n p m i n s t a l l
  14. ʊ ਓ ਓ ਓ ਓ ਓ ʊ ʼ ɹ ͭ

    Β ͍ ɹ ʻ ʉ Y ^ Y ^ Y ^ Y ʉ
  15. ί Ϛ ϯ υ ͕ ૿ ͑Δ ͱ ϛ ε

    ΍ ώ Ϡ Ϧ ϋο τ ΋ ૿ ͑Δ • σϓϩΠઌΛؒҧ͑Δʢdev ? develpoment ? staging ?ʣ • ௕͘ͳΔखॱॻɺ࿙ΕΔߋ৽ • Ωϟογϡফ͠๨ΕɺΩϟογϡ࡟আૢ࡞ϛε • ύοέʔδಉࣦࠝഊʢ--save-devͨ͠ͷ΋ೖͬͯ༰ྔΦʔόʔʣ
  16. ʊ ਓ ਓ ਓ ਓ ਓ ʊ ʼ ɹ ͭ

    Β ͍ ɹ ʻ ʉ Y ^ Y ^ Y ^ Y ʉ
  17. C o d e B u i l d w

    i t h S e r v e r l e s s F r a m e w o r k • Code Build͸Node.js͕࣮ߦՄೳ • buildspec.ymlͰσϓϩΠίϚϯυΛGit؅ཧ • ؀ڥม਺΋ઃఆՄೳͳͷͰࣗ༝౓͕ߴ͍
  18. ΍ ͬͯ Έͯ ϋϚ ͬ ͨ o r ཁ ஫

    ҙ ͩ ͬ ͨ ͱ ͜ Ζ • IAMϩʔϧ • Serverless FrameworkͷΠϯετʔϧ৔ॴ • σϓϩΠλΠϛϯάͷࢦఆͱঝೝϑϩʔ • Code Buildߋ৽Ͱ͖ͳ͍໰୊
  19. ΍ ͬͯ Έͯ ϋϚ ͬ ͨ o r ཁ ஫

    ҙ ͩ ͬ ͨ ͱ ͜ Ζ • IAMϩʔϧ • Serverless FrameworkͷΠϯετʔϧ৔ॴ • σϓϩΠλΠϛϯάͷࢦఆͱঝೝϑϩʔ • Code Buildߋ৽Ͱ͖ͳ͍໰୊
  20. I A M ϩ ʔϧ ઃ ఆ ͕ େ ม

    • Serverless FW͕৮ΔϦιʔεଟ͍ • ϑϧݖݶ͸Ͱ͖Δ͚ͩ౉ͨ͘͠ͳ͍ • IAM͸ӈͷ͕̒ͭ࠷খݶʢͳ͸ͣʣ "iam:GetRole", "iam:CreateRole", "iam:DeleteRole", "iam:PutRolePolicy", "iam:DeleteRolePolicy", "iam:PassRole"
  21. ΍ ͬͯ Έͯ ϋϚ ͬ ͨ o r ཁ ஫

    ҙ ͩ ͬ ͨ ͱ ͜ Ζ • IAMϩʔϧ • Serverless FrameworkͷΠϯετʔϧ৔ॴ • σϓϩΠλΠϛϯάͷࢦఆͱঝೝϑϩʔ • Code Buildߋ৽Ͱ͖ͳ͍໰୊
  22. n p m p r u n e - -

    p ro d u c t i o n ʹ ཁ ஫ ҙ • `npm prune --production`͢ΔͱdevDependenciesͷύοέʔδ͕ফ͑Δ • `npm install --save-dev serverless`΋ফ͑Δ • `npm install -g serverless@version`ͷํ͕ແ೉͔΋
  23. ΍ ͬͯ Έͯ ϋϚ ͬ ͨ o r ཁ ஫

    ҙ ͩ ͬ ͨ ͱ ͜ Ζ • IAMϩʔϧ • Serverless FrameworkͷΠϯετʔϧ৔ॴ • σϓϩΠλΠϛϯάͷࢦఆͱঝೝϑϩʔ • Code Buildߋ৽Ͱ͖ͳ͍໰୊
  24. ঝ ೝ ϑ ϩ ʔ Λ ͭ ͚Δ ͳ Β

    C o d e P i p e l i n e • Code PipelineΛ࢖͑͹खಈঝೝ͕ઃఆͰ͖Δ • SNSͰ௨஌Λग़ͤΔͷͰɺϦϦʔεϦʔμʔ΁ͷ֬ೝґཔ΋ࣗಈԽ • Code Pipelineͷ؅ཧը໘ͰCode BuildͷઃఆΛ͢ΔͱͪΐͬͱϋϚΔ
  25. ΍ ͬͯ Έͯ ϋϚ ͬ ͨ o r ཁ ஫

    ҙ ͩ ͬ ͨ ͱ ͜ Ζ • IAMϩʔϧ • Serverless FrameworkͷΠϯετʔϧ৔ॴ • σϓϩΠλΠϛϯάͷࢦఆͱঝೝϑϩʔ • Code Buildߋ৽Ͱ͖ͳ͍໰୊
  26. C o d e P i p e l i

    n e ͔ Β ৮ Δ ͱ ઃ ఆ ม ߋ Ͱ ͖ ͳ ͍ • Code Pipeline͔Β࡞ͬͨCode BuildͷϏϧυ͸ߋ৽Ͱ͖ͳ͍ • มߋ͍ͨ࣌͠͸ɺ৽͘͠࡞Γ௚͢ඞཁ͋Γ • ؀ڥม਺ม͍͑ͨ࣌ʹͭΒ͍