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

熊でもわかるCI/CD/モダンインフラ Vol3 AWS CDK

熊でもわかるCI/CD/モダンインフラ Vol3 AWS CDK

AWS CDKについて勉強会を開きました。

91f47c6a88734f521567938d2436b614?s=128

Shohei Kobayashi

June 12, 2022
Tweet

More Decks by Shohei Kobayashi

Other Decks in Technology

Transcript

  1. "84$%,ฤ "84Ϧιʔεͷ࡞੒ͱ&$4΁ͷσϓϩΠ·Ͱ ۽Ͱ΋Θ͔Δ$*$%ϞμϯΠϯϑϥ

  2. զ ΤϯδχΞྺɿ೥͘Β͍ ۀքɿ8FC͹͔ͬ ݴޠɿ3VCZͱ3BJMT೥ 1)11ZUIPO1FSM೥͘Β͍ʢ๨Ε͕ͪʣ Πϯϑϥ΍͖ͬͯͨྺʹΤϯδχΞྺ %/4αʔόͱ͔ϝʔϧαʔό࡞ͬͯ·ͨ͠ ࠷ۙ͸΋ͬͺΒ3BJMT࢖͍ͷϑϦʔϥϯεɻ ޷͖ͳ%/4αʔόͷϛυϧ΢ΣΞɿEKCEOT ޷͖ͳϝʔϧαʔόͷϛυϧ΢ΣΞɿ2NBJM

    ޷͖ͳ.Z42-ͷίϚϯυ͸TIPXTMBWFTUBUVT ޷͖ͳ"84ϓϩμΫτ͸&MBTUJD.BQ3FEVDF ޷͖ͳ($1ϓϩμΫτ͸$MPVESVO ޷͖ͳ$*$%πʔϧ͸(JUIVC"DUJPO &$4׬ᘳʹཧղͨ͠ কདྷͷເ͸ηΩϡϦςΟΤϯδχΞɻ
  3. $JSDMF$*͸͍͍ͧʂʂʂʂ

  4. લճ·Ͱͷ͓͞Β͍

  5. Πϯϑϥͱιʔείʔυͷద༻ͷྲྀΕ "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS 3%4"VSPSB ϩʔΧϧ͔Βຊ൪·Ͱͷ͓͞Β͍ɻ "NB[PO$MPVE'SPOU ϑϩϯτΤϯυ όοΫΤϯυ "NB[PO4 ։ൃऀͷϩʔΧϧ

    ୯ମςετ ݁߹ςετ Ϗϧυ σϓϩΠ४උ σϓϩΠ
  6. ܧଓతYYYʹ͍ͭͯ 1SPEVDUJPO؀ڥ ։ൃऀͷϩʔΧϧ ୯ମςετ ݁߹ςετ Ϗϧυ σϓϩΠ४උ σϓϩΠ ܧଓతΠϯςάϨʔγϣϯ ܧଓతσϦόϦʔ

    ܧଓతσϓϩΠϝϯτ
  7. %PDLFS*NBHF Πϝʔδ࡞੒ޙίϯςφΛ؅ཧ͢Δ3FQPTJUPSZʹQVTI͠·͢ɻ ։ൃऀͷϩʔΧϧ ୯ମςετ ݁߹ςετ Ϗϧυ σϓϩΠ४උ σϓϩΠ EPDLFSCVJME EPDLFSUBH

    EPDLFSQVTI 1SPEVDUJPO؀ڥ %PDLFS3FQPTJUPSZ
  8. $*Ͱ΍Δϑϩʔجຊ "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS 3%4"VSPSB ։ൃ͸ࣗಈɾຊ൪͸࠷ऴεςοϓͷΈखಈ όοΫΤϯυ ։ൃऀͷϩʔΧϧ ୯ମςετ ݁߹ςετ Ϗϧυ

    σϓϩΠ४උ σϓϩΠ "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS 3%4"VSPSB όοΫΤϯυ %FWFMPQNFOU 1SPEVDUJPO ։ൃ؀ڥ͸NBJOʹQVTIͱಉ࣌ʹσϓϩΠ·Ͱߦ͏ ຊ൪؀ڥ͸खಈͰσϓϩΠͷΈߦ͏ σϓϩΠ ୯ମςετ ݁߹ςετ Ϗϧυ σϓϩΠ४උ
  9. $*Ͱ΍Δϑϩʔجຊͦͷ "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS 3%4"VSPSB ຊ൪ͷσϓϩΠ४උ͸NBJOʹQVTI࣌ʹߦ͏ όοΫΤϯυ ։ൃऀͷϩʔΧϧ ୯ମςετ ݁߹ςετ Ϗϧυ

    σϓϩΠ४උ σϓϩΠ "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS 3%4"VSPSB όοΫΤϯυ %FWFMPQNFOU 1SPEVDUJPO σϓϩΠ ୯ମςετ ݁߹ςετ Ϗϧυ σϓϩΠ४උ ͜ͷεςοϓͰຊ൪΁ͷ४උ΋ߦ͏
  10. $*Ͱ΍Δϑϩʔجຊͦͷ "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS 3%4"VSPSB σϓϩΠ४උͰߦ͏͜ͱ όοΫΤϯυ ։ൃऀͷϩʔΧϧ ୯ମςετ ݁߹ςετ Ϗϧυ

    σϓϩΠ४උ σϓϩΠ %FWFMPQNFOU EPDLFSCVJME EPDLFSUBH EPDLFSQVTI EPDLFSCVJME EPDLFSUBH EPDLFSQVTI "NB[PO&MBTUJD$POUBJOFS3FHJTUPSZ
  11. $*Ͱ΍Δϑϩʔجຊͦͷ "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS σϓϩΠͰߦ͏͜ͱ όοΫΤϯυ ։ൃऀͷϩʔΧϧ ୯ମςετ ݁߹ςετ Ϗϧυ σϓϩΠ४උ

    σϓϩΠ "NB[PO&MBTUJD$POUBJOFS3FHJTUPSZ &$44FSWJDF5BTLVQEBUF &$45BTL%F fi OJUJPOVQEBUF NJHSBUJPO &$4ͷઃఆΛมߋ͢ΔͷͰ "84$%,΍5FSSBGPSNͰ ߦ͏͜ͱ͕ଟ͍Ͱ͢
  12. (JUIVC"DUJPO "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS 3%4"VSPSB ͦΕͧΕͷεςοϓΛZBNMϑΝΠϧͰఆ͍ٛͯ͘͠ όοΫΤϯυ ։ൃऀͷϩʔΧϧ ୯ମςετ ݁߹ςετ Ϗϧυ

    σϓϩΠ४උ σϓϩΠ UFTUZBNM MJOUZBNM CSBLFNBOZBNM EFQMPZZBNM CVJMEZBNM YAML YAML YAML YAML YAML
  13. ࠓճͷςʔϚ "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS σϓϩΠίϚϯυʮDELEFQMPZʯʹ͍ͭͯ࿩ͥ͢ όοΫΤϯυ ։ൃऀͷϩʔΧϧ ୯ମςετ ݁߹ςετ Ϗϧυ σϓϩΠ४උ

    σϓϩΠ ʮDELEFQMPZʯ
  14. "84$%,ͱ͸

  15. "84ϦιʔεΛίʔυͰఆٛ͢Δπʔϧ "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS 3%4"VSPSB ίʔυͰ"84ϦιʔεΛఆٛɺ࣮ߦ͢ΔͱϦιʔε͕࡞੒͞ΕΔ "NB[PO$MPVE'SPOU ϑϩϯτΤϯυ όοΫΤϯυ "NB[PO4 ։ൃऀͷϩʔΧϧ

    cdk deploy WQDTUBDLUT SETTUBDLUT Ϧιʔε࡞੒ʂ Ϧιʔεఆٛʂ
  16. ࣮ࡍͷίʔυ "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS 3%4"VSPSB &$4ͷΫϥελΛ࡞੒͢Δίʔυ "NB[PO$MPVE'SPOU ϑϩϯτΤϯυ όοΫΤϯυ "NB[PO4

  17. ࣮ࡍͷίʔυ "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS 3%4"VSPSB &$4ͷΫϥελΛ࡞੒͢Δίʔυ "NB[PO$MPVE'SPOU ϑϩϯτΤϯυ όοΫΤϯυ "NB[PO4 Infrastructure

    as Code खಈͷϓϩηεͰ͸ͳ͘ίʔυΛ࢖༻ͯ͠ ΠϯϑϥετϥΫνϟͷ؅ཧͱϓϩϏδϣχϯάΛߦ͏͜ͱ
  18. "84$%,ͷ࣮ߦखॱ ίʔυͰ"84ϦιʔεΛఆٛɺ࣮ߦ͢Δͱ$MPVE'PSNBUJPO͕ు͖ग़͞ΕΔ "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS 3%4"VSPSB "NB[PO$MPVE'SPOU ϑϩϯτΤϯυ όοΫΤϯυ "NB[PO4 ։ൃऀͷϩʔΧϧ

    cdk deploy WQDTUBDLUT SETTUBDLUT 5ZQF4DSJQUΛ $MPVE'PSNBUJPOͷελοΫʹม׵ Ϧιʔεఆٛʂ CloudFormation ֤छϦιʔε࡞੒ AWS Local
  19. "84$%,ͷελοΫͷهड़ ෳ਺ͷݴޠͰهड़Ͱ͖Δʢωοτͷ৘ใ͸5ZQF4DSJQU͕ଟ͍ҹ৅ʣ "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS 3%4"VSPSB "NB[PO$MPVE'SPOU ϑϩϯτΤϯυ όοΫΤϯυ "NB[PO4 ։ൃऀͷϩʔΧϧ

    cdk deploy WQDTUBDL SETTUBDL 5ZQF4DSJQUΛ $MPVE'PSNBUJPOͷελοΫʹม׵ CloudFormation ֤छϦιʔε࡞੒ AWS Local
  20. "84$%,ͷσΟϨΫτϦߏ੒ $%,JOJUΛ࣮ߦ͢Δͱ͜ͷܗ͕࡞ΒΕΔ ։ൃऀͷϩʔΧϧ Local WQDTUBDLUT SETTUBDLUT $ cdk init sample-app

    --language typescript
  21. "84$%,ͷσΟϨΫτϦߏ੒ͦͷ 5ZQF4DSJQUͳͷͰJNQPSU͢Ε͹͍͍ͷͰɺ͜Μͳ;͏ʹڞ௨ͷ΋ͷ͸ॻ͖ग़ͯ͠΋͍͍ ։ൃऀͷϩʔΧϧ Local WQDTUBDLUT SETTUBDLUT *OUFSGBDFॻ͖ग़͔͢͸·ͨผͱͯ͜͠Ε͸ྫ

  22. "84$%,ͷσΟϨΫτϦߏ੒ͦͷ CJOҎԼͷϑΝΠϧͰJNQPSU͢Ε͹͍͍ͷͰɺຊ൪༻ͱ։ൃ༻ͷύϥϝʔλΛ༻ҙ͢Δͱָ ։ൃऀͷϩʔΧϧ Local WQDTUBDLUT SETTUBDLUT

  23. "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS 3%4"VSPSB ิ଍ͷਤɻ όοΫΤϯυ ։ൃऀͷϩʔΧϧ "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS 3%4"VSPSB όοΫΤϯυ

    %FWFMPQNFOU 1SPEVDUJPO EFWUT QSPEUT "84$%,ͷσΟϨΫτϦߏ੒ͦͷิ଍
  24. %#ͷ৘ใ΍Ͳ͔͜ͷ"1*ͷBQJLFZɺBDDFTTUPLFO͸"844ZTUFN.BOBHFS͔4FDSFU.BOBHFSΛ࢖͏ ػີ৘ใ "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS 3%4"VSPSB "NB[PO$MPVE'SPOU ϑϩϯτΤϯυ όοΫΤϯυ "NB[PO4 ։ൃऀͷϩʔΧϧ

    cdk deploy WQDTUBDLUT SETTUBDLUT CloudFormation ֤छϦιʔε࡞੒ AWS Local ػີ৘ใΛ؀ڥม਺Ͱ औΓࠐΉ
  25. "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS 3%4"VSPSB 54ϑΝΠϧʹ͸4ZTUFN.BOBHFS4FDSFU.BOBHFSͷ"3/Λॻ͘ όοΫΤϯυ ։ൃऀͷϩʔΧϧ "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS 3%4"VSPSB όοΫΤϯυ

    %FWFMPQNFOU 1SPEVDUJPO EFWUT QSPEUT ػີ৘ใ ։ൃ༻ػີ৘ใ ຊ൪༻ػີ৘ใ
  26. "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS 3%4"VSPSB ΞϓϦέʔγϣϯଆ͸؀ڥม਺ͰಡΈࠐΉΑ͏ʹ͓ͯ͘͠ όοΫΤϯυ ։ൃऀͷϩʔΧϧ "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS 3%4"VSPSB όοΫΤϯυ

    %FWFMPQNFOU 1SPEVDUJPO EFWUT QSPEUT ػີ৘ใ ։ൃ༻ػີ৘ใ ຊ൪༻ػີ৘ใ
  27. "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS 3%4"VSPSB $%,Ͱ؀ڥม਺ΛಡΈࠐΉΑ͏ʹॻ͘͜ͱ͕Ͱ͖Δɻ όοΫΤϯυ ։ൃऀͷϩʔΧϧ "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS 3%4"VSPSB όοΫΤϯυ

    %FWFMPQNFOU 1SPEVDUJPO EFWUT QSPEUT ػີ৘ใ ։ൃ༻ػີ৘ใ ຊ൪༻ػີ৘ใ
  28. "84$%,ͱσϓϩΠ

  29. σϓϩΠͷจ຺͓͞Β͍ "84ͷυΩϡϝϯτͱࠓ·Ͱ๻Β͕ݴ͍ͬͯΔҙຯ߹͍ඍົʹݴͬͯΔ͜ͱ͕ҧ͏ ։ൃऀͷ͍͏σϓϩΠ "84ͷυΩϡϝϯτͷ͍͏σϓϩΠ खݩͷιʔείʔυΛຊ൪ʹద༻͢Δɻ %PDLFSJNBHFͱͯ͠׬੒͞Εͨ΋ͷΛίϯςφͱͯ͠ىಈຊ൪ͷ&$4ʹϦϦʔε͢Δɻ

  30. "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS 3%4"VSPSB 4ZTUFN.BOBHFS4FDSFU.BOBHFS όοΫΤϯυ ։ൃऀͷϩʔΧϧ "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS 3%4"VSPSB όοΫΤϯυ

    %FWFMPQNFOU 1SPEVDUJPO EFWUT QSPEUT ४උػີ৘ใΛ؀ڥ෼༻ҙ ։ൃ༻ػີ৘ใ ຊ൪༻ػີ৘ใ
  31. "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS 3%4"VSPSB ΞϓϦέʔγϣϯଆ͸؀ڥม਺ͰಡΈࠐΉΑ͏ʹ͓ͯ͘͠ όοΫΤϯυ ։ൃऀͷϩʔΧϧ "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS 3%4"VSPSB όοΫΤϯυ

    %FWFMPQNFOU 1SPEVDUJPO EFWUT QSPEUT ४උΞϓϦ಺ͷඞཁͳ৘ใ͸؀ڥม਺Ͱ ։ൃ༻ػີ৘ใ ຊ൪༻ػີ৘ใ
  32. ४උ"84$%,ͰجຊϦιʔεΛ࡞੒ ίʔυͰ"84ϦιʔεΛఆٛɻඞཁͳϦιʔεΛ࡞͓ͬͯ͘ "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS 3%4"VSPSB "NB[PO$MPVE'SPOU ϑϩϯτΤϯυ όοΫΤϯυ "NB[PO4 ։ൃऀͷϩʔΧϧ

    cdk deploy WQDTUBDLUT SETTUBDLUT 5ZQF4DSJQUΛ $MPVE'PSNBUJPOͷελοΫʹม׵ Ϧιʔεఆٛʂ CloudFormation ֤छϦιʔε࡞੒ AWS Local
  33. ४උ(JUIVC"DUJPOͰσϓϩΠ४උ·ͰΛఆٛ EPDLFSίϚϯυҰࣜ·Ͱߦ͍ɺ"84ͷDPOUBJOFS3FHJTUPSZʹQVTI·ͰΛ΍͓ͬͯ͘ ։ൃऀͷϩʔΧϧ ୯ମςετ ݁߹ςετ Ϗϧυ σϓϩΠ४උ EPDLFSCVJME EPDLFSUBH EPDLFSQVTI

    EPDLFSCVJME EPDLFSUBH EPDLFSQVTI "NB[PO&MBTUJD$POUBJOFS3FHJTUPSZ
  34. σϓϩΠ "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS DELEFQMPZίϚϯυ όοΫΤϯυ ։ൃऀͷϩʔΧϧ ୯ମςετ ݁߹ςετ Ϗϧυ σϓϩΠ४උ

    σϓϩΠ "NB[PO&MBTUJD$POUBJOFS3FHJTUPSZ &$44FSWJDF5BTLVQEBUF &$45BTL%F fi OJUJPOVQEBUF NJHSBUJPO DELEFQMPZ<ελοΫ໊>
  35. ࣮ԋ

  36. ·ͱΊ "84$%,  "84Ϧιʔε࡞੒ΛίʔυͰఆٛͰ͖Δπʔϧɻ  ΠϯϑϥఆٛΛίʔυͰߦ͏͜ͱΛ*OGSBTUSVDUVSFBTDPEFͱ͍͏ɻ  5ZQF4DSJQUͳͲ๻Β͕Α͘࢖͏ݴޠͰهड़Ͱ͖Δ  ࣮ࡍ͸$MPVE'PSNBUJPOͷδΣωϨʔλͰ͋Δ

    σϓϩΠϑϩʔ  ΞϓϦଆ͸ػີ৘ใ͸؀ڥม਺Ͱ஫ೖ͢ΔΑ͏ʹ͢Δ  "84ଆͷػີ৘ใ͸"844FDSFU.BOBHFS΍4ZTUFN.BOBHFSΛ࢖͏
  37. ࣍ճ༧ࠂ "NB[PO&$4 "QQMJDBUJPO-PBE#BMBODFS &$4ʹ͍ͭͯ΋ͬͱਂ۷Γ͍ͯͥ͘͠ όοΫΤϯυ