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

AWS CDKの最強の書き方を実践してみる 2023年版/practice-the-stron...

tomoki10
July 08, 2023

AWS CDKの最強の書き方を実践してみる 2023年版/practice-the-strongest-writing-method-of-aws-cdk-2023-edition

DevelopersIO 2023のイベントで登壇した際の内容です。

tomoki10

July 08, 2023
Tweet

More Decks by tomoki10

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ • ࠤ౻ஐथ • CXࣄۀຊ෦ ΞʔΩςΫτνʔϜ Ϛωʔδϟʔ • JAWS-UG CDKࢧ෦

    ӡӦ • ڭһ໔ڐ ߴߍ/தֶ਺ֶ ৘ใ • ޷͖ͳAWSαʔϏεɿLambdaɺCDK 3 @tmk2154 tomoki10
  2. ࠓճ࿩͢͜ͱʢҰ୴঺հʣ ҎԼͷτϐοΫ͔ΒԿݸ͔࿩͢ 4 1. جຊతͳCDKͷߏ੒ͷ͓͞Β͍ 2. CDKͰ͸ա౓ͳந৅ԽΛආ͚Δ 3. StackͰͳ͘ConstructͰ෼͚Δ 4.

    Construct ͸ L2(+α)ΛϝΠϯͰ࢖͏ 5. ؀ڥ͝ͱͷࠩ෼͸஋ΦϒδΣΫτΛ࢖͏ 6. Stackఆٛͷग़͠෼͚ 7. ςετΛͲ͜·Ͱ΍Δ͔ 8. NodejsFunctionΛ࢖͓͏ҕһձ 9. ϞϊϨϙ͔ɺγϯάϧϨϙ͔
  3. ࠓճ࿩͢͜ͱ ҎԼͷτϐοΫ͔ΒԿݸ͔࿩͢ 17 1. جຊతͳCDKͷߏ੒ͷ͓͞Β͍ 2. CDKͰ͸ա౓ͳந৅ԽΛආ͚Δ 3. StackͰͳ͘ConstructͰ෼͚Δ 4.

    Construct ͸ L2(+α)ΛϝΠϯͰ࢖͏ 5. ؀ڥ͝ͱͷࠩ෼͸஋ΦϒδΣΫτΛ࢖͏ 6. Stackఆٛͷग़͠෼͚ 7. ςετΛͲ͜·Ͱ΍Δ͔ 8. NodejsFunctionΛ࢖͓͏ҕһձ 9. ϞϊϨϙ͔ɺγϯάϧϨϙ͔
  4. StackͰͳ͘ConstructͰ෼͚Δ 24 PropsʹΑΔStackؒࢀর͕ݩڟͰCDK࢖༻ऀͷ
 ΄΅100%͕ϋϚΔ᠘ ࢖͍ͬͯͳ͍  ͋Δ  CDKͷΫϩεελοΫؒࢀরͰ 


    ٧·ͬͨ͜ͱ͸͋Γ·͔͢ʁ(Սۭ) https://dev.classmethod.jp/articles/aws-cdk-props-cross-stack-reference- problem-and-handle/
  5. L1,2,3 Constructͷ͓͞Β͍ 26 $POTUSVDUͷ-BZFSͷΠϝʔδ - - - &$4 $%, $POTUSVDU

    &$3 $%, $POTUSVDU 71$ $%, $POTUSVDU &$4$GO $POTUSVDU &$4 $%, $POTUSVDU &$4$GO $POTUSVDU &$4 $MPVE 'PSNBUJPO &$4 1BUUFSOT &$4 $MPVE 'PSNBUJPO ʜ ʜ - ந৅Խ ରԠ ରԠ ந৅Խ
  6. Construct ͸ L2(+α)ΛϝΠϯͰ࢖͏ 27 L2 + Security or Governance or

    Best Setting Platform Team΍Security TeamͳͲ͕ਪ঑ઃఆΛॻ͖ɺࢀর࣮͠૷
  7. ؀ڥ͝ͱͷࠩ෼͸஋ΦϒδΣΫτΛ࢖͏ 28 cdk.json: { "app": "npx ts-node --prefer-ts-exts bin/cdk-best-design-2023.ts”, "context":

    { "projectName": "hoge-fuga", "dev": { "envName": "dev", "env": { "account": "123456789012", "region": "ap-northeast-1" } }, "stg": { "envName": “stg", ... } ... } } σϓϩΠ࣌ͷίϚϯυɿ cdk deploy -c environment=dev ~~ ੲͷϕετϓϥΫςΟεɺcdk.jsonͰ؀ڥࠩ෼Λઃఆ
  8. assetsͷิ଍ʢCDKͷཪଆͷجຊతͳಈ͖ʣ 33 Client CI/CD Env Source code AWS CloudFormation AWS

    account OR AWS CDK Cfn Template Stack (Resource State) Cfn Template 1.Synthesize S3 Bucket assets 2.Upload 3.Deploy 5.Generate AWS Lambda Amazon API Gateway 6.API Call 4.Pull
  9. ςετΛͲ͜·Ͱ΍Δ͔ 36 • cdk-nag
 
 AWS΍NIST.800.53ɺPCI DSSͳͲͷηΩϡϦςΟɾίϯϓϥΠΞϯεϧʔϧʹ
 ४ڌ͍ͯ͠Δ͔֬ೝͰ͖Δπʔϧ • GoodɿσϓϩΠલݕূͰηΩϡϦςΟͷγϑτϨϑτ͕࣮ݱͰ͖Δ

    • Badɿޡݕ஌΋ଟ͘཈੍͕݁ߏඞཁΒ͍͠ • pdk-nag※
 cdk-nagͷϥΠτ൛APAC(ओʹΦʔετϥϦΞ)ͷAWS Prototyping Team͕࡞੒ ※https://aws.github.io/aws-prototyping-sdk/developer_guides/pdk-nag/index.html
  10. NodejsFunctionΛ࢖͓͏ҕһձ 37 LambdaͰNodejsΛ࢖͏ࡍͷศརπʔϧ͕ἧ͍ͬͯΔ L2+͙Β͍ͷബ͍Construct
 ҎԼ͸ར఺ͷҰ෦ • όϯυϧ͕؆୯ɻesbuildΛೖΕΔ͚ͩ
 distσΟϨΫτϦͳͲதؒͷϑΝΠϧஔ͖৔΋ෆཁ • HotswapͰ࠷଎ͷσϓϩΠʢ਺ඵͰσϓϩΠ😆

    ٳΉՋͳ͠😢ʣ • BundlingΦϓγϣϯͷcommandHooksͰ೚ҙίϚϯυϑοΫͳͲ͕Մೳʂ
 ͜ͷϑΝΠϧ΋͍ͭͰʹLambdaʹೖΕ͍ͨͱ͔΋OK • awsSdkConnectionReuse ͰTCP઀ଓͷ࢖͍ճ͠ΛαΫοͱઃఆ