Node.jsでCloudFormationテンプレートを書く
タイトルの通りですが、Node.jsでCloudFormationテンプレートを書いてみました。
完全にネタです。
以下のコードを実行すると、標準出力にjson文字列が出力されます。
var template = {}; template['AWSTemplateFormatVersion'] = '2010-09-09'; template['description'] = 'Apache Web Server Configuration stack'; template['Parameters'] = { 'KeyName' : { 'Description' : 'Name of an existing EC2 KeyPair to enable SSH access', 'Type' : 'AWS::EC2::KeyPair::KeyName' }, 'SubnetIDs' : { 'Description' : 'Subnet IDs', 'Type' : 'List<AWS::EC2::Subnet::Id>' }, 'InstanceType' : { 'Description' : 'EC2 instance type (e.g. m1.small)', 'Type' : 'String', 'Default' : 't2.small', 'AllowedValues' : [ 't2.micro', 't2.small' ] }, 'SecurityGroupName' : { 'Description' : 'Security group name', 'Type' : 'String' } }; template['Resources'] = { 'EC2Instance' : { 'Type' : 'AWS::EC2::Instance', 'Metadata' : { 'AWS::CloudFormation::Init' : { 'config' : { 'packages' : { 'yum' : { "git" : [] } } } } }, 'Properties' : { 'InstanceType' : { 'Ref' : 'InstanceType' }, 'ImageId' : 'ami-xxxxxxxx', 'SubnetId' : { 'Ref' : 'SubnetIDs' }, 'SecurityGroups' : { 'Ref' : 'SecurityGroupName' }, 'Tags' : { 'Key' : 'Name', 'Value' : 'xxxxx' }, 'UserData' : { "Fn::Base64" : { "Fn::Join" : ["", [ '#!/bin/bash\n', 'yum update -y' ] ] } } } } }; console.log(JSON.stringify(template, null, ' '));
はい、ほとんどjsonですね。
何が嬉しいのか
このようなアプローチの他にも各言語用に様々なラッパーライブラリがあるようですが、個人的にはこのレベルで必要十分かなーと思っています。
ネタとか言いながら個人的には本気だったり・・・。
さて最後になりましたが、この度旧ブログ(akiiiiiiiioの日記)から移転してまいりました!
(今日は主にこれを言いたかった)
今後とも宜しくお願いします!