EC2实例Cloudformation - 可用区域作为参数传递

时间:2017-07-12 19:00:53

标签: amazon-ec2 amazon-cloudformation

我写了一个简单的cloudformation模板,参数很少。所有参数都有效。但是当我通过可用区时,模板在创建过程中会出现“不是有效可用区”的错误。以下是我的错误和代码:

11:48:47 UTC-0700 CREATE_FAILED AWS :: EC2 :: Instance EC2Instance无效的可用区:

   {
       "AWSTemplateFormatVersion": "2010-09-09",
       "Description": "EC2 Head Node Instance ",
       "Parameters": {
              "AZ": {
               "Description": "Availablity Zone",
               "Type": "String"

    },
    "Region":{
        "Description": "Dev/Test/Prod regions",
        "Type": "String"
    },
    "AMI": {
        "Description": "AMI to start virtual server",
        "Type": "String",
        "MaxLength": 12,
        "MinLength": 12
    },

    "Subnet": {
        "Description": "subnet to launch virtual server in",
        "Type": "AWS::EC2::Subnet::Id"
    }

},
"Resources": {
    "EC2Instance": {
        "Type": "AWS::EC2::Instance",
        "Properties": {
            "ImageId": {"Ref": "AMI"},
            "SubnetId": {"Ref": "Subnet"},
            "AvailabilityZone": {"Ref":"AZ"},
            "Tags": [
                {
                    "Key": "Name",
                    "Value": "QRM Head Node in DEV region"
                }
            ]
            }
        }

},
"Outputs": {
    "InstanceId": {
        "Value": {"Ref": "EC2Instance"},
        "Description": "ID of virtual server"
    },

    "PublicIPAddress": {
        "Value": {"Fn::GetAtt": ["EC2Instance", "PublicIp"]},
        "Description": "public IP address of virtual server"
    }
 }

}

1 个答案:

答案 0 :(得分:0)

只需将参数更改为:

"Parameters": {
    "AZ": {
         Description": "Availability Zone of the Subnet",
         "Type": "AWS::EC2::AvailabilityZone::Name"
     },
     ....
 }