0
1

More than 3 years have passed since last update.

AWS YAML の JSON パーサー

Posted at

動機

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
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1