Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 8916

AWS YAML の JSON パーサー

$
0
0

動機

AWS の設定ファイルは JSON より YAML 派なんだけど、設定ファイルを Node.js (JSON) で処理したい。

AWS 独自の組み込み関数が使われていて、そのおかげで便利なんだけど、普通のYAMLパーサーだと読めない。
(組み込み関数のドキュメントは こちら)

そこで、組み込み関数を出来る限りエミュレートした専用パーサーを用意した。

ソースコード

https://github.com/exabugs/aws-yaml

インストール

yarn add aws-yaml

使い方

import yaml from 'aws-yaml';
import fs from 'fs';

const buff = await fs.promises.readFile('template.yaml', 'utf8');
const json = yaml.load(buff);

const { Resources } = json;

使える関数

fullshort
Ref!Ref
Fn::Join!Join
Fn::Select!Select
Fn::Split!Split
Fn::GetAtt!GetAtt
Fn::Sub!Sub
Fn::FindInMap!FindInMap
Fn::GetAZs!GetAZs
Fn::If!If
Fn::Equals!Equals
Fn::And!And
Fn::Or!Or
Fn::Not!Not
Fn::Base64!Base64
Fn::Cidr!Cidr

使えない関数

fullshort
Fn::ImportValue!ImportValue
Fn::Transform!Transform

Viewing all articles
Browse latest Browse all 8916

Trending Articles