Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
AWS CDKの最強の書き方を実践してみる 2023年版/practice-the-stron...
Search
tomoki10
July 08, 2023
Technology
4
6.6k
AWS CDKの最強の書き方を実践してみる 2023年版/practice-the-strongest-writing-method-of-aws-cdk-2023-edition
DevelopersIO 2023のイベントで登壇した際の内容です。
tomoki10
July 08, 2023
Tweet
Share
More Decks by tomoki10
See All by tomoki10
Classmethod流のPlatform Engineering / classmethod-platform-engineering-devio2024
tomoki10
1
1.2k
AWS CDK Conference Japan 2024 OP
tomoki10
0
630
TypeScripterに送るIaCの世界への招待〜AWS CDKと共に〜/inviting-typescripters-to-the-world-of-iac-with-aws-cdk
tomoki10
0
700
AWSでもBuildpacksを使ってDockerfileレスに出来るのか!?/can-i-use-buildpacks-to-go-dockerfile-less-in-aws
tomoki10
0
2.8k
ECS on Fargate のセキュリティ対策は何をやるべき?開発者目線で考える/security-for-ecs-on-fargate-secjawsdays
tomoki10
14
11k
CDK支部のこれまでとこれから / jaws-ug-cdk-past-and-future
tomoki10
1
860
AWS CDKでECS on FargateのCI/CDを実現する際の理想と現実 / ideal-and-reality-when-implementing-cicd-for-ecs-on-fargate-with-aws-cdk
tomoki10
21
26k
AWSCDKを通してAWSを学ぶ/learn AWS through AWS CDK
tomoki10
0
3.4k
それでも俺はAWS CDKが作るリソースに物理名を付けたい 〜CDKのベストプラクティスは本当にベストなのか〜 / AWS CDK resource name can be a physical name
tomoki10
1
7.7k
Other Decks in Technology
See All in Technology
OCI 運用監視サービス 概要
oracle4engineer
PRO
0
4.8k
ノーコードデータ分析ツールで体験する時系列データ分析超入門
negi111111
0
430
The Rise of LLMOps
asei
9
1.8k
Zennのパフォーマンスモニタリングでやっていること
ryosukeigarashi
0
250
Taming you application's environments
salaboy
0
200
Storybook との上手な向き合い方を考える
re_taro
5
1.1k
飲食店データの分析事例とそれを支えるデータ基盤
kimujun
0
210
日経電子版のStoreKit2フルリニューアル
shimastripe
1
150
Amplify Gen2 Deep Dive / バックエンドの型をいかにしてフロントエンドへ伝えるか #TSKaigi #TSKaigiKansai #AWSAmplifyJP
tacck
PRO
0
390
Making your applications cross-environment - OSCG 2024 NA
salaboy
0
200
100 名超が参加した日経グループ横断の競技型 AWS 学習イベント「Nikkei Group AWS GameDay」の紹介/mediajaws202411
nikkei_engineer_recruiting
1
170
インフラとバックエンドとフロントエンドをくまなく調べて遅いアプリを早くした件
tubone24
1
430
Featured
See All Featured
Embracing the Ebb and Flow
colly
84
4.5k
Automating Front-end Workflow
addyosmani
1366
200k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
BBQ
matthewcrist
85
9.3k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Unsuck your backbone
ammeep
668
57k
Code Reviewing Like a Champion
maltzj
520
39k
Transcript
AWS CDKͷ࠷ڧͷॻ͖ํΛ ࣮ફͯ͠ΈΔ 2023൛ 2023/7/8 CXࣄۀຊ෦ ࠤ౻ஐथ
None
ࣗݾհ • ࠤ౻ஐथ • CXࣄۀຊ෦ ΞʔΩςΫτνʔϜ Ϛωʔδϟʔ • JAWS-UG CDKࢧ෦
ӡӦ • ڭһ໔ڐ ߴߍ/தֶֶ ใ • ͖ͳAWSαʔϏεɿLambdaɺCDK 3 @tmk2154 tomoki10
ࠓճ͢͜ͱʢҰ୴հʣ ҎԼͷτϐοΫ͔ΒԿݸ͔͢ 4 1. جຊతͳCDKͷߏͷ͓͞Β͍ 2. CDKͰաͳநԽΛආ͚Δ 3. StackͰͳ͘ConstructͰ͚Δ 4.
Construct L2(+α)ΛϝΠϯͰ͏ 5. ڥ͝ͱͷࠩΦϒδΣΫτΛ͏ 6. Stackఆٛͷग़͚͠ 7. ςετΛͲ͜·ͰΔ͔ 8. NodejsFunctionΛ͓͏ҕһձ 9. ϞϊϨϙ͔ɺγϯάϧϨϙ͔
ࠓͷϋογϡλά 5 ɹ #devio2023
࣍ •νϣʔΫτʔΫͱ •ͳͥࠓ͢ͷ͔ •͢͜ͱͷݩωλ •ࠓճ͢͜ͱ 6
νϣʔΫτʔΫͱ ٕज़ઐࣝʹؔ͢ΔτϐοΫʹ͍ͭͯɺΤΩεύʔτ ઐՈ͕ࢀՃऀʹରͯ͠తʹઆ໌σϞϯετϨʔγϣ ϯΛߦ͍ͳ͕ΒɺରσΟεΧογϣϯΛߦ͏Πϕϯτܗ ࣜͰ͢ɻ νϣʔΫτʔΫͷಛɺࢀՃऀͱΤΩεύʔτͱͷؒͰର σΟεΧογϣϯ͕׆ൃʹߦΘΕΔ͜ͱͰ͢ɻࢀՃऀ ɺ࣭Λͨ͠ΓɺٙҙݟΛड़ͨΓ͢Δ͜ͱͰɺΤΩ εύʔτͱͷ૬ޓ࡞༻Λ௨ͯ͡ΑΓਂ͍ཧղࣝΛಘΔ͜ ͱ͕Ͱ͖·͢ɻ
7
νϣʔΫτʔΫͱ ٕज़ઐࣝʹؔ͢ΔτϐοΫʹ͍ͭͯɺΤΩεύʔτ ઐՈ͕ࢀՃऀʹରͯ͠తʹઆ໌σϞϯετϨʔγϣ ϯΛߦ͍ͳ͕ΒɺରσΟεΧογϣϯΛߦ͏Πϕϯτܗ ࣜͰ͢ɻ νϣʔΫτʔΫͷಛɺࢀՃऀͱΤΩεύʔτͱͷؒͰର σΟεΧογϣϯ͕׆ൃʹߦΘΕΔ͜ͱͰ͢ɻࢀՃऀ ɺ࣭Λͨ͠ΓɺٙҙݟΛड़ͨΓ͢Δ͜ͱͰɺΤΩ εύʔτͱͷ૬ޓ࡞༻Λ௨ͯ͡ΑΓਂ͍ཧղࣝΛಘΔ͜ ͱ͕Ͱ͖·͢ɻ
8
͍ͭͰ/ͲΜͳ࣭Ͱ Welcome!! 9
CDKͬͯԿʁ ͿͬͪΌ͚ࠓϊϦͰདྷͨΜͰ 10 ྫ͑…
࣭ CDKͬͨ͜ͱ͕͋Δਓʁ ɹɹɹ1. ࣄͰ2Ҏ্͍ͬͯΔ ɹɹɹ2. ࣄͰ1Ҏ্͍ͬͯΔ ɹɹɹ3. ϋϯζΦϯۀ֎Ͱࢼ͍ͯ͠Δ ɹɹɹ4. ͬͨ͜ͱ͕ͳ͍
11
ͳͥࠓ͢ͷ͔ 12 ੲͷࢿྉ
2021ͷࢿྉͰݕ౼ࣄ߲ྑ͍͕͑ݹ͘ͳ͖ͬͯͨ ͳͥࠓ͢ͷ͔ 13
ࠓճ͢͜ͱͷݩωλ 14
ࢿྉΞοϓϩʔυ͞Εͯ·͢ 15
͜ͷ໘ന͞ΘͬͯΔͷ͔ͳ͋ʁ ͬͱΊ͍ͨʂ 16
ࠓճ͢͜ͱ ҎԼͷτϐοΫ͔ΒԿݸ͔͢ 17 1. جຊతͳCDKͷߏͷ͓͞Β͍ 2. CDKͰաͳநԽΛආ͚Δ 3. StackͰͳ͘ConstructͰ͚Δ 4.
Construct L2(+α)ΛϝΠϯͰ͏ 5. ڥ͝ͱͷࠩΦϒδΣΫτΛ͏ 6. Stackఆٛͷग़͚͠ 7. ςετΛͲ͜·ͰΔ͔ 8. NodejsFunctionΛ͓͏ҕһձ 9. ϞϊϨϙ͔ɺγϯάϧϨϙ͔
αϯϓϧϦϙδτϦ https://github.com/tomoki10/cdk-best-design-2023 18
جຊతͳCDKͷߏͷ͓͞Β͍ 19 DELKTPO 03 BQQPQUJPO FOUSZQPJOU
جຊతͳCDKͷߏͷ͓͞Β͍ 20
CDKͰաͳநԽΛආ͚Δ खଓܕ͕ͩએݴܕతʹॻ͘ 21
CDKͰաͳநԽΛආ͚Δ खଓܕ͕ͩએݴܕతʹॻ͘ ҎԼۃͳѱ͍ྫ 22
CDKͰաͳநԽΛආ͚Δ Ifɺforۃྗॻ͔ͳ͍ɺڥࠩҟجຊύϥϝʔλͰઃఆ ։ൃ/ຊ൪ؒͰͷϦιʔεଘࡏͷࠩҟۃྗ͑Δ※ 23 ※ ʮTwelve-Factor App ։ൃ/ຊ൪Ұகʯhttps://12factor.net/ja/dev-prod-parity
StackͰͳ͘ConstructͰ͚Δ 24 PropsʹΑΔStackؒࢀর͕ݩڟͰCDK༻ऀͷ ΄΅100%͕ϋϚΔ᠘ ͍ͬͯͳ͍ ͋Δ CDKͷΫϩεελοΫؒࢀরͰ
٧·ͬͨ͜ͱ͋Γ·͔͢ʁ(Սۭ) https://dev.classmethod.jp/articles/aws-cdk-props-cross-stack-reference- problem-and-handle/
StackͰͳ͘ConstructͰ͚Δ 25
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 ʜ ʜ - நԽ ରԠ ରԠ நԽ
Construct L2(+α)ΛϝΠϯͰ͏ 27 L2 + Security or Governance or
Best Setting Platform TeamSecurity TeamͳͲ͕ਪઃఆΛॻ͖ɺࢀর࣮͠
ڥ͝ͱͷࠩΦϒδΣΫτΛ͏ 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ͰڥࠩΛઃఆ
ڥ͝ͱͷࠩΦϒδΣΫτΛ͏ 29 parameter.ts bin/cdk-best-design-2023.ts
Stack ఆٛͷग़͚͠ 30
Stack ఆٛͷग़͚͠ 31
ςετΛͲ͜·ͰΔ͔ 32 • Snapshot Test CloudFormationςϯϓϨʔτΛอଘ͠ɺࠩ֬ೝΛߦ͑Δ • GoodɿCDKΞοϓσʔτ࣌ͷมߋࠩΛ֬ೝͰ͖ͯ҆৺ •
BadɿS3ͳͲΞηοτͰఆҎ্ʹมߋ͕ࠩͰ͖ΔͷͰ੍͕͍Δ
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
ςετΛͲ͜·ͰΔ͔ 34 • Fine-grained Assertions CloudFormation্ͷϦιʔε͕ఆͨ͠ঢ়ଶ͔֬ೝͰ͖Δ • Goodɿ੍ޚߏจΛ͏߹ʹಈ࡞֬ೝ͕Ͱ͖Δ •
BadɿL2ϕʔεͰίʔυΛએݴతʹॻ͍͍ͯΕͦͦෆཁͳ߹ଟ͍
ςετΛͲ͜·ͰΔ͔ 35 • Integration Test (Alpha) ϦιʔεΛ࣮ࡍͷΞΧϯτʹσϓϩΠͯ͠ɺσϓϩΠՄೳ͔ͷ֬ೝ σϓϩΠޙʹHTTPSϦΫΤετͷૄ௨֬ೝͳͲ͕Ͱ͖Δ CDKͷ෦࣮ͰओʹΘΕ͍ͯΔ
• Goodɿ࣮ࡍͷڥͰఆͨ͠ಈ࡞Λ͢Δ͔֬ೝՄೳ • BadɿσϓϩΠ͕͋ΔͷͰςετύλʔϯ͕ଟ͍ͱςετ͕࣌ؒ͘ͳΔ
ςετΛͲ͜·ͰΔ͔ 36 • cdk-nag AWSNIST.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
NodejsFunctionΛ͓͏ҕһձ 37 LambdaͰNodejsΛ͏ࡍͷศརπʔϧ͕ἧ͍ͬͯΔ L2+͙Β͍ͷബ͍Construct ҎԼརͷҰ෦ • όϯυϧ͕؆୯ɻesbuildΛೖΕΔ͚ͩ distσΟϨΫτϦͳͲதؒͷϑΝΠϧஔ͖ෆཁ • HotswapͰ࠷ͷσϓϩΠʢඵͰσϓϩΠ😆
ٳΉՋͳ͠😢ʣ • BundlingΦϓγϣϯͷcommandHooksͰҙίϚϯυϑοΫͳͲ͕Մೳʂ ͜ͷϑΝΠϧ͍ͭͰʹLambdaʹೖΕ͍ͨͱ͔OK • awsSdkConnectionReuse ͰTCPଓͷ͍ճ͠ΛαΫοͱઃఆ
ϞϊϨϙ͔ɺγϯάϧϨϙ͔ 38 ͓લΑΓ·্ͩͷੈք͕͋Δʂ 💦 ͳΜʜͩͱʜ
ϞϊϨϙ͔ɺγϯάϧϨϙ͔ 39 ϦϙδτϦʢϞϊϨϙʣ
ϞϊϨϙ͔ɺγϯάϧϨϙ͔ 40 ϦϙδτϦ ϦϙδτϦ ϦϙδτϦ
એ 41 དྷि$%,ࢧ෦ͰΠϕϯτΓ·͢ʂ ਫ ʙ https://jawsug-cdk.connpass.com/
Ξϯέʔτ͓ئ͍͠·͢ 42 https://forms.gle/Upi2i5PsMTEUyJ6F8 ຬ্ҐͷηογϣϯΛޙϒϩάͰެ։༧ఆʂ ճͷ͝ڠྗΛΑΖ͓͘͠ئ͍͠·͢ɻ
͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ 43