Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

I am trying to create a t2.micro ec2 instance with Amazon Linux as os using cloudformation. Following is the JSON file (parts that matter).

    "FileName" :{

        "Type" : "String",

        "Default" : "cf-file.sh",

        "AllowedValues": [ "cf-file.sh"]

    },

    "InstanceType" : {

      "Description" : "WebServer EC2 instance type",

      "Type" : "String",

      "Default" : "t2.micro",

      "AllowedValues" : ["t2.micro"],

      "ConstraintDescription" : "must be a valid EC2 instance type."

    },

       "AMIID" :{

         "Type": "String",

        "Default":"ami-1ecae776",

        "AllowedValues":["ami-1ecae776"]

    }

  },

  "Resources" : {

    "EC2Instance" : {

      "Type" : "AWS::EC2::Instance",

      "Properties" : {

        "UserData" : {

                "Fn::Base64" : {

                    "Fn::Join" : [ 

                            "", 

                            [

                                "#!/bin/bash\n",

                                "yes y | yum install dos2unix\n",

                                "touch ",{ "Ref" : "FileName" },"\n",

                                "chmod 777 ",{ "Ref" : "FileName" },"\n" 

                            ]

                    ]

                 } 

        },

          "KeyName" : { "Ref" : "KeyName" },

        "ImageId" : { "Ref" : "AMIID" }

      }

    },

When i run this file i get following error

Non-Windows instances with a virtualization type of 'hvm' are currently not supported for this instance type

I guess this error comes when we use t1 family instance type but I am using t2.micro. Please explain the reason why is it so?

1 Answer

0 votes
by (44.4k points)

If you do not mention “InstanceType” in the Properties section of Resources, it will not work. Also, it will in default take (m1.small) instance which does not support ‘HVM’. So, use this below code snippet:

"Parameters":{

    "ServerKeyName":{

        "Description" :"key pair to connect to Server",

        "Type": "AWS::EC2::KeyPair::KeyName"

    },

    "InstanceType" : {

        "Description" : "Type of EC2 instance to launch",

        "Type" : "String",

        "Default" : "t2.micro"

    },

    ....

    ....

}

....

....

"Properties": {

    "KeyName" : { "Ref" : "ServerKeyName" },

    "Tags" : [

    {

        "Key" : "Name",

        "Value" : "test Server"

    }],

    "ImageId" : { "Ref" : "InstanceAMI" },

    "InstanceType" : { "Ref" : "InstanceType"},

    ....

    ....

    ....

}

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...