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でカイゼンする/2022-03-23-llt25
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Satoshi SAKAO
March 23, 2022
Programming
120
0
Share
AWSインフラのデプロイをCDKでカイゼンする/2022-03-23-llt25
社内のLTイベント「えるLT Vol.25 オンライン」で発表した資料です
Satoshi SAKAO
March 23, 2022
More Decks by Satoshi SAKAO
See All by Satoshi SAKAO
Testcontainers/2024-11-20-llt32
ottijp
0
87
Pkl/2024-04-17-llt31
ottijp
0
120
JavaScriptのデバッグ/2023-09-04-llt30
ottijp
0
190
CDK for TerraformでAzureリソースをデプロイする/2023-05-15-llt29
ottijp
1
320
TWELITEへの誘い/2022-12-27-llt28
ottijp
0
180
ビルドツールBazelを触ってみた/2022-09-28-llt27
ottijp
0
210
HashiCorp Vaultを使ったシークレットのセキュアな一元管理 〜Ansibleを添えて〜/2022-07-12-llt26
ottijp
0
170
Amazon Timestreamでデータ補間/2021-12-27-llt24
ottijp
0
120
ncurses/2021-05-12-llt21
ottijp
0
230
Other Decks in Programming
See All in Programming
tRPCの概要と少しだけパフォーマンス
misoton665
2
250
AIと共に生きる技術選定 2026
sgash708
0
110
(Re)make Regexp in Ruby: Democratizing internals for the JIT
makenowjust
3
890
UIの境界線をデザインする | React Tokyo #15 メイントーク
sasagar
2
400
運転動画を検索可能にする〜Cosmos-Embed1とDatabricks Vector Searchで〜/cosmos-embed1-databricks-vector-search
studio_graph
1
520
The Less-Told Story of Socket Timeouts
coe401_
3
810
PicoRuby for IoT: Connecting to the Cloud with MQTT
yuuu
2
710
【26新卒研修資料】TDD実装演習
dip_tech
PRO
0
130
mruby on C#: From VM Implementation to Game Scripting (RubyKaigi 2026)
hadashia
2
1.2k
WebAssembly を読み込むベストプラクティス 2026年春版 / Best Practices for Loading WebAssembly (Spring 2026)
petamoriken
4
920
第3木曜LT会 #28
tinykitten
PRO
0
120
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
280
Featured
See All Featured
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.4k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.6k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
520
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.8k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Done Done
chrislema
186
16k
Building the Perfect Custom Keyboard
takai
2
740
The SEO identity crisis: Don't let AI make you average
varn
0
450
Faster Mobile Websites
deanohume
310
31k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
520
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
200
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Transcript
AWSインフラのデプロイをCDKでカイゼンする Satoshi SAKAO えるLT Vol.25 2022-03-23 1
話すひと 2 🏢 インフォコム株式会社 品質マネジメント推進室 👨🔧 ソフトウェアエンジニア 🛠 Node.js /
AWS / IoT / iOS (Swift) 💖 猫,テクテクライフ(ランク: 24) Satoshi SAKAO @ottijp
3 3 months have passed
Disclaimer • CloudFormationの話が出てきますが, 実はほとんど触ったことがないので, 多少間違っている部分があるかも. 間違ってたら誠にごめんなさい. 4
AWSインフラのデプロイ方法 • マネジメントコンソール • CLI, SDK • CloudFormation • CDK
(Cloud Development Kit) 5
AWSインフラのデプロイ方法 6 マネジメント コンソール CLI, SDK Cloud- Formation CDK GUI
x IaCʢ܁Γฦ͠ੑ, ࠶ݱੑʣ x x x એݴతΞϓϩʔν ϦιʔεηοτʢStackͷཧʣ x x ߴϨϕϧͳఆٛ x CloudFormation ⊆ CDK
CDK (Cloud Development Kit) • 宣言的アプローチのIaCのひとつ • 使い慣れたPG言語で定義できる • 内部でCloudFormationテンプレートを生成してデプロイする
• 高いレベル(抽象度)でインフラを定義できる • OSSとして公開されている 7
CDKによるAWSインフラ構築例 • Minecraftサーバを立てた • 誰かがログインしたら通知が来てほしい 8
構成 9
CDKのコード 10 // ログアップロード用のユーザ const minecraftServer = new iam.User(this, 'MinecraftServer');
// ログ解析用のファンクション const lambdaFunction = new lambda.Function(this, 'minecraft-join-notifier', { runtime: lambda.Runtime.NODEJS_14_X, handler: 'minecraft-join-notifier.handler', code: lambda.Code.fromAsset('resources'), environment: { SLACK_WEBHOOK_URL: this.node.tryGetContext('slackWebhookUrl') as string, DISCORD_WEBHOOK_URL: this.node.tryGetContext('discordWebhookUrl') as string, }, }); // ログアップロード先キュー const queue = new sqs.Queue(this, 'MinecraftLog', { fifo: true, contentBasedDeduplication: true, }); queue.grant(minecraftServer, 'sqs:SendMessage'); // キューとファンクションの結合 const eventSource = new lambda_event_sources.SqsEventSource(queue); lambdaFunction.addEventSource(eventSource); IAMポリシというリソースを 意識する必要がない リソースを特定するIDを 意識する必要がない オブジェクトを作る感覚で リソースを定義できる https://github.com/ottijp/minecraft-man/blob/main/lib/minecraft-man-stack.ts
話したこと CDKを使うことで,AWSインフラのデプロイを • 宣言的なIaCで • 高レベルに • 好きなPG言語で 実現する方法へカイゼンできる. 11
勧誘(Java版) 12
13 Appendix
SAMとの違い • どちらもCloudFormationにトランスレーションしてデプロイする • SAMはサーバレスアプリケーションに特化しており,ローカルでビルド,テストできる • CDKはサーバレスに限らずAWSの全リソースのデプロイを汎用的に可能だが, ローカルでのビルド,テストはサポートしていない • 両者の統合
• 正式な統合はパブリックプレビュー中 • SAMを併用することでサーバレスアプリケーションをローカルでビルド,テストできる • CDKでsynthして作られたロジカルIDを指定して,SAMコマンドを実行する • https://docs.aws.amazon.com/cdk/v2/guide/sam.html 14
CDKがすべてのユースケースにおいて最適解なのか? • No.それぞれに利点があるのでユースケースに合わせて選択することが必要 • マネジメントコンソール • はじめて使うときに,GUIでどんなオプションがあるのか見ながら簡単にできる • CLI, SDK
• インフラのデプロイ以外のAPIコール(データ参照など) • カスタムスクリプトによる特殊なデプロイの構成 • CloudFormation • 低レベルな調整が必要な構成 • (ただ,CDKで基本ラップされているので,CloudFormationに限っては 互換性の課題がなければCDKに優先して採用する理由は無い気がする) 15
CDKはCloudFormation以外にも対応している • cdktf • Terraform HCL ステートファイルの定義 • alpha release
• cdk8s • Kubernetes 構成の定義 • alpha release 16
CodePipelineとの統合 • 公式ドキュメントには見つからなかった • SAMが一般的にCodeBuildでやるようなので,同様かな? 17
今回の例で作成されるリソース 18
refs • aws/aws-cdk: The AWS Cloud Development Kit is a
framework for defining cloud infrastructure in code • https://github.com/aws/aws-cdk • AWS クラウド開発キット – アマゾン ウェブ サービス • https://aws.amazon.com/jp/cdk/ • IaC (Infrastructure as Code) とは • https://www.redhat.com/ja/topics/automation/what-is-infrastructure-as-code-iac • ottijp/minecraft-man • https://github.com/ottijp/minecraft-man 19