vpc_multiple_subnet.template を読んでみる

Type な key で M-x occur してみた。

27 matches for ""Type"" in buffer: vpc_multiple_subnet.template
     10:      "Type" : "String",
     18:      "Type" : "Number",
     54:      "Type" : "AWS::EC2::VPC",
     65:      "Type" : "AWS::EC2::Subnet",
     77:      "Type" : "AWS::EC2::InternetGateway",
     87:       "Type" : "AWS::EC2::VPCGatewayAttachment",
     95:      "Type" : "AWS::EC2::RouteTable",
    106:      "Type" : "AWS::EC2::Route",
    115:      "Type" : "AWS::EC2::SubnetRouteTableAssociation",
    123:      "Type" : "AWS::EC2::NetworkAcl",
    134:      "Type" : "AWS::EC2::NetworkAclEntry",
    147:      "Type" : "AWS::EC2::NetworkAclEntry",
    160:      "Type" : "AWS::EC2::NetworkAclEntry",
    173:      "Type" : "AWS::EC2::NetworkAclEntry",
    186:      "Type" : "AWS::EC2::SubnetNetworkAclAssociation",
    194:      "Type" : "AWS::EC2::Subnet",
    206:      "Type" : "AWS::EC2::RouteTable",
    217:      "Type" : "AWS::EC2::SubnetRouteTableAssociation",
    225:      "Type" : "AWS::EC2::NetworkAcl",
    236:      "Type" : "AWS::EC2::NetworkAclEntry",
    249:      "Type" : "AWS::EC2::NetworkAclEntry",
    262:      "Type" : "AWS::EC2::SubnetNetworkAclAssociation",
    270:      "Type" : "AWS::ElasticLoadBalancing::LoadBalancer",
    286:      "Type" : "AWS::EC2::SecurityGroup",
    296:      "Type" : "AWS::AutoScaling::AutoScalingGroup",
    310:      "Type" : "AWS::AutoScaling::LaunchConfiguration",
    322:      "Type" : "AWS::EC2::SecurityGroup",

Subnet は二つなのか。つうかこれ、ローカルに保存して CloudFormation から状態確認してやれ。と思ったら何があったのか知らんが rollback しよるぞorz
あ、横着してホストを launch しなかったら云々、なのか。Events 見たら着々と DELETE な処理が動いててヘコみますね。とは言え、これやっぱ使った方が色々と管理は楽になるはず。Resources というタブで一覧表示できますね。つうか ROLLBACK_COMPLETE な status になったら何故 rollback したかも分からないのか。これは酷い。
あと、確かに validate 事前にしとく必要がありますね。途中で失敗は色々な意味でキツいです。
とりあえず横着するな、ってことで確認に再度着手。

オチないアレを作ろうとしてみる

diff が以下。

$ diff vpc_multiple_subnet.template vpc_multiple_subnet_new.template
6,50d5
<   "Parameters" : {
< 
<     "InstanceType" : {
<       "Description" : "WebServer EC2 instance type",
<       "Type" : "String",
<       "Default" : "m1.small",
<       "AllowedValues" : [ "t1.micro","m1.small","m1.medium","m1.large","m1.xlarge","m2.xlarge","m2.2xlarge","m2.4xlarge","m3.xlarge","m3.2xlarge","c1.medium","c1.xlarge","cc1.4xlarge","cc2.8xlarge","cg1.4xlarge"],
<       "ConstraintDescription" : "must be a valid EC2 instance type."
<     },
< 
<     "InstanceCount" : {
<       "Description" : "Number of EC2 instances to launch",
<       "Type" : "Number",
<       "Default" : "1"
<     }
<   },
< 
<   "Mappings" : {
<     "AWSInstanceType2Arch" : {
<       "t1.micro"    : { "Arch" : "64" },
<       "m1.small"    : { "Arch" : "64" },
<       "m1.medium"   : { "Arch" : "64" },
<       "m1.large"    : { "Arch" : "64" },
<       "m1.xlarge"   : { "Arch" : "64" },
<       "m2.xlarge"   : { "Arch" : "64" },
<       "m2.2xlarge"  : { "Arch" : "64" },
<       "m2.4xlarge"  : { "Arch" : "64" },
<       "m3.xlarge"   : { "Arch" : "64" },
<       "m3.2xlarge"  : { "Arch" : "64" },
<       "c1.medium"   : { "Arch" : "64" },
<       "c1.xlarge"   : { "Arch" : "64" }
<     },
< 
<     "AWSRegionArch2AMI" : {
<       "us-east-1"      : { "32" : "ami-aba768c2", "64" : "ami-81a768e8" },
<       "us-west-1"      : { "32" : "ami-458fd300", "64" : "ami-b18ed2f4" },
<       "us-west-2"      : { "32" : "ami-fcff72cc", "64" : "ami-feff72ce" },
<       "eu-west-1"      : { "32" : "ami-018bb975", "64" : "ami-998bb9ed" },
<       "sa-east-1"      : { "32" : "ami-a039e6bd", "64" : "ami-a239e6bf" },
<       "ap-southeast-1" : { "32" : "ami-425a2010", "64" : "ami-5e5a200c" },
<       "ap-southeast-2" : { "32" : "ami-f98512c3", "64" : "ami-43851279" },
<       "ap-northeast-1" : { "32" : "ami-7871c579", "64" : "ami-7671c577" }
<     }
<   },
< 
294,329d248
< 
<     "WebServerGroup" : {
<       "Type" : "AWS::AutoScaling::AutoScalingGroup",
<       "Properties" : {
<         "AvailabilityZones" : [{ "Fn::GetAtt" : [ "PrivateSubnet", "AvailabilityZone" ] }],
<         "VPCZoneIdentifier" : [{ "Ref" : "PrivateSubnet" }],
<         "LaunchConfigurationName" : { "Ref" : "LaunchConfig" },
<         "MinSize" : "1",
<         "MaxSize" : "10",
<         "DesiredCapacity" : { "Ref" : "InstanceCount" },
<         "LoadBalancerNames" : [ { "Ref" : "ElasticLoadBalancer" } ],
<         "Tags" : [ {"Key" : "Network", "Value" : "Public", "PropagateAtLaunch" : "true" } ]
<       }
<     },
< 
<     "LaunchConfig" : {
<       "Type" : "AWS::AutoScaling::LaunchConfiguration",
<       "Properties" : {
<         "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" },
<                                           { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" },
<                                           "Arch" ] } ] },
<         "UserData" : { "Fn::Base64" : "80" },
<         "SecurityGroups" : [ { "Ref" : "InstanceSecurityGroup" } ],
<         "InstanceType" : { "Ref" : "InstanceType" }
<       }
<     },
< 
<     "InstanceSecurityGroup" : {
<       "Type" : "AWS::EC2::SecurityGroup",
<       "Properties" : {
<         "GroupDescription" : "Enable HTTP access on the configured port",
<         "VpcId" : { "Ref" : "VPC" },
<         "SecurityGroupIngress" : [ { "IpProtocol" : "tcp", "FromPort" : "80", "ToPort" : "80", "SourceSecurityGroupId" : { "Ref" : "LoadBalancerSecurityGroup" } } ]
<       }
<     }
<   },

これを aws-sdk な irb で validate してみます。

require 'yaml'
require 'json'
require 'aws-sdk'
config_file = File.join(File.dirname(__FILE__), "config.yml")
config = YAML.load(File.read(config_file))
AWS.config(config)
cfm = AWS::CloudFormation.new
template_file = File.join(File.dirname(__FILE__), "vpc_multiple_subnet.new.template")
template_json = JSON.parse(File.read(template_file))

う、以下を、と思ったのに

cfm.validate_template(template_json)

JSON.parse に失敗するorz
原因は

    }
  },

  "Outputs" : {

なナニが

    },

  "Outputs" : {

ってなってたからでした。とほほ杉る。
で、validate に吸わせてみました。

> cfm.validate_template(template_json)
=> {:parameters=>[], :capabilities=>[], :description=>"略", 
    :response_metadata=>{:request_id=>"370de0ac-7b2c-11e2-83a2-a1a45ac8fcb4"}}

コンソールを見てみても何も起きてはいないはずなので、検査してるだけかな。出力によれば valid なのかどうか。

これを

コンソールから投入してみました。どうなるか。結果正常終了してるんですが、az な指定はどこで、と言いつつ以下を見つつ ELB とか Subnet あたりのソレを確認。

stack の中のリソースが一括管理できるのもなかなか良いです。む、ROLLBACK 開始しよった。さっきは理由が云々と書きましたが、event なナニに情報が残る模様。曰く、

Only one of SubnetIds or AvailabilityZones may be specified

ELB な記述は以下です。

    "ElasticLoadBalancer" : {
      "Type" : "AWS::ElasticLoadBalancing::LoadBalancer",
      "Properties" : {
	"AvailabilityZones" : ["ap-northeast-1a"],

むむ、これは一体どーゆー事だろ。指定スルーでリトライしてみるか。を、指定ナシだと通りましたな。これはこれで微妙。
あ、デフォで大丈夫なのか。public な subnet に置かれてる形になってるや。そーゆー意味ではこの指定は不要なのかな。ちょっと色々謎が多い。