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

AWS CDKのチーム開発で採用したこと、諦めたこと。

mazyu36
July 12, 2023

AWS CDKのチーム開発で採用したこと、諦めたこと。

mazyu36

July 12, 2023
Tweet

More Decks by mazyu36

Other Decks in Technology

Transcript

  1. ͋Γ͕ͪͳʢʁʣ νʔϜ։ൃͷγνϡΤʔγϣϯ CDK stg dev prod InfraB InfraA Infra Team

    infra Frontend Backend End User Develper Team ΠϯϑϥνʔϜͰෳ਺ਓͰ$%, Λ։ൃ͍ͨ͠ɻ ඞཁͳ΋ͷᶃɿෳ਺ਓͰ෼୲Մೳ ͳϓϩδΣΫτߏ੒ɾ։ൃϑϩʔ $%,࣮૷࣌͸ଞνʔϜʹӨڹΛ༩͑ͣʹ 
 ࣗ༝ʹݕূ͍ͨ͠ɻ ඞཁͳ΋ͷᶄɿΠϯϑϥνʔϜઐ༻ͷݕূ؀ڥ EFWTUHQSPE͸ΞϓϦ։ൃνʔϜ΍Ϣʔβʔ͕ ࢖͍ͬͯΔͷͰɺޡͬͨมߋ͸ආ͚͍ͨɻ ඞཁͳ΋ͷᶅɿ҆શʹมߋΛEFQMPZͰ͖Δ࢓૊Έ 
  2. ߟ͑ͨνʔϜ։ൃͷશମ૾ InfraB Frontend Backend End User InfraA feature_hoge feature_fuga main

    stg CodeBuild (build, test, diff) CodeBuild (deploy) Manual Approval dev prod npx cdk deploy --all --concurrency 3 --require-approval never Develper Team Infra Team merge npx cdk deploy -c env=infraA npx cdk deploy -c env=infraB infraA infraB ᶄݕূ؀ڥΛ࢖͍ 
 ɹͳ͕Β࣮૷ɻ ᶅγϯϓϧͳ$*$%ύΠϓϥΠϯͰ 
 ɹ֤؀ڥʹ൓өʢOPU$%,1JQFMJOFTʣɻ w ͳΔ΂͘γϯϓϧͳ࢓૊ΈͰɺॳ৺ऀͰ΋ΩϟονΞοϓ͠΍͘͢͢Δʢ$%,ΤΩεύʔτ͸ଟ͘ͳ͍ʣɻ w ͳΔ΂҆͘৺ͯ͠࡞ۀΛߦ͑ΔΑ͏ʹ͢ΔʢϑΝΠϧ෼ׂʹΑΔڝ߹๷ࢭɺઐ༻؀ڥͰͷࣗ༝ͳݕূʜFUDʣɻ  ᶃߏ଄Խͨ͠ϓϩδΣΫτߏ੒ɺ 
 ɹ։ൃϑϩʔͰ։ൃΛ෼୲ɻ
  3. ߟ͑ͨνʔϜ։ൃͷશମ૾ InfraB Frontend Backend End User InfraA feature_hoge feature_fuga main

    stg CodeBuild (build, test, diff) CodeBuild (deploy) Manual Approval dev prod npx cdk deploy --all --concurrency 3 --require-approval never Develper Team Infra Team merge npx cdk deploy -c env=infraA npx cdk deploy -c env=infraB infraA infraB  ᶃߏ଄Խͨ͠ϓϩδΣΫτߏ੒ɺ 
 ɹ։ൃϑϩʔͰ։ൃΛ෼୲ɻ
  4. ϓϩδΣΫτ͸ϑΝΠϧΛ෼ׂͯ͠ߏ଄Խ͢Δ͜ͱͰɺ෼୲Λ͠΍͘͢͢Δ w 4UBDL͸ۃྗ෼ׂͤͣɺ$POTUSVDUͰϑΝΠϧΛ෼ׂ˞ w ؀ڥґଘύϥϝʔλ͸ΦϒδΣΫτʢUTʣͰ؅ཧ˞ 
 "QQ$POTUSVDU͝ͱʹରԠ͢Δ$PO fi HUTΛ࡞੒͢Δɻ w

    UFTU 'JOFHSBJOFE"TTFSUJPOT ͸$POTUSVDU୯ҐͰ෼ׂ࣮͠૷ɻ ˞͸#-&"W౳Ͱ΋࠾༻͞ΕɺׂͱҰൠతʹͳ͖ͬͯͨʢ͸ͣʣ  ᵓᴷᴷCJO ᴹᵓᴷᴷBQQUT ᴹᵋᴷᴷDPO fi H ᴹᵋᴷᴷFOW$PO fi HUT ᵓᴷᴷMJC ᴹᵓᴷᴷBQQ4UBDLUT ᴹᵓᴷᴷDPOTUSVDUT ᴹᴹᵓᴷᴷOFUXPSLUT ᴹᴹᵋᴷᴷTFSWFSUT ᴹᵋᴷᴷDPO fi H ᴹᵓᴷᴷOFUXPSL$PO fi HUT ᴹᵋᴷᴷTFSWFS$PO fi HUT ᵓᴷᴷUFTU ᴹᵓᴷᴷ@@TOBQTIPUT@@ ᴹᴹᵋᴷᴷTOBQTIPUUFTUUTTOBQ ᴹᵓᴷᴷTOBQTIPUUFTUUT ᴹᵓᴷᴷDPOTUSVDUT ᴹᴹᵓᴷᴷOFUXPSLUFTUUT ᴹᴹᵋᴷᴷTFSWFSUFTUUT ᴹᵋᴷᴷDSFBUF5FNQMBUFUT ᵓᴷᴷDELDPOUFYUKTPO ᵓᴷᴷDELKTPO ᵋᴷᴷUTDPO fi HKTPO #-&"։ൃνʔϜֶ͕Μͩ"84$%,ͷ։ൃϓϥΫςΟε೥൛ "QQ "QQͷύϥ ϝʔλ 4UBDL $POTUSVDU $POTUSVDUͷ ύϥϝʔλ $POTUSVDUͷ ςετ ˞4UBDLͷύϥϝʔλ΋ඞཁͳ৔߹͸࡞੒ 
  5. ։ൃͷྲྀΕ w $POTUSVDU୯ҐͰ։ൃΛ෼୲ɻ w ࣮૷͕ऴΘͬͨΒ13Λ࡞੒͠ɺNBJOʹϚʔδ͢Δɻ  ᵓᴷᴷCJO ᴹᵓᴷᴷBQQUT ᴹᵋᴷᴷDPO fi

    H ᴹᵋᴷᴷFOW$PO fi HUT ᵓᴷᴷMJC ᴹᵓᴷᴷBQQ4UBDLUT ᴹᵓᴷᴷDPOTUSVDUT ᴹᴹᵓᴷᴷOFUXPSLUT ᴹᴹᵋᴷᴷTFSWFSUT ᴹᵋᴷᴷDPO fi H ᴹᵓᴷᴷOFUXPSL$PO fi HUT ᴹᵋᴷᴷTFSWFS$PO fi HUT ᵓᴷᴷUFTU ᴹᵓᴷᴷ@@TOBQTIPUT@@ ᴹᴹᵋᴷᴷTOBQTIPUUFTUUTTOBQ ᴹᵓᴷᴷTOBQTIPUUFTUUT ᴹᵓᴷᴷDPOTUSVDUT ᴹᴹᵓᴷᴷOFUXPSLUFTUUT ᴹᴹᵋᴷᴷTFSWFSUFTUUT ᴹᵋᴷᴷDSFBUF5FNQMBUFUT ᵓᴷᴷDELDPOUFYUKTPO ᵓᴷᴷDELKTPO ᵋᴷᴷUTDPO fi HKTPO InfraB InfraA feature_network feature_server Infra Team main merge ఆৗతʹଘࡏ͢ΔͷNBJOϒϥϯνͷΈɻϚʔδޙʹ $*$%ύΠϓϥΠϯͰEFWTUHQSPEʹ൓өɻ ϒϥϯνΛ੾ͬͯ୲౰͢Δ$POTUSVDU $PO fi H5FTUΛ࣮૷ 
  6. ߟ͑ͨνʔϜ։ൃͷશମ૾ InfraB Frontend Backend End User InfraA feature_hoge feature_fuga main

    stg CodeBuild (build, test, diff) CodeBuild (deploy) Manual Approval dev prod npx cdk deploy --all --concurrency 3 --require-approval never Develper Team Infra Team merge npx cdk deploy -c env=infraA npx cdk deploy -c env=infraB infraA infraB ᶄݕূ؀ڥΛ࢖͍ 
 ɹͳ͕Β࣮૷ɻ 
  7. $%,։ൃ࣌͸ݕূ؀ڥΛ࢖༻͠ɺίϚϯυͰݕূ࣮૷ DELίϚϯυͷద༻ઌΛDPOUFYUͰॊೈʹ੾Γସ͑ͳ͕Βɺݕূ͓Αͼ࣮૷͢Δɻ  ᵓᴷᴷCJO ᴹᵓᴷᴷBQQUT ᴹᵋᴷᴷDPO fi H ᴹᵋᴷᴷFOW$PO fi

    HUT // context͔ΒσϓϩΠର৅ͷ؀ڥΛऔಘ const envName = app.node.tryGetContext('env'); // ରԠ͢Δઃఆ஋Λऔಘ const envConfig: EnvConfig = createEnvConfig(envName) // StackΛ࡞੒ new AppStack(app, 'AppStack', { stackName: `${envName}-App-Stack`, env: envConfig, terminationProtection: false, envName: envName }) InfraA npx cdk deploy -c env=infraA infraA ؀ڥ໊ʢίϯςΩετ஋ʣΛϑΝΫτϦؔ਺ʹ౉͠ɺ ରԠ͢ΔύϥϝʔλͷΦϒδΣΫτΛऔಘɻ 
 ˞DELKTPOʹΑΔύϥϝʔλ੾ସ͸ߦΘͳ͍ɻ औಘͨ͠ύϥϝʔλΛઃఆɻ·ͨ؀ڥ໊ʢFOW/BNFʣ ͸4UBDL$POTUSVDUʹҾ͖ܧ͗࢖༻͢Δɻ جຊ͸ࣗ෼༻ͷ؀ڥͰEFQMPZͳͲ ࣗ༝ʹݕূ͠ͳ͕Β։ൃɻ dev npx cdk diff -c env=dev EFWTUHQSPEͷEJ ff औಘ͸ڐՄɻ ։ൃதʹదٓ֬ೝ 
  8. ύϥϝʔλͷ੾Γସ͑ʹ͍ͭͯ ίϚϯυͰ؀ڥ໊Λࢦఆ͠ɺύϥϝʔλΛ੾Γସ͑Δ ํ๏͸*B$ຊʢˠʣͰΞϯνύλʔϯͱ͞Ε͍ͯΔɻ ʢखೖྗͩͱϛεΔՄೳੑ͕͋Δ͔Βʣ Q"OUJQBUUFSO.BOVBM4UBDL1BSBNFUFST   ᵓᴷᴷCJO ᴹᵓᴷᴷBQQUT ᴹᵋᴷᴷDPO

    fi H ᴹᵋᴷᴷFOW$PO fi HUT export interface EnvConfig { account: string, region: string } export function createEnvConfig(envName: string): EnvConfig { switch (envName) { case 'dev': return { account: '123456789012', region: 'ap-northeast-1' } case 'stg': return { account: '123456789012', region: 'ap-northeast-1' } case 'prod': return { account: '123456789012', region: 'ap-northeast-1' } case 'infraA': return { account: '123456789012', region: 'ap-northeast-1' } case 'infraB': return { account: '123456789012', region: 'ap-northeast-1' } default: throw new Error( `EnvConfig does not exist. envName:${envName}` ) } } ରࡦɿଘࡏ͠ͳ͍؀ڥΛࢦఆͨ͠৔߹͸Τϥʔʹ͢Δ w ؀ڥґଘύϥϝʔλΛऔಘ͢ΔϑΝΫτϦؔ਺Λ࣮૷ɻ 
 TXJUDIจͰଘࡏ͠ͳ͍؀ڥ͕ࢦఆ͞Εͨ৔߹͸Τϥʔʹ͢Δɻ 
 ˞UZQP౳ʹΑΔ༧ظͤ͵σϓϩΠΛ๷ࢭ ରࡦɿ*".ϙϦγʔʹΑΔޡσϓϩΠ๷ࢭ w EFWTUHQSPEʹ௚઀σϓϩΠͰ͖ͳ͍Α͏ϙϦγʔͰറΔɻ 
 ˞ޡͬͯຊ൪؀ڥʹ൓өͪ͠Ό͏ͳͲΛ๷͙ɻ 
 ɹͨͩ͠DELEJ ff ͷݖݶ͸෇༩͓ͯ͘͠ɻ ύϥϝʔλͷ JOUFSGBDFΛఆٛɻ ଘࡏ͠ͳ͍FOW/BNF͸Τϥʔ FOW/BNFʹԠ͡ ͯΦϒδΣΫτΛ ࡞੒ͯ͠ฦ٫ 
  9. ߟ͑ͨνʔϜ։ൃͷશମ૾ InfraB Frontend Backend End User InfraA feature_hoge feature_fuga main

    stg CodeBuild (build, test, diff) CodeBuild (deploy) Manual Approval dev prod npx cdk deploy --all --concurrency 3 --require-approval never Develper Team Infra Team merge npx cdk deploy -c env=infraA npx cdk deploy -c env=infraB infraA infraB ᶅγϯϓϧͳ$*$%ύΠϓϥΠϯͰ 
 ɹ֤؀ڥʹ൓өʢOPU$%,1JQFMJOFTʣɻ 
  10. $PEFγϦʔζͰಠࣗʹ$*$%ύΠϓϥΠϯΛߏங ίϚϯυ࣮ߦΛࣗಈԽͨ͠γϯϓϧͳ΋ͷΛ࢖͏͜ͱ͕ଟ͍ɻ$PEFγϦʔζΛ࢖͏ཧ༝͸ҎԼɻ w "84ܦݧऀͰ͋Ε͹େ఍࢖ͬͨ͜ͱ͕͋ΔͨΊɻ w "84֎ͷαʔϏεΛ࢖༻͢Δͷ͸େਓͷࣄ৘తʹ೉͍͜͠ͱ΋ଟ͍ͨΊɻ CodeCommit stg CodeBuild (build,

    test, diff) CodeBuild (deploy) Manual Approval dev CodeBuild (build, test, diff) CodeBuild (deploy) Manual Approval prod CodeBuild (build, test, diff) CodeBuild (deploy) Manual Approval main npx cdk deploy -c env=dev npx cdk deploy -c env=stg npx cdk deploy -c env=prod NBJOϒϥϯνͷΈͰӡ༻ɻ 
 σϓϩΠ࣌ʹ؀ڥΛࢦఆ͢Δ͜ͱ Ͱύϥϝʔλ UT ʹΑΓ੾Γସ͑ ΒΕΔͨΊɻ NBJOʹϚʔδ͢Δͱશ؀ڥ෼ͷ $*$%ύΠϓϥΠϯ͕૸Δɻ Ϗϧυςετ׬ྃޙ͸DELEJ ff Λ࣮ࢪɻखಈঝೝ࣌ʹ มߋࠩ෼͕֬ೝՄɺ͔ͭมߋࠩ෼ͷཤྺΛ࢒ͤΔɻ EFQMPZઌ͸DPOUFYUͰࢦఆɻ ʢ$PEF#VJMEͷ؀ڥม਺ܦ༝ʹ͢Δ͜ͱ͕ଟ͍ʣ ͜ͷํࣜͷΠϚΠνͳ఺ɻ  ߋ৽͕ͳ͍؀ڥͷ$*$%΋૸Δɻ 
 ˠৗʹ࠷৽ͷίʔυ͕ద༻͞Ε͍ͯΔͱ ΋ݴ͑ΔͷͰڐ༰͢Δ͜ͱ͕ଟ͍ɻ  ຖճશ؀ڥ෼ͷखಈঝೝΛߦΘͳ͍ͱ͍ ͚ͳ͍ͷ͕ɺগ͠໘౗ɻ 
 ˠύΠϓϥΠϯࣗମΛݮΒ͢͜ͱ΋͋Δ ʢৄࡉ͸࣍εϥΠυʣ 
  11. $*$%ύΠϓϥΠϯͷҰຊԽ EFWTUHQSPEͷ4UBDLΛ௚઀"QQʹఆٛ͠ɺͭͷύΠϓϥΠϯͰσϓϩΠՄೳʹ͢Δɻ ·ͨɺσϓϩΠ࣌͸DPODVSSFODZΛ࢖͍ߴ଎Խ͢Δɻ CodeCommit stg CodeBuild (build, test, diff) CodeBuild

    (deploy) Manual Approval dev prod main npx cdk deploy --all --concurrency 3 --require-approval never // ------ dev ------- const devEnvConfig: EnvConfig = createEnvConfig(devEnvName) const devAppStack = new AppStack(app, `${devEnvName}AppStack`, { stackName: `${devEnvName}AppStack`, env: devEnvConfig, envName: devEnvName, terminationProtection: true }) // ------ stg ------- const stgEnvConfig: EnvConfig = createEnvConfig(stgEnvName) const stgAppStack = new AppStack(app, `${stgEnvName}AppStack`, { stackName: `${stgEnvName}AppStack`, env: stgEnvConfig, envName: stgEnvName, terminationProtection: true }) // ------ prod ------- const prodEnvConfig: EnvConfig = createEnvConfig(prodEnvName) const prodAppStack = new AppStack(app, `${prodEnvName}AppStack`, { stackName: `${prodEnvName}AppStack`, env: prodEnvConfig, envName: prodEnvName, terminationProtection: true }) DPODVSSFODZͰര଎ฒྻσϓϩΠ EFWTUHQSPEͷ4UBDL͸௚ ઀ఆٛ͠ɺͭͷύΠϓϥΠϯ ͰσϓϩΠͰ͖ΔΑ͏ʹ͢Δɻ DPODVSSFODZͰߴ଎Խ ༨ஊ QSPEͳͲ࡟আͯ͠͸͍͚ͳ ͍4UBDL͸࡟আอޢΛඞͣߦ͏ɻ ࣄނͬͨܦݧ͋Γʜ 
  12. ߟ͑ͨνʔϜ։ൃͷશମ૾ʢ࠶ܝʣ InfraB Frontend Backend End User InfraA feature_hoge feature_fuga main

    stg CodeBuild (build, test, diff) CodeBuild (deploy) Manual Approval dev prod npx cdk deploy --all --concurrency 3 --require-approval never Develper Team Infra Team merge npx cdk deploy -c env=infraA npx cdk deploy -c env=infraB infraA infraB ᶃߏ଄Խͨ͠ϓϩδΣΫτߏ੒ɺ 
 ɹ։ൃϑϩʔͰ։ൃΛ෼୲ɻ ᶄݕূ؀ڥΛ࢖͍ 
 ɹͳ͕Β࣮૷ɻ ᶅγϯϓϧͳ$*$%ύΠϓϥΠϯͰ 
 ɹ֤؀ڥʹ൓өʢOPU$%,1JQFMJOFTʣɻ w ͳΔ΂͘γϯϓϧͳ࢓૊ΈͰɺॳ৺ऀͰ΋ΩϟονΞοϓ͠΍͘͢͢Δʢ$%,ΤΩεύʔτ͸ଟ͘ͳ͍ʣɻ w ͳΔ΂҆͘৺ͯ͠࡞ۀΛߦ͑ΔΑ͏ʹ͢ΔʢϑΝΠϧ෼ׂʹΑΔڝ߹๷ࢭɺઐ༻؀ڥͰͷࣗ༝ͳݕূʜFUDʣɻ