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.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
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
210
あの日俺達が夢見たサーバレスアーキテクチャ/the-serverless-architecture-we-dreamed-of
tomoki10
0
460
re:Invent2024のIaC周りのアップデート&セッションの共有/around-re-invent-2024-iac-updates
tomoki10
0
1k
Classmethod流のPlatform Engineering / classmethod-platform-engineering-devio2024
tomoki10
1
1.3k
AWS CDK Conference Japan 2024 OP
tomoki10
0
700
TypeScripterに送るIaCの世界への招待〜AWS CDKと共に〜/inviting-typescripters-to-the-world-of-iac-with-aws-cdk
tomoki10
0
740
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
880
Other Decks in Technology
See All in Technology
10個のフィルタをAXI4-Streamでつなげてみた
marsee101
0
170
第3回Snowflake女子会_LT登壇資料(合成データ)_Taro_CCCMK
tarotaro0129
0
200
非機能品質を作り込むための実践アーキテクチャ
knih
5
1.5k
普通のエンジニアがLaravelコアチームメンバーになるまで
avosalmon
0
110
Opcodeを読んでいたら何故かphp-srcを読んでいた話
murashotaro
0
270
5分でわかるDuckDB
chanyou0311
10
3.2k
PHPからGoへのマイグレーション for DMMアフィリエイト
yabakokobayashi
1
170
watsonx.ai Dojo #5 ファインチューニングとInstructLAB
oniak3ibm
PRO
0
170
サービスでLLMを採用したばっかりに振り回され続けたこの一年のあれやこれや
segavvy
2
490
日本版とグローバル版のモバイルアプリ統合の開発の裏側と今後の展望
miichan
1
130
Oracle Cloud Infrastructure:2024年12月度サービス・アップデート
oracle4engineer
PRO
0
200
DevOps視点でAWS re:invent2024の新サービス・アプデを振り返ってみた
oshanqq
0
180
Featured
See All Featured
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Code Review Best Practice
trishagee
65
17k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
66k
Music & Morning Musume
bryan
46
6.2k
Into the Great Unknown - MozCon
thekraken
33
1.5k
The Language of Interfaces
destraynor
154
24k
Building Applications with DynamoDB
mza
91
6.1k
Being A Developer After 40
akosma
87
590k
Making Projects Easy
brettharned
116
5.9k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
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