3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[JAWS-UG CLI] JSONをYAMLに変換するシェルスクリプト

3
Last updated at Posted at 2018-05-23

CloudFormationではJSON、YAMLの2種類の記法を利用することができます。

利用者の間では可読性と記述性の高いYAMLが人気ですが、AWSアーキテクチャセンター( https://aws.amazon.com/jp/architecture/ )で配布されるテンプレートにはJSONのものが多いように感じます。

シェルスクリプト(例)

CLI環境で気軽にCloudFormationテンプレートをYAMLに変換するために以下のようなシェルスクリプトを作成しておくと良いでしょう。

~/bin/json2yaml.sh
# !/bin/sh

readonly FILE_INPUT=$1

if [ ! -z ${FILE_INPUT} ]; then
  ruby -ryaml -rjson -e 'puts YAML.dump(JSON.parse(STDIN.read))' < ${FILE_INPUT}
else
  echo "usage: $0 json_file"
fi

使用方法

templateの取得(例)

  1. https://docs.aws.amazon.com/quickstart/latest/vpc/welcome.html にアクセスする。

  2. "View Template"ボタンをクリックする。(JSON形式テンプレートのダウンロードがはじまる)

  3. シェルスクリプトでテンプレートをコンバートする。

コマンド
~/bin/json2yaml.sh aws-vpc.template
結果(一部)
---
AWSTemplateFormatVersion: '2010-09-09'
Description: This template creates a Multi-AZ, multi-subnet VPC infrastructure with
  managed NAT gateways in the public subnet for each Availability Zone. You can also
  create additional private subnets with dedicated custom network access control lists
  (ACLs). If you deploy the Quick Start in a region that doesn't support NAT gateways,
  NAT instances are deployed instead. **WARNING** This template creates AWS resources.
  You will be billed for the AWS resources used if you create a stack from this template.
  QS(0027)
Metadata:
  AWS::CloudFormation::Interface:
    ParameterGroups:
    - Label:
        default: Availability Zone Configuration
      Parameters:
      - AvailabilityZones
      - NumberOfAZs
    - Label:
        default: Network Configuration
      Parameters:
      - VPCCIDR
3
2
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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?