Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
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.7k
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
re:Invent2024のIaC周りのアップデート&セッションの共有/around-re-invent-2024-iac-updates
tomoki10
0
600
Classmethod流のPlatform Engineering / classmethod-platform-engineering-devio2024
tomoki10
1
1.3k
AWS CDK Conference Japan 2024 OP
tomoki10
0
680
TypeScripterに送るIaCの世界への招待〜AWS CDKと共に〜/inviting-typescripters-to-the-world-of-iac-with-aws-cdk
tomoki10
0
720
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
870
AWS CDKでECS on FargateのCI/CDを実現する際の理想と現実 / ideal-and-reality-when-implementing-cicd-for-ecs-on-fargate-with-aws-cdk
tomoki10
21
27k
AWSCDKを通してAWSを学ぶ/learn AWS through AWS CDK
tomoki10
0
3.4k
Other Decks in Technology
See All in Technology
A/Aテストにおけるサンプルサイズ/japanr2024
nikkei_engineer_recruiting
1
610
宇宙最速のランチRecap LT会(AWS re:Invent 2024)
watany
1
380
最近のUplift Modeling手法にRでトライ
hskksk
0
130
セキュリティ系アップデート全体像と AWS Organizations 新ポリシー「宣言型ポリシー」を紹介 / reGrowth 2024 Security
masahirokawahara
0
140
2000年てづくりキーボードの旅
tagomoris
1
170
re:Inventで発表された Bedrockの新機能を色々使って、マルチRAGエージェントにクラウド選定させてみた件
minorun365
PRO
3
220
開志専門職大学特別講義 2024 デモパート
1ftseabass
PRO
0
210
Ruby on Browser - RubyWorld Conference 2024
tmtms
1
110
つくってあそぼ! ユビキタス言語作文の紹介
ndadayo
1
150
開発者向けツールを魔改造してセキュリティ診断ツールを作っている話 - 第1回 セキュリティ若手の会 LT
pizzacat83
0
400
突き破って学ぶコンテナセキュリティ/container-breakout-cncj-lt
mochizuki875
6
1.1k
.NET のUnified AI Building Blocks 入門...!
okazuki
0
190
Featured
See All Featured
Building Your Own Lightsaber
phodgson
103
6.1k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
Optimising Largest Contentful Paint
csswizardry
33
3k
A designer walks into a library…
pauljervisheath
204
24k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.3k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Code Review Best Practice
trishagee
64
17k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
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