Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Unix command is not working on newly created EC2 instance using Heat Template

I am using below Heat template for creation of EC2 instance. Though successfully created the EC2 instance, not able to see the commands output in the VM instance after login. I am using default cirros image for VM creation on UBUNTU.

{ "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."
}

},

"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" : {
      "config" : {            

        "commands" : {
            "test" : {
                "command" : "echo \"$MAGIC\" > /tmp/test.txt",
                "env" : { "MAGIC" : "I come from the RTOSS environment!" },
                "cwd" : "~",
                "ignoreErrors" : "false"
            }
        },

        "files" : {
            "/tmp/test2.txt" : {
                "content" : "Content for {{name}}",
                "context" : { "name" : "RTOSS" }
            }
        }
      }
    }
  },
  "Properties": {
    "ImageId" : "62f2fcf4-3ddf-4557-8572-8ebcf949a69d",
    "InstanceType"   : { "Ref" : "InstanceType" }
  }
}

},

"Outputs" : {
"Instance" : { "Value" : { "Ref" : "NewEC2Instance" } } } }

Please let me know incase required any other information.

Unix command is not working on newly created EC2 instance using Heat Template

I am using below Heat template for creation of EC2 instance. Though successfully created the EC2 instance, but not able to see the commands output in the VM instance after login. I am using default cirros image for VM creation on UBUNTU.

{ "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" : {
      "config"     "configSets" : {
              "ascending" : [ "config1" , "config2" ],
              "descending" : [ "config2" , "config1" ]
          },
          "config1" : {
              "commands" : {
                  "test" : {
                      "command" : "sudo echo \"I come from RTOSS1\" > test6.txt",
                      "env" : {            

        "commands" : {
            "test" : {
                "command" : "echo \"$MAGIC\" > /tmp/test.txt",
                "env" : { "MAGIC" "CFNTEST" : "I come from the RTOSS environment!" config1." },
                 "cwd" : "~",
                "ignoreErrors" : "false"
            }
"~"
                  }
              }
          },

        "files" : {
            "/tmp/test2.txt" : {
                "content" : "Content for {{name}}",
                "context"           "config2" : {
              "commands" : {
                  "test" : {
                      "command" : "sudo echo \"I come from RTOSS2\" > test7.txt",
                      "env" : { "name" : "RTOSS" }
            }
        }
      }
    }
"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.

Unix command "UserData" Property in Heat Template is not working on newly created EC2 instance using Heat Templatetriggered

I am using below Heat template for creation of EC2 instance. Though The EC2 instance is successfully created but the EC2 instance, but 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.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.