"UserData" Property in Heat Template is not triggered
I am using below Heat template for creation of EC2 instance. The EC2 instance is successfully created but the commands/script defined in the "UserData" property is not executed. What triggers this property? I am not able to see the commands output in the VM instance after login. I am using default cirros image for VM creation on UBUNTU. The path that is required to be in the UserData - /opt/aws/bin/cfn-init - is not created. How do we install this?
{ "AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "AWS CloudFormation Sample Template WordPress_Single_Instance: WordPress is web software you can use to create a beautiful website or blog. This template installs a single-instance WordPress deployment using a local MySQL database to store the data.",
"Parameters" : {
"InstanceType" : {
"Description" : "EC2 instance type",
"Type" : "String",
"Default" : "m1.small",
"AllowedValues" : [ "m1.tiny", "m1.small", "m1.medium", "m1.large", "m1.xlarge" ],
"ConstraintDescription" : "must be a valid EC2 instance type."
},
"KeyName" : {
"Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances",
"Type" : "String"
}
},
"Resources" : {
"network": {
"Type": "OS::Quantum::Net",
"Properties": {
"name": "Heat Network for EC2 Instance"
}
},
"subnet": {
"Type": "OS::Quantum::Subnet",
"Properties": {
"network_id": { "Ref" : "network" },
"ip_version": 4,
"cidr": "192.168.1.0/24",
"allocation_pools": [{"start": "192.168.1.3", "end": "192.168.1.20"}]
}
},
"NewEC2Instance": {
"Type": "AWS::EC2::Instance",
"Metadata" : {
"AWS::CloudFormation::Init" : {
"configSets" : {
"ascending" : [ "config1" , "config2" ],
"descending" : [ "config2" , "config1" ]
},
"config1" : {
"commands" : {
"test" : {
"command" : "sudo echo \"I come from RTOSS1\" > test6.txt",
"env" : { "CFNTEST" : "I come from config1." },
"cwd" : "~"
}
}
},
"config2" : {
"commands" : {
"test" : {
"command" : "sudo echo \"I come from RTOSS2\" > test7.txt",
"env" : { "CFNTEST" : "I come from config2" },
"cwd" : "~"
}
}
}
}
},
"Properties": {
"ImageId" : "62f2fcf4-3ddf-4557-8572-8ebcf949a69d",
"InstanceType" : { "Ref" : "InstanceType" },
"KeyName" : { "Ref" : "KeyName" },
"UserData": {
"Fn::Base64": "#!/bin/sh\n/opt/aws/bin/cfn-init -c ascending -s HeatTemplateStack -r NewEC2Instance\n"
}
}
}
},
"Outputs" : {
"Instance" : {
"Value" : { "Ref" : "NewEC2Instance" }
}
}
}
Please let me know incase required any other information.