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
AWSを活用したマルチテナントSaaSの設計と実践~実践編~CDKハンズオン
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
mu7889yoon / Yuta Nakamura
April 05, 2025
Technology
180
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
AWSを活用したマルチテナントSaaSの設計と実践~実践編~CDKハンズオン
mu7889yoon / Yuta Nakamura
April 05, 2025
More Decks by mu7889yoon / Yuta Nakamura
See All by mu7889yoon / Yuta Nakamura
JSONataとAWS Step Functionsで目指すRuntimelessな世界
mu7889yoon
1
1.2k
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
1
710
AWS CodeArtifact だいぶディープ
mu7889yoon
0
93
本当の”仕事”を手放せる未来が見えた
mu7889yoon
0
400
今だから言える(?) Q Developer Pro のクレジットが神ってた話
mu7889yoon
0
180
API Gateway→Lambda→AgentCore を再考する
mu7889yoon
0
69
MCPで決済に楽にする
mu7889yoon
1
280
Lambdaを使い倒す
mu7889yoon
0
160
~Everything as Codeを諦めない~ 後からCDK
mu7889yoon
3
1.6k
Other Decks in Technology
See All in Technology
Oracle Database Security 詳細解説
oracle4engineer
PRO
1
180
キヨさん67歳 AIコーディングエージェント物語
happysamurai294
0
140
バイブコーディングの特徴と「コケて直す」ループ
happysamurai294
0
130
Systems Manager AgentがインストールされたPCを紛失した時の対策を考えてみた
amarelo_n24
1
110
AI時代のエンジニアの情報発信〜個人の発信を組織の力に変える〜
ryo_kawamata
0
6k
AI時代、つくる力を自分たちの手に。 ──電通×KAG、アジャイルとAI駆動開発で挑む開発の変革
yuukiyo
3
450
複雑な業務システムを高速でつくるため、チーム全員をつくれる人へ
ayakurabuchi
0
110
【Oracle AI SPOTLIGHT ウェビナー】事例から見る!なぜOCIが選ばれたのか ― AI時代のクラウド戦略を紐解く ―
oracle4engineer
PRO
1
140
Content Mapper APIの応用例~CSS Modules、言語ファイル~
uhyo
2
410
あなたのDartコードは丸見えかもしれない ~reFlutterで暴くFlutterアプリの中身と多層防御~
zozotech
PRO
0
710
Patterns in AI Driven Software Development
akosma
PRO
0
390
re:Invent の去年のスケジュールを公開します!
miu_crescent
PRO
0
130
Featured
See All Featured
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
550
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
1.1k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.5k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
440
Intergalactic Javascript Robots from Outer Space
tanoku
273
28k
Utilizing Notion as your number one productivity tool
mfonobong
4
630
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
660
Being A Developer After 40
akosma
PRO
92
590k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1.1k
Music & Morning Musume
bryan
48
7.5k
Balancing Empowerment & Direction
lara
6
1.4k
Transcript
© SEEDS Co., Ltd. All rights reserved. CDKハンズオン 株式会社シーズ 中村 勇太
JAWS-UG 京都支部 × KyotoLT AWSを活用したマルチテナントSaaSの設計と実践
© SEEDS Co., Ltd. All rights reserved. 株式会社シーズ - クラウドソリューション事業部
FROM 経歴 2024年3月 大阪電気通信大学 卒業 2024年4月 株式会社シーズ 入社 好きなAWSサービス Amazon Lightsail / AWS Step Functions 中村 勇太 Yuta Nakamura 2
© SEEDS Co., Ltd. All rights reserved. ハンズオン環境構築 IaC /
CDKについて CDKハンズオン SaaSハンズオン環境構築(先にデプロイだけします!) 目次 3
© SEEDS Co., Ltd. All rights reserved. 4 ハンズオン環境構築
© SEEDS Co., Ltd. All rights reserved. 5 ハンズオン環境構築 1/2
https://github.com/aws-samples/sagemaker-studio-code-editor-template us-west-2のLaunch Stackをクリックする 参考:https://qiita.com/moritalous/items/656793cd97e1e967f045
© SEEDS Co., Ltd. All rights reserved. 6 ハンズオン環境構築 1/2
360にしてください
© SEEDS Co., Ltd. All rights reserved. 7 IaC /
CDKとは
© SEEDS Co., Ltd. All rights reserved. 8 IaCとは 1/2
Infrastructure as Code(IaC)とは、インフラストラクチャの構成をコードとして管理する アプローチです。 手動でのインフラ構築やGUIツールを使った設定に代わり、テキストファイルやコードを 使ってインフラの構成を定義します。
© SEEDS Co., Ltd. All rights reserved. 9 IaCとは 2/2
一般的に知られているEC2を作成する方法に、コンソールにログインして作成する方法 がありますが、IaCを用いて作成することもできます。
© SEEDS Co., Ltd. All rights reserved. 10 IaCのメリット •
再現性 : 同じコードから常に同じ環境が構築される • バージョン管理 : GitなどでIaCコードを管理が可能になる • 自動化 : デプロイメントプロセスの自動化が容易になる • ドキュメント化 : IaCコード自体がドキュメントとなる • スケーラビリティ : 環境の複製や拡張が容易
© SEEDS Co., Ltd. All rights reserved. 11 AWSにおけるIaC AWS
CloudFormation(CFn) YAML/JSONでAWSリソースを記述、幅広くリソースを管理できる。 AWS SAM CFnをベースに、AWS Lambda中心にサーバレスな構成を記述できる。 AWS CDK コンストラクトによる部品化に加えて条件分岐、ループといった プログラミングの恩恵を享受できる。 https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2017/08/09/aws_sam_introduction-1024x286.png
© SEEDS Co., Ltd. All rights reserved. 12 CDKとは AWS
CDK (Cloud Development Kit) は、プログラミング言語(TypeScript、Python、 Java、C#など)を使ってAWSリソースを定義できるオープンソースのIaCフレームワーク です。 CDKで書かれたコードは最終的にCFnに変換されてデプロイされます。
© SEEDS Co., Ltd. All rights reserved. 13 CDKのメリット •
プログラミング言語の利用 : 馴染みのある言語でAWSリソースを定義 • 型安全性 : コンパイル時にエラーを検出(TypeScriptなど) • 抽象化 : 高レベルの構成要素(Construct)を使用可能 • 再利用性 : コンポーネントの再利用が容易 • IDE統合 : コード補完やリファクタリング、AIエージェントの機能が使える
© SEEDS Co., Ltd. All rights reserved. 14 CDK ハンズオン
© SEEDS Co., Ltd. All rights reserved. CDK触ったことある人 🙋
© SEEDS Co., Ltd. All rights reserved. 16 CDKハンズオンの構成 シンプルなCreateとReadができる
サーバレスなアプリケーション
© SEEDS Co., Ltd. All rights reserved. 17 ハンズオン環境へのアクセス 1/2
Amazon SageMaker AIのコンソールにアクセス
© SEEDS Co., Ltd. All rights reserved. 18 ハンズオン環境へのアクセス 2/2
© SEEDS Co., Ltd. All rights reserved. 19 CDKハンズオンのコードの用意 >
git clone https://github.com/papi-tokei/cdk-sample.git Code Editorでフォルダを開く → > cd cdk-sample > npm i
© SEEDS Co., Ltd. All rights reserved. 20 リポジトリのファイル構成 ├──
README.md ├── bin │ └── cdk-sample.ts ├── cdk.json ├── lambda │ ├── get.py DBに読み取りをするコード │ └── post.py DBに書き込みをするコード └── lib └── cdk-sample-stack.ts 今回メインで見ていくコード > npx cdk bootstrap // CDK初めてだよという方は実行してください
© SEEDS Co., Ltd. All rights reserved. 21 リポジトリのファイル構成 ├──
README.md ├── bin │ └── cdk-sample.ts ├── cdk.json ├── lambda │ ├── get.py DBに読み取りをするコード │ └── post.py DBに書き込みをするコード └── lib └── cdk-sample-stack.ts 今回メインで見ていくコード > npx cdk bootstrap // CDK初めてだよという方は実行してください さっそく見てみましょう (git stashすればなんとかなります)
© SEEDS Co., Ltd. All rights reserved. 22 cdk-sample-stack.ts L11-16
- DynamoDB作成 // DynamoDBのテーブルを作成する const table = new dynamodb.Table(this, 'SampleTable', { partitionKey: { name: 'id', type: dynamodb.AttributeType.STRING }, tableName: 'SampleTable', removalPolicy: cdk.RemovalPolicy.DESTROY, });
© SEEDS Co., Ltd. All rights reserved. 23 cdk-sample-stack.ts L18-26,
L38-40 - Lambda(Get)作成 // Lambda関数を作成する(GET用) const getLambda = new lambda.Function(this, 'GetLambda', { runtime: lambda.Runtime.PYTHON_3_9, handler: 'get.handler', code: lambda.Code.fromAsset('lambda'), environment: { TABLE_NAME: table.tableName, }, }); === 略 === // DynamoDBテーブルへのアクセス権限を Lambda関数に付与する // GET Lambdaに対してテーブルの読み取り権限を付与 table.grantReadData(getLambda);
© SEEDS Co., Ltd. All rights reserved. 24 cdk-sample-stack.ts L44-51
- API Gateway作成 1/3 // API Gatewayを作成する const api = new apigateway.RestApi(this, 'SampleApi', { restApiName: 'Sample Service', apiKeySourceType: apigateway.ApiKeySourceType.HEADER, }); // APIキーを作成する const apiKey = api.addApiKey('ApiKey');
© SEEDS Co., Ltd. All rights reserved. 25 cdk-sample-stack.ts L53-64
- API Gateway作成 2/3 // 使用量プランを作成し、 APIキーと紐づける const usagePlan = api.addUsagePlan('UsagePlan', { name: 'BasicUsagePlan', throttle: { rateLimit: 10, burstLimit: 2, }, }); usagePlan.addApiKey(apiKey); usagePlan.addApiStage({ stage: api.deploymentStage, });
© SEEDS Co., Ltd. All rights reserved. 26 cdk-sample-stack.ts L66-70
- API Gateway作成 3/3 // API GatewayとLambda関数を紐づける const getIntegration = new apigateway.LambdaIntegration(getLambda); api.root.addMethod('GET', getIntegration, { apiKeyRequired: true, // Require API key });
© SEEDS Co., Ltd. All rights reserved. 27 デプロイ >
npx cdk synth // CFnテンプレートを生成 > npx cdk bootstrap // cdkが初めての方は実行してください(再掲) > npx cdk deploy // デプロイ この内容でデプロイしてOKか聞かれますので y で返答してください。
© SEEDS Co., Ltd. All rights reserved. 28 コンソールから確認
© SEEDS Co., Ltd. All rights reserved. 29 API キーのチェック
⚠このAPIキーはこの後使用します ⚠
© SEEDS Co., Ltd. All rights reserved. 30 APIエンドポイントのチェック ✅
CdkSampleStack ✨ Deployment time: 1.69s Outputs: CdkSampleStack.SampleApiEndpoint = https://xxxxxxxxxx.execute-api.ap-northeast-1.amazonaws.com/prod/ Stack ARN: arn:aws:cloudformation:ap-northeast-1:123456789012:stack/CdkSampleSt ack/xxxxxxx-xxxx-xxxxxxx
© SEEDS Co., Ltd. All rights reserved. 31 動作チェック >
curl -X POST '<ここにエンドポイントを入れる>' \ -H 'Content-Type: application/json' \ -H 'x-api-key: <ここにAPIキーを入れる>' \ -d '{"name":"TARO", "age":55}' > curl -X GET '<ここにエンドポイントを入れる>' \ -H 'x-api-key: <ここにAPIキーを入れる>'
© SEEDS Co., Ltd. All rights reserved. 32 EX) Lambdaのアーキテクチャを
Graviton(ARM64)に 1/2 // Lambda関数を作成する(GET用) const getLambda = new lambda.Function(this, 'GetLambda', { runtime: lambda.Runtime.PYTHON_3_9, handler: 'get.handler', architecture: lambda.Architecture.ARM_64, // ここを追加 code: lambda.Code.fromAsset('lambda'), environment: { TABLE_NAME: table.tableName, }, }); GravitonはAmazonが独自設計したARMベースのプロセッサ 高いパフォーマンスと低コスト、低消費電力が特徴
© SEEDS Co., Ltd. All rights reserved. 33 EX) Lambdaのアーキテクチャを
Graviton(ARM64)に 2/2 > npx cdk diff // 手元のCFnとデプロイされたCFnの差分を表示 Resources [~] AWS::Lambda::Function GetLambda GetLambdaXXXXXX └─ [+] Architectures └─ ["arm64"] [~] AWS::Lambda::Function PostLambda PostLambdaXXXXXX └─ [+] Architectures └─ ["arm64"]
© SEEDS Co., Ltd. All rights reserved. 34 CDKハンズオン環境の削除 >
npx cdk destroy 削除していいか聞かれますので y で返答してください。
© SEEDS Co., Ltd. All rights reserved. 35 SaaS ハンズオン環境構築
© SEEDS Co., Ltd. All rights reserved. 36 CDKハンズオンのコードを用意 >
git clone https://github.com/papi-tokei/saas-reference-architecture-ecs-deploy.git Code Editor上でフォルダを開く → > cd saas-reference-architecture-ecs-deploy > npm i
© SEEDS Co., Ltd. All rights reserved. 37 SaaSハンズオン環境構築 1/4
lib/saas-reference-architecture-ecs-deploy-stack.ts L28-34 build: { commands: [ 'cd scripts', './build-application.sh', './install.sh <ここにメールアドレスを入れる >' ], }, ⚠必ず受信できるメールアドレスを入力してください ⚠
© SEEDS Co., Ltd. All rights reserved. 38 SaaSハンズオン環境構築 2/4
> npx cdk deploy この内容でデプロイしてOKか聞かれますので y で返答してください。
© SEEDS Co., Ltd. All rights reserved. 39 デプロイ中にまとめ 座学編から一部抜粋
© SEEDS Co., Ltd. All rights reserved. 40 SaaSハンズオン環境構築 3/4
© SEEDS Co., Ltd. All rights reserved. 41 SaaSハンズオン環境構築 4/4
© SEEDS Co., Ltd. All rights reserved. 42 ありがとうございました! コメントやワイワイは
#jawsug でお待ちしております
© SEEDS Co., Ltd. All rights reserved. 43 [付録] cdk
deployの裏で何が動いているのか