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
アジャイルでの品質の進化 Agile in Motion vol.1/20241118 Hiroyuki Sato
shift_evolve
0
170
10XにおけるData Contractの導入について: Data Contract事例共有会
10xinc
6
650
Lambda10周年!Lambdaは何をもたらしたか
smt7174
2
110
B2B SaaSから見た最近のC#/.NETの進化
sansantech
PRO
0
870
OCI Vault 概要
oracle4engineer
PRO
0
9.7k
VideoMamba: State Space Model for Efficient Video Understanding
chou500
0
190
New Relicを活用したSREの最初のステップ / NRUG OKINAWA VOL.3
isaoshimizu
3
620
Terraform CI/CD パイプラインにおける AWS CodeCommit の代替手段
hiyanger
1
240
なぜ今 AI Agent なのか _近藤憲児
kenjikondobai
4
1.4k
第1回 国土交通省 データコンペ参加者向け勉強会③- Snowflake x estie編 -
estie
0
130
[CV勉強会@関東 ECCV2024 読み会] オンラインマッピング x トラッキング MapTracker: Tracking with Strided Memory Fusion for Consistent Vector HD Mapping (Chen+, ECCV24)
abemii
0
220
社内で最大の技術的負債のリファクタリングに取り組んだお話し
kidooonn
1
550
Featured
See All Featured
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
Thoughts on Productivity
jonyablonski
67
4.3k
Practical Orchestrator
shlominoach
186
10k
A better future with KSS
kneath
238
17k
Why Our Code Smells
bkeepers
PRO
334
57k
The Language of Interfaces
destraynor
154
24k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Facilitating Awesome Meetings
lara
50
6.1k
Git: the NoSQL Database
bkeepers
PRO
427
64k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Into the Great Unknown - MozCon
thekraken
32
1.5k
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