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
Node.js_で_CloudFormation_のテンプレートを分割して管理する.pdf
Search
藤巻商店
September 08, 2018
Programming
0
560
Node.js_で_CloudFormation_のテンプレートを分割して管理する.pdf
藤巻商店
September 08, 2018
Tweet
Share
Other Decks in Programming
See All in Programming
Giselleで作るAI QAアシスタント 〜 Pull Requestレビューに継続的QAを
codenote
0
330
大規模Cloud Native環境におけるFalcoの運用
owlinux1000
0
240
Combinatorial Interview Problems with Backtracking Solutions - From Imperative Procedural Programming to Declarative Functional Programming - Part 2
philipschwarz
PRO
0
130
AtCoder Conference 2025
shindannin
0
910
ZJIT: The Ruby 4 JIT Compiler / Ruby Release 30th Anniversary Party
k0kubun
1
310
生成AI時代を勝ち抜くエンジニア組織マネジメント
coconala_engineer
0
38k
PC-6001でPSG曲を鳴らすまでを全部NetBSD上の Makefile に押し込んでみた / osc2025hiroshima
tsutsui
0
200
PostgreSQLで手軽にDuckDBを使う!DuckDB&pg_duckdb入門/osc25hi-duckdb
takahashiikki
0
230
CSC307 Lecture 01
javiergs
PRO
0
660
AIの誤りが許されない業務システムにおいて“信頼されるAI” を目指す / building-trusted-ai-systems
yuya4
7
4.3k
GoLab2025 Recap
kuro_kurorrr
0
1.6k
ThorVG Viewer In VS Code
nors
0
600
Featured
See All Featured
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
0
34
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
120
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
0
1.8k
AI: The stuff that nobody shows you
jnunemaker
PRO
1
160
Accessibility Awareness
sabderemane
0
32
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Why Our Code Smells
bkeepers
PRO
340
58k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
72
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.4k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
sira's awesome portfolio website redesign presentation
elsirapls
0
110
Transcript
Node.js で CloudFormation の テンプレートを分割管理する
自己紹介 藤巻商店(@fujimakishouten) • 株式会社 Eq • Debian GNU/Linux をデスクトップ環境で愛用 •
交互浴が好きで週に5〜6回銭湯に行く • 恵海人
株式会社 Eq について • サーバーを見られるエンジニアは2名 • サーバー管理のコストを下げたい • 小さなチームなので、効率よく開発したい ◦
AWS のクラウドサービスを組み合わせて開発 ◦ Lambda、APIGateway、DynamoDB などを使用
株式会社 Eq について • 環境構築には CloudFormation を選択 ◦ SAM を利用する前提
◦ SAM-Local で Lambda のテストをする予定だった
CloudFormation • テンプレートが大きくなりやすい ◦ DynamoDB のオートスケールをしようとすると 5つくらい設定が必要 ◦ リソースによっては設定する項目も多い •
ごちゃごちゃして見通しが悪くなる
CloudFormation テンプレートを分割して管理したい
テンプレートを分割する方法 • 検索すると2つの方法が見つかった ◦ AWS::Include ◦ AWS::CloudFormation::Stack • 予め S3
に置いてあるテンプレートを 読み込んで利用できるらしい
テンプレートを分割する方法 • S3 にテンプレートを置くのが面倒 ◦ できればスタックを1つにしたい ◦ とりあえず動かして試したいだけなのに、 アップロードする仕組みをつくらないとダメなの?
面倒くさいところ • テンプレートを JSON で書く場合、 プロパティ名をクォートする必要がある ◦ JavaScript ならこんな感じで書くことが可能 {
Type: 'AWS::S3::Bucket', Properties: { BucketName: 'documents.honoka.io', AccessControl: 'Private' } };
Node.js を使ってテンプレートを結合する JavaScript で書いて、 JSON.stringify() すればいいのでは!?
Node.js を使ってテンプレートを結合する ./templates/resources/FunctionApi.js module.exports = { Type: 'AWS::Lambda::Function', Properties: {
Code: './dest/api', Description: 'honoka.io JSON-RPC 2.0 API', FunctionName: 'honoka-api', Handler: 'index.handler', Role: { 'Fn::GetAtt': ['RoleLambda', 'Arn'] }, Runtime: 'nodejs8.10' } };
Node.js を使ってテンプレートを結合する ./templates/resources/index.js module.exports = fs.readdirSync(__dirname).reduce((collection, filename) => { if
('index.js' === filename) { return collection; } const name = filename.replace(path.extname(filename), ''); collection[name] = require(path.resolve(__dirname, name)); return collection; }, {});
Node.js を使ってテンプレートを結合する ./templates/index.js const converter = require('../lib/converter/resources'); module.exports = {
AWSTemplateFormatVersion: '2010-09-09', Parameters: {}, Conditions: {}, Resources: converter({}, require('./resources')) };
Node.js を使ってテンプレートを結合する ./package.json "scripts": { "template": "node -e \"console.log(JSON.stringify(require('./templates'), null,
4));\" > template.json" } npm run template を実行すると、 template.json が出力されるようにしている
できるようになったこと • テンプレートを分割して管理できた ◦ サブディレクトリを作ることも可能
できるようになったこと • テンプレートに JavaScript が書ける ◦ 環境に合わせて設定ファイルを変えたり const config =
require(path.resolve(__dirname, '../../config', process.env.environment)); ◦ 外部ファイルを読み込んだり RequestTemplates: { 'application/json': fs.readFileSync(path.resolve(__dirname, '../mapping/JSONRequest')).toString('UTF-8') }
まとめ • 内容がすっきりして、見通しがよくなった ◦ 見たい部分だけに注目できる ◦ エラーが出ている部分や、 変更が必要な部分が見つけやすくなった ◦ テンプレートがきれいに書ける
• 面倒くさく無くなった!
まとめ CloudFormation を使っていて、 同じようなことで困っている方の、 参考になれば嬉しいです。
参考 URL サンプルを公開しています https://github.com/honokaio/honoka-api-base