動機
AWS の設定ファイルは JSON より YAML 派なんだけど、設定ファイルを Node.js (JSON) で処理したい。
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;
使える関数
| full | short |
|---|---|
| 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 |
使えない関数
| full | short |
|---|---|
| Fn::ImportValue | !ImportValue |
| Fn::Transform | !Transform |