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
500
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
LINEヤフーのフロントエンド組織・体制の紹介【24年12月】
lycorp_recruit_jp
0
540
ずっと昔に Star をつけたはずの思い出せない GitHub リポジトリを見つけたい!
rokuosan
0
150
[Ruby] Develop a Morse Code Learning Gem & Beep from Strings
oguressive
1
180
Fanstaの1年を大解剖! 一人SREはどこまでできるのか!?
syossan27
2
180
なぜCodeceptJSを選んだか
goataka
0
170
re:Invent をおうちで楽しんでみた ~CloudWatch のオブザーバビリティ機能がスゴい!/ Enjoyed AWS re:Invent from Home and CloudWatch Observability Feature is Amazing!
yuj1osm
0
130
Amazon VPC Lattice 最新アップデート紹介 - PrivateLink も似たようなアップデートあったけど違いとは
bigmuramura
0
200
どちらを使う?GitHub or Azure DevOps Ver. 24H2
kkamegawa
0
1k
10個のフィルタをAXI4-Streamでつなげてみた
marsee101
0
180
NW-JAWS #14 re:Invent 2024(予選落ち含)で 発表された推しアップデートについて
nagisa53
0
270
小学3年生夏休みの自由研究「夏休みに Copilot で遊んでみた」
taichinakamura
0
170
10分で学ぶKubernetesコンテナセキュリティ/10min-k8s-container-sec
mochizuki875
3
370
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
Docker and Python
trallard
42
3.1k
Visualization
eitanlees
146
15k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Building Better People: How to give real-time feedback that sticks.
wjessup
366
19k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.2k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
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