0
votes

I am using below could formation template to create a EC2 machine and install elastic search on it using user data.

I have a key pair named "novus1" in my account. When I try creating a stack. I get Unrecognized resource types: [AWS::EC2::KeyPair::KeyName].

Is there any issue in the below JSON template? Any support is appreciated.

{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "Basic template for Novus",
    "Resources": {
        "novus1": {
            "Description": "Name of an existing EC2 KeyPair to enable SSH access to the web server",
            "Type": "AWS::EC2::KeyPair::KeyName"
        },
        "Ec2Instance1": {
            "Type": "AWS::EC2::Instance",
            "Properties": {
                "InstanceType": "t2.micro",
                "ImageId": "ami-4836a428",
                "KeyName": "novus1",
                "UserData": {
                    "Fn::Base64": {
                        "Fn::Join": ["", [
                            "rpm -ivh elasticsearch-5.2.1.rpm"
                        ]]
                    }
                }
            }
        }
    }
}
1

1 Answers

0
votes

The novus1 keyname should be in the Parameters section of your template. You can refer to it using the Ref: object:

{   
    "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "Basic template for Novus",
    "Parameters": {
        "novus1": {
            "Type": "AWS::EC2::KeyPair::KeyName",
            "Description": "Name of an existing EC2 KeyPair to enable SSH access to the web server"
        }
    }
    "Resources": {
        "Ec2Instance1": {
            "Type": "AWS::EC2::Instance",
            "Properties": {
                "InstanceType": "t2.micro",
                "ImageId": "ami-4836a428",
                "KeyName": {
                    "Ref": "novus1"
                },
                "UserData": {
                    "Fn::Base64": {
                        "Fn::Join": ["", [
                            "rpm -ivh elasticsearch-5.2.1.rpm"
                        ]]
                    }
                }
            }
        }
    }
}

See documentation for more examples on the AWS::EC2::KeyPair::KeyName parameter type.