$30 off During Our Annual Pro Sale. View Details »

AWS CDKでまるっと インフラ環境をIaCしたぞ!

kubotak
September 24, 2022

AWS CDKでまるっと インフラ環境をIaCしたぞ!

PHPConference2022 ゴールドスポンサーLT 2022/09/24

kubotak

September 24, 2022
Tweet

More Decks by kubotak

Other Decks in Programming

Transcript

  1. Copyright© M&AΫϥ΢υ AWS CDKͰ·Δͬͱ Πϯϑϥ؀ڥΛIaCͨͧ͠ʂ PHP Conference Japan 2022 /

    Kenjiro Kubota
  2. Copyright© M&AΫϥ΢υ ͓ͳ͡ΈɺM&AΫϥ΢υͰ͢ PHPConferenceͱ͍͑͹M&AΫϥ΢υ ※౰ࣾઆɺॾઆ͋Γ·͢ • PHPConference 2020(4໊) • PHPConference

    2021(5໊) • PHPConference 2022(4໊) M&AΫϥ΢υࡏ੶ΤϯδχΞͷPHPConferenceొஃྺ
  3. Copyright© M&AΫϥ΢υ ٻਓ޿ࠂαΠτͷΑ͏ͳM&AμΠϨΫτϚονϯά 3 ങ͍ख ɾҊ݅ใु͸M&A੒ޭใुͷΈ ɾ࠷௿ख਺ྉͳ͠ ɾചΓखιʔγϯάͷνϟωϧ͕૿͑Δ ɾM&AχʔζΛൃ৴͢Δ͚ͩͰചΓखΛू٬ ɾ஥հۀऀΛհͣ͞ʹμΠϨΫτʹ΍ΓऔΓՄೳ

    ɾજࡏ૚ʹ΋Ϧʔν͕Մೳ ख਺ྉແ ྉ ※ϓϥοτϑΥʔϜҊ݅ͷ৔߹ ※ ചΓख 1.ܝࡌ͢Δ ɾങ͍खͷM&AχʔζΛࣗΒௐ΂Δ͜ͱ͕Մೳ
 ɾ஥հۀऀΛհͣ͞ʹμΠϨΫτʹ΍ΓऔΓՄೳ
 ɾങ͍खͷM&A୲౰ऀʹ௚઀ίϯλΫτΛͱΕΔ
 ɾ஥հۀऀΛ࢖Θͳ͍ͷͰख਺ྉ͕ແྉ 2.ΦϑΝʔ͢Δ M&Aɾग़ࢿχʔζΛܝࡌ ങ͍खͷϝϦοτ ചΓखͷϝϦοτ ɾ஥հۀऀΛ࢖Θͳ͍ͷͰख਺ྉ͕ແྉ ʓʓྖҬͷձࣾΛ ืू͠·͢ ͜ͷձࣾͱҰॹʹ ΍͍͖͍ͬͯͨʂ 3 PR
  4. Copyright© M&AΫϥ΢υ ࢿۚௐୡϓϥοτϑΥʔϜ 2022೥ౙఏڙ։࢝ PR ࡢࠓͷࢿۚௐୡχʔζٸ૿ʹ͋Θͤɺैདྷ͸M&AΫϥ΢υ಺Ͱఏڙ͍ͯͨ͠ ʮࢿۚௐୡͷػೳʯΛ੾Γग़͠ɺࢿۚௐୡʹಛԽͨ͠৽αʔϏεΛߏஙதͰ͢ɻ ͜ΕʹΑΓɺ೔ຊதͷελʔτΞοϓاۀͷࢿۚௐୡΛεϜʔζʹ͠ɺΑΓεϐʔυ ײΛ࣋ͬͨࣄۀ੒௕ʹߩݙͯ͠·͍Γ·͢ɻ

  5. Copyright© M&AΫϥ΢υ AWS CDKͱ͸

  6. Copyright© M&AΫϥ΢υ AWS CDKͱ͸ AWS Cloud Development Kit (AWS CDK)

    AWS CloudFormationΛ࣮ߦ͢ΔίʔυΛએݴతͳςϯϓϨʔτͱͯ͠ఆٛ͢Δ͜ͱͰϓϩϏ δϣχϯάΛ࣮ݱͰ͖ΔϑϨʔϜϫʔΫ CloudFormationʹΑΓIaC͕࣮ߦ͞ΕΔͷͰࣗಈϩʔϧόοΫ΍υϦϑτݕग़ʢखಈมߋͯ͠͠ ·ͬͨ৔߹ʹఆٛͱ࣮ମ͕ဃ཭͢Δ͜ͱΛݕग़ʣ͕Ͱ͖Δɻ ҎԼͷݴޠ͕αϙʔτ͞Ε͍ͯΔ PHP͸ͳ͍
  7. Copyright© M&AΫϥ΢υ AWS CDKͱ͸ AWS CDK Constructs CDK͸APPɺStackɺConstructͷ֤ཁૉʹΑͬͯߏ੒͞Ε͍ͯΔɻ • APP

    ◦ Stackͷґଘؔ܎ͷఆٛ • Stack ◦ CloudformationͷStack୯Ґ ◦ σϓϩΠͷ࠷খ୯Ґ • Construct ◦ AWSͷϦιʔε
  8. Copyright© M&AΫϥ΢υ AWS CDKͱ͸ Construct Library CDK͸Construct LibraryΛ࢖༻ͯ͠AWSϦιʔεΛఆٛ͠·͢ɻ Construct Libraryʹ͸ҎԼͷ3छྨʹ෼͚ΒΕ·͢ɻ

    • low-level constructsʢL1ʣ ◦ ௚ײతʹϦιʔεΛఆٛ͢Δ͜ͱ͕Ͱ͖ɺσϑΥϧτ஋͕ઃఆࡁΈͷศརͳϝιου ͕ఏڙ͞ΕΔ • higher-level, intent-based APIʢL2ʣ ◦ ϓϩύςΟΛ໌ࣔతʹઃఆ͢Δඞཁ͕͋ΔͨΊɺύϥϝʔλΛৄࡉʹઃఆͰ͖Δ ◦ Ϋϥε໊ʹCfnϓϨϑΟοΫε͕͍͍ͭͯΔ • patternsʢL3ʣ ◦ ҰൠతͳΞʔΩςΫνϟύλʔϯʹै͏ߴϨϕϧͷConstructΛఏڙ
  9. Copyright© M&AΫϥ΢υ AWS CDKͱ͸ AWS SDKʹ͍ͭͯৄ͘͠஌Γ͍ͨํ͸ ͪ͜ΒͷηογϣϯΛνΣοΫʂ ʢ͢ͰʹऴΘ͍ͬͯΔηογϣϯͳͷͰεϥΠυ͔ಈըΛࢀর͍ͩ͘͞ʣ

  10. Copyright© M&AΫϥ΢υ M&AΫϥ΢υͷࣄྫ M&AΫϥ΢υͷΠϯϑϥ Amazon Web Service(AWS)্Ͱߏங͍ͯ͠·͢ɻ ओʹҎԼͷαʔϏεΛར༻ • ECS(Fargate)

    • ECR • Lambda • Cloudfront • Open Search Service • ALB • CloudWatch • Athena • S3 • RDS • ElastiCache • SQS • etc
  11. Copyright© M&AΫϥ΢υ AWS CDKΛಋೖ͢Δલ ϒϥ΢βͷAWSίϯιʔϧ͔Βૢ࡞ αʔϏεΠϯ͔Β3೥ఔ౓͸࣮͸͜ͷঢ়ଶͰಛʹ໰୊ʹͳͬͯͳ͔ͬͨɻ ࡞ۀΛεΫγϣͯ͠υΩϡϝϯτʹ࢒͢ͳͲߦ͍ͬͯͯ൥Θ͠͞͸͕͋ͬͨɺසൟʹΠϯϑϥʹ खΛೖΕΔ͜ͱ͕ͳ͔ͬͨɻ Ұ෦Serverless FrameworkΛ࢖͏ͳͲIaCʹͳ͍ͬͯΔ΋ͷ΋͋ͬͨɻ

  12. Copyright© M&AΫϥ΢υ ֬ೝ؀ڥΛ૿΍ͦ͏

  13. Copyright© M&AΫϥ΢υ ։ൃऀ͕૿͑ɺνʔϜΛ෼͚ͨ νʔϜ͕෼͔Εͨ͜ͱʹΑΓ֬ೝ؀ڥʢ͍ΘΏΔεςʔδ؀ڥʣͰಈ࡞֬ೝ͍ͨ͠λΠϛ ϯά͕ҟͳΓσϓϩΠौ଺͕ൃੜͨ͠ɻ ͦͷͨΊɺ֬ೝ؀ڥΛෳ਺࡞Δ͜ͱʹɾɾɾ

  14. Copyright© M&AΫϥ΢υ ෳ਺؀ڥ࡞Δࡍͷো֐

  15. Copyright© M&AΫϥ΢υ εϖοΫΛ͋Θͤͯෳ਺؀ڥ࡞Δखؒ ϒϥ΢βίϯιʔϧ͔Β؀ڥΛ࡞Δͷ͕ඇৗʹखؒ কདྷతʹ͞ΒʹνʔϜ͕૿͑ͨ৔߹ɺ·ͨಉ͡޻਺Λ࢖ͬͯ࡞Δख͕ؒൃੜ͢Δ ͞ΒʹฐࣾͰ͸CloudfrontͷBehaviorΛར༻ͯ͠ύε͝ͱʹ ΞϓϦέʔγϣϯͷ޲͖ઌΛมߋ͢Δॲཧ͕େྔʹ͋ͬͨɻ ؀ڥΛෳ਺࡞Δࡍʹͱͯͭ΋ͳ͍࡞ۀ΍֬ೝ͕ඞཁʹͳΔɻ

  16. Copyright© M&AΫϥ΢υ ͦ͜ͰɺAWS CDK

  17. Copyright© M&AΫϥ΢υ AWS CDKΛར༻ͯ͠؀ڥߏங Stack୯ҐͰڞ௨Խ͠ɺ؀ڥʹΑͬͯҟͳΔม਺Λ༩͑Δ͜ͱͰεϖοΫ΍֤छIPΞυϨε ͷมಈ͕Ͱ͖ΔΑ͏ʹߏங CloudfrontͷBehavior΋഑ྻͰอ࣋͠ɺCDK͔ΒҰׅͰ൓ө͞ΕΔΑ͏ʹରԠ ෳ਺؀ڥ·ͱΊͯಉ͡BehaviorΛઃఆ͢Δ͜ͱ͕Ͱ͖ΔΑ͏ʹͳͬͨɻ

  18. Copyright© M&AΫϥ΢υ ͪΐͬͱ࢒೦ͳͱ͜Ζ

  19. Copyright© M&AΫϥ΢υ AWS CDKΛར༻ͯ͠ݟ͑ͨ՝୊ • CloudFromation͕࣮ߦ͞ΕΔͨΊɺ׬ྃ·Ͱ݁ߏ͕͔͔࣌ؒΔɻ ◦ ಛʹCloudfront͸֤Edgeαʔόʔͷ൓ө·Ͱ଴͍ͬͯΔײ͡ʁͰ஗͍ • Fargate

    SpotΛ࢖͏ͨΊʹ͸L1 ConstructͰ͸͏·͘ߦ͔ͳ͔ͬͨͷͰL2ʹΑΔCfnΫϥ εΛ࢖͏ඞཁ͕͋ͬͨɻͦͷଞʹ΋݁ہCfnΫϥεͰॻ͔ͳ͍ͱࢦఆͰ͖ͳ͍΋ͷ͕ଟ͔ͬ ͨ • ϥΠϒϥϦ͕TypeScriptͷݴޠͷྑ͞Λ࢖͍੾Ε͍ͯͳ͍ ◦ ܾ·ͬͨจࣈ͔͠࢖͑ͳ͍ͳΒUnionͰఆٛͯ͠΄͍͠ɻStringʹͳ͍ͬͯΔͷͰɺ ͳʹ͕ࢦఆͰ͖Δ͔Θ͔Βͳ͍΋ͷ͕݁ߏ͋Δʢ݁ہެࣜυΩϡϝϯτΛݟͳ͚Ε͹ ࢖͑ͳ͍ʣ • CDKͷίʔυ΋ͨͩཏྻ͢Δ͚ͩͰ͸ͳ͘Stack΍Construct୯ҐΛ͏·͘ઃܭ͢Δඞཁ͕ ͋Δͱײͨ͡
  20. Copyright© M&AΫϥ΢υ ·ͱΊ • Թ͔Έͷ͋Δख࡞ۀ͔ΒIaCʹҠߦͨ͜͠ͱͰࠓޙ؀ڥ͕૿͑ͯ΋ఆٛΛ΄΅ίϐϖ Ͱ૿΍͚ͩ͢Ͱྑ͍Ϩϕϧʹͳͬͨʂ • CloudfrontͷBehavior͸ͣͬͱ՝୊ײ͕͕͋ͬͨCDKͰεοΩϦͨ͠ • ୀ۶ͳ͜ͱ͸CDKʹ΍ΒͤΑ͏ɻ

  21. Copyright© M&AΫϥ΢υ Thanks for watching this :)