Slide 1

Slide 1 text

AWS CDKͷ࠷ڧͷॻ͖ํΛ ࣮ફͯ͠ΈΔ 2023೥൛ 2023/7/8 CXࣄۀຊ෦ ࠤ౻ஐथ

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

ࣗݾ঺հ • ࠤ౻ஐथ • CXࣄۀຊ෦ ΞʔΩςΫτνʔϜ Ϛωʔδϟʔ • JAWS-UG CDKࢧ෦ ӡӦ • ڭһ໔ڐ ߴߍ/தֶ਺ֶ ৘ใ • ޷͖ͳAWSαʔϏεɿLambdaɺCDK 3 @tmk2154 tomoki10

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

ࠓ೔ͷϋογϡλά 5 ɹ #devio2023

Slide 6

Slide 6 text

໨࣍ •νϣʔΫτʔΫͱ͸ •ͳͥࠓ೔࿩͢ͷ͔ •࿩͢͜ͱͷݩωλ •ࠓճ࿩͢͜ͱ 6

Slide 7

Slide 7 text

νϣʔΫτʔΫͱ͸ ٕज़΍ઐ໳஌ࣝʹؔ͢ΔτϐοΫʹ͍ͭͯɺΤΩεύʔτ΍ ઐ໳Ո͕ࢀՃऀʹରͯ͠௚઀తʹઆ໌΍σϞϯετϨʔγϣ ϯΛߦ͍ͳ͕Βɺର࿩΍σΟεΧογϣϯΛߦ͏Πϕϯτܗ ࣜͰ͢ɻ νϣʔΫτʔΫͷಛ௃͸ɺࢀՃऀͱΤΩεύʔτͱͷؒͰର ࿩΍σΟεΧογϣϯ͕׆ൃʹߦΘΕΔ͜ͱͰ͢ɻࢀՃऀ ͸ɺ࣭໰Λͨ͠Γɺٙ໰΍ҙݟΛड़΂ͨΓ͢Δ͜ͱͰɺΤΩ εύʔτͱͷ૬ޓ࡞༻Λ௨ͯ͡ΑΓਂ͍ཧղ΍஌ࣝΛಘΔ͜ ͱ͕Ͱ͖·͢ɻ 7

Slide 8

Slide 8 text

νϣʔΫτʔΫͱ͸ ٕज़΍ઐ໳஌ࣝʹؔ͢ΔτϐοΫʹ͍ͭͯɺΤΩεύʔτ΍ ઐ໳Ո͕ࢀՃऀʹରͯ͠௚઀తʹઆ໌΍σϞϯετϨʔγϣ ϯΛߦ͍ͳ͕Βɺର࿩΍σΟεΧογϣϯΛߦ͏Πϕϯτܗ ࣜͰ͢ɻ νϣʔΫτʔΫͷಛ௃͸ɺࢀՃऀͱΤΩεύʔτͱͷؒͰର ࿩΍σΟεΧογϣϯ͕׆ൃʹߦΘΕΔ͜ͱͰ͢ɻࢀՃऀ ͸ɺ࣭໰Λͨ͠Γɺٙ໰΍ҙݟΛड़΂ͨΓ͢Δ͜ͱͰɺΤΩ εύʔτͱͷ૬ޓ࡞༻Λ௨ͯ͡ΑΓਂ͍ཧղ΍஌ࣝΛಘΔ͜ ͱ͕Ͱ͖·͢ɻ 8

Slide 9

Slide 9 text

͍ͭͰ΋/ͲΜͳ࣭໰Ͱ΋ Welcome!! 9

Slide 10

Slide 10 text

CDKͬͯԿʁ ͿͬͪΌ͚ࠓ೔ϊϦͰདྷͨΜͰ 10 ྫ͑͹…

Slide 11

Slide 11 text

࣭໰ CDK࢖ͬͨ͜ͱ͕͋Δਓʁ ɹɹɹ1. ࢓ࣄͰ2೥Ҏ্࢖͍ͬͯΔ ɹɹɹ2. ࢓ࣄͰ1೥Ҏ্࢖͍ͬͯΔ ɹɹɹ3. ϋϯζΦϯ΍ۀ຿֎Ͱࢼ͍ͯ͠Δ ɹɹɹ4. ࢖ͬͨ͜ͱ͕ͳ͍ 11

Slide 12

Slide 12 text

ͳͥࠓ೔࿩͢ͷ͔ 12 ੲͷࢿྉ

Slide 13

Slide 13 text

2021೥ͷࢿྉͰݕ౼ࣄ߲͸ྑ͍͕౴͑͸ݹ͘ͳ͖ͬͯͨ ͳͥࠓ೔࿩͢ͷ͔ 13

Slide 14

Slide 14 text

ࠓճ࿩͢͜ͱͷݩωλ 14

Slide 15

Slide 15 text

ࢿྉ΋Ξοϓϩʔυ͞Εͯ·͢ 15

Slide 16

Slide 16 text

͜ͷ໘ന͞఻ΘͬͯΔͷ͔ͳ͋ʁ ΋ͬͱ޿Ί͍ͨʂ 16

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

αϯϓϧϦϙδτϦ https://github.com/tomoki10/cdk-best-design-2023 18

Slide 19

Slide 19 text

جຊతͳCDKͷߏ੒ͷ͓͞Β͍ 19 DELKTPO 03 ŠBQQPQUJPO FOUSZQPJOU

Slide 20

Slide 20 text

جຊతͳCDKͷߏ੒ͷ͓͞Β͍ 20

Slide 21

Slide 21 text

CDKͰ͸ա౓ͳந৅ԽΛආ͚Δ खଓܕ͕ͩએݴܕతʹॻ͘ 21

Slide 22

Slide 22 text

CDKͰ͸ա౓ͳந৅ԽΛආ͚Δ खଓܕ͕ͩએݴܕతʹॻ͘
 ҎԼ͸ۃ୺ͳѱ͍ྫ 22

Slide 23

Slide 23 text

CDKͰ͸ա౓ͳந৅ԽΛආ͚Δ Ifɺfor΋ۃྗॻ͔ͳ͍ɺ؀ڥࠩҟ͸جຊύϥϝʔλͰઃఆ
 ։ൃ/ຊ൪ؒͰͷϦιʔεଘࡏͷࠩҟ΋ۃྗ཈͑Δ※ 23 ※ ʮTwelve-Factor App ։ൃ/ຊ൪Ұகʯhttps://12factor.net/ja/dev-prod-parity

Slide 24

Slide 24 text

StackͰͳ͘ConstructͰ෼͚Δ 24 PropsʹΑΔStackؒࢀর͕ݩڟͰCDK࢖༻ऀͷ
 ΄΅100%͕ϋϚΔ᠘ ࢖͍ͬͯͳ͍ ͋Δ CDKͷΫϩεελοΫؒࢀরͰ 
 ٧·ͬͨ͜ͱ͸͋Γ·͔͢ʁ(Սۭ) https://dev.classmethod.jp/articles/aws-cdk-props-cross-stack-reference- problem-and-handle/

Slide 25

Slide 25 text

StackͰͳ͘ConstructͰ෼͚Δ 25

Slide 26

Slide 26 text

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 ʜ ʜ - ந৅Խ ରԠ ରԠ ந৅Խ

Slide 27

Slide 27 text

Construct ͸ L2(+α)ΛϝΠϯͰ࢖͏ 27 L2 + Security or Governance or Best Setting Platform Team΍Security TeamͳͲ͕ਪ঑ઃఆΛॻ͖ɺࢀর࣮͠૷

Slide 28

Slide 28 text

؀ڥ͝ͱͷࠩ෼͸஋ΦϒδΣΫτΛ࢖͏ 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Ͱ؀ڥࠩ෼Λઃఆ

Slide 29

Slide 29 text

؀ڥ͝ͱͷࠩ෼͸஋ΦϒδΣΫτΛ࢖͏ 29 parameter.ts bin/cdk-best-design-2023.ts

Slide 30

Slide 30 text

Stack ఆٛͷग़͠෼͚ 30

Slide 31

Slide 31 text

Stack ఆٛͷग़͠෼͚ 31

Slide 32

Slide 32 text

ςετΛͲ͜·Ͱ΍Δ͔ 32 • Snapshot Test
 
 CloudFormationςϯϓϨʔτΛอଘ͠ɺࠩ෼֬ೝΛߦ͑Δ • GoodɿCDKΞοϓσʔτ࣌ͷมߋࠩ෼Λ֬ೝͰ͖ͯ҆৺ • BadɿS3ͳͲΞηοτͰ૝ఆҎ্ʹมߋࠩ෼͕Ͱ͖ΔͷͰ཈੍͕͍Δ

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

ςετΛͲ͜·Ͱ΍Δ͔ 34 • Fine-grained Assertions
 
 CloudFormation্ͷϦιʔε͕૝ఆͨ͠ঢ়ଶ͔֬ೝͰ͖Δ • Goodɿ੍ޚߏจΛ࢖͏৔߹ʹಈ࡞֬ೝ͕Ͱ͖Δ • BadɿL2ϕʔεͰίʔυΛએݴతʹॻ͍͍ͯΕ͹ͦ΋ͦ΋ෆཁͳ৔߹΋ଟ͍

Slide 35

Slide 35 text

ςετΛͲ͜·Ͱ΍Δ͔ 35 • Integration Test (Alpha)
 
 ϦιʔεΛ࣮ࡍͷΞΧ΢ϯτʹσϓϩΠͯ͠ɺσϓϩΠՄೳ͔ͷ֬ೝ΍
 σϓϩΠޙʹHTTPSϦΫΤετͷૄ௨֬ೝͳͲ͕Ͱ͖Δ
 CDKͷ಺෦࣮૷Ͱओʹ࢖ΘΕ͍ͯΔ • Goodɿ࣮ࡍͷ؀ڥͰ૝ఆͨ͠ಈ࡞Λ͢Δ͔֬ೝՄೳ • BadɿσϓϩΠ͕͋ΔͷͰςετύλʔϯ͕ଟ͍ͱςετ͕࣌ؒ௕͘ͳΔ

Slide 36

Slide 36 text

ςετΛͲ͜·Ͱ΍Δ͔ 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

Slide 37

Slide 37 text

NodejsFunctionΛ࢖͓͏ҕһձ 37 LambdaͰNodejsΛ࢖͏ࡍͷศརπʔϧ͕ἧ͍ͬͯΔ L2+͙Β͍ͷബ͍Construct
 ҎԼ͸ར఺ͷҰ෦ • όϯυϧ͕؆୯ɻesbuildΛೖΕΔ͚ͩ
 distσΟϨΫτϦͳͲதؒͷϑΝΠϧஔ͖৔΋ෆཁ • HotswapͰ࠷଎ͷσϓϩΠʢ਺ඵͰσϓϩΠ😆 ٳΉՋͳ͠😢ʣ • BundlingΦϓγϣϯͷcommandHooksͰ೚ҙίϚϯυϑοΫͳͲ͕Մೳʂ
 ͜ͷϑΝΠϧ΋͍ͭͰʹLambdaʹೖΕ͍ͨͱ͔΋OK • awsSdkConnectionReuse ͰTCP઀ଓͷ࢖͍ճ͠ΛαΫοͱઃఆ

Slide 38

Slide 38 text

ϞϊϨϙ͔ɺγϯάϧϨϙ͔ 38 ͓લΑΓ·্ͩͷੈք͕͋Δʂ 💦 ͳΜʜͩͱʜ

Slide 39

Slide 39 text

ϞϊϨϙ͔ɺγϯάϧϨϙ͔ 39 ϦϙδτϦʢϞϊϨϙʣ

Slide 40

Slide 40 text

ϞϊϨϙ͔ɺγϯάϧϨϙ͔ 40 ϦϙδτϦ ϦϙδτϦ ϦϙδτϦ

Slide 41

Slide 41 text

એ఻ 41 དྷि$%,ࢧ෦ͰΠϕϯτ΍Γ·͢ʂ ਫ ʙ https://jawsug-cdk.connpass.com/

Slide 42

Slide 42 text

Ξϯέʔτ͓ئ͍͠·͢ 42 https://forms.gle/Upi2i5PsMTEUyJ6F8 ຬ଍౓্ҐͷηογϣϯΛޙ೔ϒϩάͰެ։༧ఆʂ ճ౴΁ͷ͝ڠྗΛΑΖ͓͘͠ئ͍͠·͢ɻ

Slide 43

Slide 43 text

͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ 43