Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
CDKのコードレビューを楽にするパッケージcdk-mentorを作ってみた/cdk-m...
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
tomoki10
January 17, 2025
Technology
830
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
CDKのコードレビューを楽にするパッケージcdk-mentorを作ってみた/cdk-mentor
クラスメソッドのAWS CDK事情大公開スペシャル#2での登壇資料です。
https://classmethod.connpass.com/event/337711/
tomoki10
January 17, 2025
More Decks by tomoki10
See All by tomoki10
Claude Code の Sandbox 機能を Anthropic Sandbox Runtime(srt) で試そう!/lets-play-anthropic-sandbox-runtime
tomoki10
1
1.2k
チームで安全にClaude Codeを利用するためのプラクティス / team-claude-code-practices
tomoki10
7
5.5k
re:Invent2025 3つの Frontier Agents を紹介 / introducing-3-frontier-agents
tomoki10
0
1.4k
AWS Security Agentの紹介/introducing-aws-security-agent
tomoki10
0
1.8k
Kiro Autonomous AgentとKiro Powers の紹介 / kiro-autonomous-agent-and-powers
tomoki10
0
2.1k
CDK Vibe Coding Fes
tomoki10
1
1.1k
cdk initで生成されるあのファイル達は何なのか/cdk-init-generated-files
tomoki10
1
1.8k
Devin(Deep) Wiki/Searchの活用で変わる開発の世界観/devin-wiki-search-impact
tomoki10
1
4.3k
AI駆動で進化する開発プロセス ~クラスメソッドでの実践と成功事例~ / aidd-in-classmethod
tomoki10
2
5.5k
Other Decks in Technology
See All in Technology
.NET WebAssemblyで実現するクライアントサイドAI推論:NuGetからViteまで、2つのエコシステムを繋ぐビルド戦略
yamachu
1
870
Antigravity SDK for the Java Developer
glaforge
0
210
白金鉱業Meetup Vol.25 アウトカムが二値のデータに対するCausal Impact
brainpadpr
0
310
Oracle Cloud Infrastructure(OCI):Onboarding Session(はじめてのOCI/Oracle Supportご利⽤ガイド)
oracle4engineer
PRO
2
21k
AIに任せた品質は、誰が見立てるのか - AI時代のテストマネジメント
nakanao
3
3.1k
作って終わりじゃないサーバーレス 〜9年運用する大規模EC物流API基盤の設計・運用のリアル〜
zozotech
PRO
0
540
プラットフォームを「作る」、 チームに「入り込む」
sansantech
PRO
0
180
JSONataとAWS Step Functionsで目指すRuntimelessな世界
mu7889yoon
1
510
Von-Neumann Machines, Dreams & The Futures of IT
ufried
0
130
AI Native Platform Engineering 〜PlatformとAgileで“作る速さ”を“価値”へ〜
uya116
0
150
AI Agent入門〜今更聞けないAgentの話〜
hiromimaganuma
0
120
2026-09-18 gotanda.sre Terraformで複数環境作ったり、複数Stateに分割したりそれとTerragrunt / Terraform multi envs and multi states
masasuzu
4
740
Featured
See All Featured
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
370
Color Theory Basics | Prateek | Gurzu
gurzu
1
470
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
390
It's Worth the Effort
3n
188
29k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
470
How to Think Like a Performance Engineer
csswizardry
28
2.8k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
440
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
370
Tell your own story through comics
letsgokoyo
1
1.1k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
530
The Limits of Empathy - UXLibs8
cassininazir
1
690
Transcript
CDKのコードレビューを楽にするパッケージ cdk-mentorを作ってみた 2025/01/17 製造ビジネステクノロジー部 佐藤智樹
CDKのコードレビューって何やってます? 参考のため是⾮ポストしてください!! #cm_cdk_special 2
• 佐藤智樹 • 製造ビジネステクノロジー部 • アーキテクトチーム • JAWS-UG CDK⽀部 運営
• 好きなもの:孤独のグルメ • 好きなAWSサービス↓ ⾃⼰紹介 3 @tmk2154 @tomoki10 @tomoki10 Lambda CDK
• CDKのコードレビュー ◦ インフラ設定 ◦ セキュリティ設定 ◦ CDK/CloudFormationの構造 • cdk-mentorの紹介
◦ 機能紹介 ◦ デモ • 実装の中⾝を紹介 ◦ CDKのAspectsとは ◦ cdk-mentorの機能 ⽬次 4
ライフサイクルの早い段階でバグなどを取り除くことで、影響を最⼩限に抑える ただレビューは結構⼤変なのでなるべく静的コード解析に任せたい コードレビューの重要性 5 https://gihyo.jp/dev/serial/01/code_dev_cycle/0001
• インフラ設計(機能⾯、⾮機能⾯) ◦ インフラの構成が問題ないか ▪ ⼈⼿でレビュー (今ならAIレビュー?) ◦ パラメータの設定が社内ルールなどに準拠しているか ▪
Aspectsを使ったテスト(Fine-grained Assertions Test)で対応可能 • セキュリティ設計 ◦ AWSのセキュリティ基準や社内ルールなどに準拠しているか ▪ ⼈⼿でのレビュー ▪ cdk-nagを使ったリソース全体の⾃動チェック(要⼿動での除外設定) ▪ デプロイ後のSecurity Hubなどによる指摘修正 CDKのコードレビューの要素 6
• CDK/CloudFormationの構造に関わる部分のレビュー ◦ クロススタック参照/ネストスタック参照などを利⽤していないか ▪ ネイティブの参照機能(strong stack reference)を使っていないか ▪ 注意点を理解しているか
◦ Construct IDがPascalCaseになっているか ◦ Construct IDにConstructやStackなどの名前が含まれないか ▪ 物理リソース名が冗⻑にならないようチェック ◦ カスタムリソースを使っていないか ▪ 内部でカスタムリソースを使うような実装になっていないか CDKのコードレビューの要素 7
参考情報 8 https://dev.classmethod.jp/articles/aws-cdk-props-cross-stack-referen ce-problem-and-handle/ https://dev.classmethod.jp/articles/best-way-to-name-aws-cdk-construct -id/
• CDK/CloudFormationの構造に関わる部分のレビュー ◦ クロススタック参照/ネストスタック参照などを利⽤していないか ▪ ネイティブの参照機能(strict stack reference)を使っていないか ▪ 注意点を理解しているか
◦ Construct IDがPascal Caseになっているか ◦ Construct IDにConstructやStackなどの名前が含まれないか ▪ 物理リソース名が冗⻑にならないようチェック ◦ カスタムリソースを使っていないか ▪ 内部でカスタムリソースを使うような実装になっていないか CDKのコードレビューの要素 9
https://github.com/tomoki10/cdk-mentor cdk-mentor 10
デモ 11
デモ動画 12
例えばスコープを左のStackにすれば、 左のStack配下のConstructに同じ操作を ⾏うことが可能。 以下のコード場合は、Appがスコープ • CDKのAspectsとは ◦ 特定のスコープ(StackやAppなど)のConstructに対して、共通の操作を⾏える機能 中⾝の紹介の前におさらい 13
https://aws.amazon.com/jp/blogs/aws/boost-your-infrastructure-with-cdk/
CloudFormation経由でデプロイされるまでに4つのフェーズがあり PrepareのフェーズでAspectsのvisitが実⾏される CDKでリソースがデプロイされるまでの流れ 14 https://aws.amazon.com/jp/blogs/devops/align-with-best-practices-while-creating-infrastructure-using-cdk-aspects/
cdk-nag:Aspectsを利⽤して、CDKが⽣成したAWSリソース⽤の オブジェクトを精査しセキュリティ基準に合うのかチェックする Aspectsの主な利⽤例 15 https://github.com/cdklabs/cdk-nag
cdk.IAspects インターフェースからクラスを実装してvisitを実⾏ cdk-mentorの実装⽅法 16 CloudFormationテンプレートにaws:cdk:pathとして出⼒される NodeのPath構造からConstruct IDを抽出
Constructに指定するIDがPascalCaseでなければエラーとする cdk-mentorの機能(Construct IDがPascalCaseかチェック) 17
Constructに指定するIDにConstruct|Stackという⽂字を⼊れない cdk-mentorの機能(Construct IDにConstruct|Stackを⼊れない) 18
未然に事故を防ぐため、CDKがデフォルトで提供するprops渡しのクロスス タック参照(※strong stack reference)を使った場合に警告を出す cdk-mentorの機能(クロススタック参照で警告) 19 ※参考:https://github.com/aws/aws-cdk/pull/22008
内部実装はTypeScriptですが、jssiによる変換でPythonでも使えます cdk-mentorの機能(python対応) 20 appファイル stackファイル
• CDKのL2/L3が⽣成するConstructIDがPascalCase出ない場合もある ◦ APIGateway(v1/v2) ◦ VPC(ElasticIP, InternetGateway, SecurityGroupIngress/Egress) ◦ Cognito(Role)
◦ AppConfig etc… おまけ:実装で苦労した(している)点 21 …
おまけ:実装で苦労した(している)点 22 • 対処⽅法 ◦ GAしている全L2 ConstructをSynthできるコードを書いて検査 ▪ Readmeのサンプルレベルのリソースを⽣成して確認 ◦
AWSリソースやパスのprefix、特定のAWSリソースで特定の名前の場合は除外 • おまけ情報 ◦ 現状AWSリソースでL2がGAしてるのは⼤体80~90ぐらいっぽい https://github.com/tomoki10/cdk-mentor/blob/main/src/excluded-resource-types.ts
出来そうなこと(未検証) • 特定のAWSリソースで、特定の命名規則を適⽤する ◦ ex: DynamoDBのテーブル名はUPPER_SNAKE_CASEとする ◦ ex: DynamoDBのGSI名はUPPER_SNAKE_CASEとする •
L2Constructがある場合、L1 Constructの利⽤でアラートを出す • コスト最適化のため、特定のインスタンスタイプを推奨 • バックアップ設定の確認 • 特定サービスの組み合わせを強制(LambdaにDLQを設定) 考えられる今後の拡張 23
None