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 入門ガイド これだけは知っておきたいヒント集
Search
Anan Kikuchi
July 12, 2025
Technology
1
170
AWS CDK 入門ガイド これだけは知っておきたいヒント集
AWS CDK Conference Japan 2025 での登壇資料です。
https://jawsug-cdk.connpass.com/event/356357/
Anan Kikuchi
July 12, 2025
Tweet
Share
Other Decks in Technology
See All in Technology
AI エージェントと考え直すデータ基盤
na0
15
4.5k
CDK Vibe Coding Fes
tomoki10
0
160
マネジメントって難しい、けどおもしろい / Management is tough, but fun! #em_findy
ar_tama
7
1.2k
敢えて生成AIを使わないマネジメント業務
kzkmaeda
2
460
20250705 Headlamp: 專注可擴展性的 Kubernetes 用戶界面
pichuang
0
280
【Oracle Cloud ウェビナー】インフラのプロフェッショナル集団KELが考えるOCIでのソリューション実現
oracle4engineer
PRO
1
100
DatabricksにOLTPデータベース『Lakebase』がやってきた!
inoutk
0
130
VS CodeとGitHub Copilotで爆速開発!アップデートの波に乗るおさらい会 / Rapid Development with VS Code and GitHub Copilot: Catch the Latest Wave
yamachu
2
180
AWS CDK 開発を成功に導くトラブルシューティングガイド
wandora58
2
120
AWS認定を取る中で感じたこと
siromi
1
200
サイバーエージェントグループのSRE10年の歩みとAI時代の生存戦略
shotatsuge
3
300
【LT会登壇資料】TROCCO新コネクタ「スマレジ」を活用した直営店データの分析
kazari0425
1
110
Featured
See All Featured
Building a Scalable Design System with Sketch
lauravandoore
462
33k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
45
7.5k
The Language of Interfaces
destraynor
158
25k
What's in a price? How to price your products and services
michaelherold
246
12k
Producing Creativity
orderedlist
PRO
346
40k
Documentation Writing (for coders)
carmenintech
72
4.9k
Art, The Web, and Tiny UX
lynnandtonic
299
21k
It's Worth the Effort
3n
185
28k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
48
2.9k
How to Ace a Technical Interview
jacobian
278
23k
YesSQL, Process and Tooling at Scale
rocio
173
14k
Transcript
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 1 © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. Amazon Confidential and Trademark. AWS CDK 入門ガイド これだけは知っておきたいヒント集 菊地 晏南 A W S C D K C O N F E R E N C E J A P A N 2 0 2 5 アマゾンウェブサービスジャパン合同会社
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 2 菊地 晏南 / Anan Kikuchi Solutions Architect 趣味 バスケットボール、バレーボール、 旅⾏、Web開発 好きなAWSサービス AWS Cloud Development Kit (AWS CDK) AWS CloudFormation Amazon Bedrock @anan_kikuchi
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 3 アジェンダ 1. AWS Cloud Development Kit (AWS CDK) とは? 2. AWS CDK での開発フロー 3. ドキュメントと実装例 4. 開発効率化ツール 5. AWS CDK と生成 AI 6. まとめ
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 4 © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. Amazon Confidential and Trademark. AWS Cloud Development Kit (AWS CDK) とは?
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 5 Infrastructure as Code (IaC) 手動ではなく、コードによって インフラストラクチャの管理やプロビジョニングを行うプロセス ソースコード IaC ツール クラウドリソース ソフトウェア開発のプラクティスをインフラ構築の⾃動化に活かす 継続的デリバリーに必須の技術のひとつ リソースは この状態であるべき (宣⾔的) ⽬的の状態に 収束 https://docs.aws.amazon.com/whitepapers/latest/introduction-devops-aws/infrastructure-as-code.html
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 6 AWS Cloud Development Kit (AWS CDK) AWS CDK Meeting developers where they are 使い慣れたプログラミング⾔語で クラウドリソースを定義できる OSS のフレームワーク アプリ全体をコードで定義 ⾼レベルの抽象化 開発者体験を改善 • アプリと同じ⾔語で記述でき ドメイン固有⾔語の習得が不要 • ソフトウェア開発の技法と プラクティス、ツールを活⽤ • 型付けとバリデーションで 素早くフィードバックを得る • リソースとスタックの依存関係を ⾃動的に解決 • クラウドリソースだけでなく AWS Lambda 関数のコードや コンテナイメージなど アプリ全体をまとめて管理 • CI/CD パイプラインを⾃動構築 • 複数の AWS アカウントに またがる環境を管理 • 複雑な設定を抽象化し コード量と学習コストを削減 • いつでも抽象化から抜け出して 個別の設定にアクセス可能 • ベストプラクティスに基づく デフォルト値と設定を提供 • チームの構成パターンや ガードレールを共有・再利⽤ TypeScript JavaScript Python Java .NET Go https://github.com/aws/aws-cdk
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 7 AWS CDK の仕組み プログラミング⾔語で インフラ構成を定義 開発者 TypeScript JavaScript Python Java .NET Go 各⾔語のコンストラクトライブラリを利⽤ クラウドリソース ⽬的の状態に収束 API 呼び出し AWS CloudFormation テンプレートに定義された 状態になるようリソースを操作 • S3 バケットがなかったら作成 • 状態が違っていたら更新 • 状態が同じなら何もしない etc. テンプレートを実⾏ • Lambda関数のコード • コンテナイメージ • ファイル など アセットをデプロイ テンプレートと状態をスタックとして管理 AWS CDK Toolkit (CLI) CloudFormation テンプレートを合成 アセットをバンドル、デプロイ $ cdk deploy Node.js Node.js のコマンドラインツール Synthesize
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 8 AWS CDK の基本要素 https://docs.aws.amazon.com/cdk/v2/guide/home.html • アプリケーション全体 • 複数のAWSアカウント、リージョンに またがることが可能 App • CloudFormation スタックに対応 • デプロイ可能な最⼩単位 Stack • CDKの最も基本的なビルディングブロック • 1つまたは複数のAWSリソースを表現 • ユーザーにより定義・配布が可能 Construct • CDK App の出⼒。デプロイに必要な資材⼀式 • CloudFormation テンプレート • アセット(ファイル、Docker イメージなど) Cloud Assembly
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 9 AWS CDK Construct • Patterns (L3) • 複数のリソースを含む一般的な構成パターンを抽象化 • aws-ecs-patterns.LoadBalancedFargateService など • High-level constructs (L2) • デフォルト値や便利なメソッドを定義した 単一の AWS リソースを表すクラス • s3.Bucket クラスのインスタンスは addLifeCycleRule() メソッドを実装 • より特定のシナリオに合わせて単一リソースを抽象化した L2.5 constructs も存在 • aws-lambda-nodejs.NodeJsFunction, eks.FargateCluster など • Low-level constructs (L1) • CloudFormationリソースおよびプロパティと1:1で対応(自動生成される) • CfnXXX という名前 (例:s3.CfnBucket は AWS::S3::Bucket を意味) • すべてのプロパティを明示的に設定する必要がある 抽象化 レベル
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 10 © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. Amazon Confidential and Trademark. AWS CDK での開発フロー
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 11 AWS CDK での開発フロー(TypeScript の場合) Initialize Code Test Deploy プロジェクトを作成する リソースを定義する テストを実⾏する アプリをデプロイする
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 12 AWS CDK での開発フロー(TypeScript の場合) Initialize Code Test Deploy $ mkdir sample-app $ cd sample-app $ npx aws-cdk init app --language=typescript $ npx aws-cdk bootstrap • bootstrap は アカウントとリージョン ごとに最初だけ実⾏する • CDKToolkit という CloudFormation スタックが作成される • CDK 利⽤時には必須なので消さない プロジェクトを作成する リソースを定義する テストを実⾏する アプリをデプロイする
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 13 AWS CDK での開発フロー(TypeScript の場合) プロジェクトを作成する リソースを定義する テストを実⾏する アプリをデプロイする . ├── README.md ├── bin │ └── sample-app.ts ├── cdk.json ├── jest.config.js ├── lib │ └── sample-app-stack.ts ├── node_modules ├── package-lock.json ├── package.json ├── test │ └── sample-app.test.ts └── tsconfig.json init で作成される ディレクトリ構造 (TypeScript) File Structure CDK App の作成 CDK Stack の呼び出し CDK Stack の定義 テストの定義 Initialize Code Test Deploy
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 14 AWS CDK での開発フロー(TypeScript の場合) プロジェクトを作成する リソースを定義する テストを実⾏する アプリをデプロイする // ライブラリをインポート import {Stack} from "aws-cdk-lib"; import * as s3 from 'aws-cdk-lib/aws-s3'; import * as sqs from 'aws-cdk-lib/aws-sqs'; // Stack を定義 export class SampleAppStack extends Stack { constructor() { // コンストラクタ内で Construct を追加 new s3.Bucket(this, "HogeBucket"); new sqs.Queue(this, "HogeQueue"); } } lib/sample-app-stack.ts Initialize Code Test Deploy CDK Stack を定義し constructor() 内でリソースを定義する 基本的には L2 (, L3) コンストラクトを使う L2 コンストラクトがない場合は L1 コンストラクトを使う
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 15 AWS CDK での開発フロー(TypeScript の場合) プロジェクトを作成する リソースを定義する テストを実⾏する アプリをデプロイする Initialize Code Test Deploy $ npx aws-cdk synth 合成 $ npm run test テスト • テストには Snapshot / Fine-Grained Assertion / Validation / Integration Test や Policy Validation などがある • CDK によって⽣成される CloudFormation テンプレートの 差分を確認し、意図しない変更に気づける Snapshot Test は導⼊が簡単でおすすめ ※ テストの詳細︓ AWS CDKにおける開発とテスト (Advanced #1) $ npx aws-cdk diff 差分確認 $ npx aws-cdk deploy デプロイ
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 16 © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. Amazon Confidential and Trademark. ドキュメントと実装例
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 17 ドキュメントと実装例 API Reference AWS CDK Developer Guide AWS CDK Examples 公式の AWS CDK 実装例 AWS CDK の基礎やチュートリ アルから CLI の使い⽅、ベスト プラクティスなどを紹介 AWS Construct Library の使い ⽅を紹介 https://docs.aws.amazon.com/cdk/api/v 2/docs/aws-construct-library.html https://github.com/aws-samples/aws- cdk-examples https://docs.aws.amazon.com/ja_jp/cdk/ v2/guide/home.html
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 18 API Reference https://docs.aws.amazon.com/cdk/api/v2/docs/aws-construct-library.html ① 利⽤したいサービス (ex. Lambda) のライブラリを探す ③ 利⽤したいコンストラクト (ex. Function) を確認する ④ 実装例を参考にする ⑤ コンストラクト引数や メソッドを確認して詳細 な設定を⾏う TypeScript の基礎から始める AWS CDK 開発⼊⾨ では API Reference を参照しながらコードを記述する流れを解説 ② まずは Overview を⾒る
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 19 AWS CDK Examples https://github.com/aws-samples/aws-cdk-examples/tree/main 公式の AWS CDK 実装例 TypeScript / Python / Go / Java / C# の⾔語ご とに実装例を紹介 実際に複数サービスを 連携する⽅法などの参 考になる
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 20 © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. Amazon Confidential and Trademark. 開発効率化ツール
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 21 開発効率化ツール AWS Toolkit for Visual Studio Code Visual Studio Code の補完機能 App で定義されたスタックとリソースをツリー 状で確認できる cdk synth コマンドで⽣成される tree.json を使 ⽤するため AWS 認証情報なしで表⽰可能 各⾔語で補完機能が利⽤可能 TypeScript の場合標準で型チェックも効く
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 22 開発効率化ツール $ cdk watch $ cdk deploy --hotswap コードとアセットの変更を監視して 変更を検知すると⾃動的にデプロイ を実⾏ デフォルトで --hotswap を利⽤ AWS リソースの API を利⽤して 直接変更を試みる AWS CloudFormation を介さない分⾼ 速にコードの変更を反映可能 AWS Lambda や AWS Step Functions など特定のサービスに対応 hostswap 対応サービス⼀覧はこちら ︓cdk deploy CDK Watch を活⽤した開発速度の向上 ※ 実験的機能のため破壊的変更が⼊る可 能性があることに注意 ※ CloudFormation スタックでドリフトが 発⽣するため開発⽤途でのみ利⽤可能 (本番デプロイでは使⽤しない)
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 23 © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. Amazon Confidential and Trademark. AWS CDK と生成 AI
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 24 生成 AI で AWS CDK アプリ開発を加速する • Amazon Q Developer などで コーディング支援 • AWS CDK MCP Server や AWS Documentation MCP Server などの MCP サーバーと連携 IDE に Amazon Q Developer 拡張機能またはプラ グインをインストールする Amazon Q Developer が新しいエージェントコーディング エクスペリエンスで IDE エクスペリエンスを改善
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 25 AWS CDK で生成 AI アプリを開発する • 新しい Amplify AI Kit で、フルスタックの AI アプリを数分で構築 • AWS Amplify Gen 2 と AWS CDK で爆速アプリ開発 & 拡張 ! 第 2 回 AWS Amplify AI Kit で簡単 ! RAG アプリケーション開発 オープンソースの CDK 拡張 L2 コンストラクトに加えて「ベクトル DB と Amazon Bedrock Knowledge Bases」などパターンごとの L3 コンス トラクトを提供 AWS Amplify AI Kit Generative AI CDK Construct AWS Amplify を利用してチャットや 生成など生成 AI 機能を簡単に実装可 能 AWS Generative AI CDK Constructs
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 26 まとめ • AWS CDK は IaC ツールの一つで、使い慣れたプログラミング言語 でクラウドリソースを定義できるOSS のフレームワーク • 公式のドキュメントや実装例が豊富で実装時のヒントになる • IDE の拡張機能や生成 AI を活用することで効率的に開発できる
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 27 お役立ちリンク集 • 初心者がおさえておきたいAWS CDKのベストプラクティス 2024 • AWS CDK だけでなくソフトウェア開発の基本に立ち返ったプラクティス を紹介 • AWS CDKのあるあるお悩みに答えたい • プログラミング言語の選択やスタックの分け方など、CDK を開発する上で よくある疑問について紹介 • CDK での開発に慣れてきた頃に見返すのが Good
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 28 お役立ちリンク集 • ワークショップ • TypeScript の基礎から始める AWS CDK 開発入門 • CDK だけでなく TypeScript の基礎も学べるため TypeScript 入門者に最適 • TypeScript 経験者は CDK の基礎から学ぶことも可能 • AWS CDK Immersion Day Workshop • TypeScript だけでなく Python の例も紹介 • AWS 規範ガイダンス • AWS がお客様を長年支援する中で得られた知見を紹介 • L1, L2, L3 コンストラクトに関するAWS CDK レイヤーガイドや AWS CloudFormation、AWS SAM も含めたIaC ツールの選択など
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Confidential and Trademark. 29 Thank you! © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. Amazon Confidential and Trademark.