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
Node.js_で_CloudFormation_のテンプレートを分割して管理する.pdf
Search
藤巻商店
September 08, 2018
Programming
600
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Node.js_で_CloudFormation_のテンプレートを分割して管理する.pdf
藤巻商店
September 08, 2018
Other Decks in Programming
See All in Programming
선언형 햅틱 라이브러리 진동을 소개합니다
l2hyunwoo
1
280
現場と育てるRailsモデリング 〜Spreadsheetから始めたモデル設計〜
siroemk
2
1.2k
當我們開始不讀 Code - AI Agent 時代,Code Review 與 Clean Code 還剩下什麼?
jame2408
1
360
AWS CDKを理解するために公式の定義を深掘って解説してみる / Understanding AWS CDK by Digging into Its Official Definition
akihisaikeda
2
240
自作Discord音声botをLambda MicroVMsに移行した話 / Migrating My Discord Voice Bot to Lambda MicroVMs
akihisaikeda
1
280
コーディング自動化の次へ。人の介入をゼロにするファクトリーとサポートAIによる実践
timakin
5
5.1k
Goコンパイラを作ってGoをもっと理解する / Build a Go compiler to better understand Go
ikura_hamu
0
120
ActionController meets Protocol Buffers
sorah
1
780
学びを記事・スライド・Xへ高速展開する― AI-assisted Learning Loopで回すコンテンツ生成術
ochtum
0
190
AI時代のシニアエンジニアとは
yosuke_furukawa
PRO
14
11k
Getting Started with Vibe Coding
miccheng
0
180
AI時代のTerminal環境を UNIX哲学で設計・運用する
yasunori0418
1
340
Featured
See All Featured
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
KATA
mclloyd
PRO
35
16k
Building Applications with DynamoDB
mza
96
7.3k
A Modern Web Designer's Workflow
chriscoyier
699
190k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.9k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.3k
Into the Great Unknown - MozCon
thekraken
41
2.8k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
60k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
240
Prompt Engineering for Job Search
mfonobong
0
570
Why Our Code Smells
bkeepers
PRO
340
58k
Scaling GitHub
holman
464
140k
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