是否可以将 EC2 实例模板的 VPCId 定义为属性?
我想做的是,
"Resources" : {
"Ec2Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"SecurityGroups": [ { "Ref": "AWSSecurityGroups" } ],
"KeyName" : { "Ref" : "KeyName" },
"InstanceType" : { "Ref" : "InstanceType" },
"Tags" : [ { "Key" : "Name", "Value" : "Softnas-CF" }],
"ImageId" : { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "AMI" ]},
"VpcId" : { "Ref" : "VPCId" },
.....some other stuff...
},
在我的参数中,我定义了 VPCId,
"Parameters" : {
....
"VPCId": {
"Description": "Name of an existing VPC ID",
"Type": "AWS::EC2::VPC::Id",
"ConstraintDescription": "must be the name of an existing VPC Id."
},
...
},
但是当我创建堆栈时(通过 .net api),它回滚并出现错误
Encountered unsupported property VpcId
这是不允许的吗,我找不到任何文档来执行此操作。这样做作为一个实验。如果使用模板创建,EC2 实例是否始终在默认 VPC 中创建?
最佳答案
Ec2Instance:Properties
不支持VpcId
使用SubnetId
。
"Ec2Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"SecurityGroupIds" : [ { "Ref" : "xxxxx" } ],
"Tags" : [ { "Key" : "Name", "Value" : "xxx" } ],
"ImageId" : { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "AMI" ]},
"SubnetId" : { "Ref" : "VpcSubnet" },
"InstanceType" : { "Ref" : "InstanceType" },
....
"VpcSubnet": {
"Description" : "Enter the VPC subnet",
"Type" : "AWS::EC2::Subnet::Id",
"Default" : ""
},
关于amazon-web-services - 不允许为 VPC 创建 EC2 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36439206/