模板验证错误:模板格式错误:无法识别的资源类型:[AWS :: EC2 :: KeyPair :: KeyName]

时间:2017-06-01 12:34:07

标签: amazon-web-services amazon-ec2 amazon-cloudformation

我正在使用下面的编队模板来创建EC2机器并使用用户数据在其上安装弹性搜索。

我有一个名为" novus1"在我的帐户中。当我尝试创建堆栈时。我得到了无法识别的资源类型:[AWS :: EC2 :: KeyPair :: KeyName]。

以下JSON模板中是否有任何问题?任何支持都表示赞赏。

{
    "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 个答案:

答案 0 :(得分:0)

novus1键名应位于模板的Parameters部分。您可以使用Ref:对象来引用它:

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

有关AWS::EC2::KeyPair::KeyName参数类型的更多示例,请参阅documentation