不允许为VPC创建EC2实例 [英] Create an EC2 instance for a VPC not allowed

查看:83
本文介绍了不允许为VPC创建EC2实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将EC2实例模板的VPCId定义为属性?

Is it possible to define VPCId for an EC2 instance template as a property?

我尝试执行的操作类似于

I am trying to do is something like,

"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,

In my parameters I define 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)时,它回滚并出现错误

But when I creating the stack (via the .net api), it Rollback with the error


遇到不受支持的属性VpcId

Encountered unsupported property VpcId

这是不允许的,我找不到任何文档来做到这一点。做这个实验。如果使用模板创建EC2实例,是否总是在默认VPC中创建它?

Isn't this allowed, I couldn't find any documentation to do this. Doing this as an experiment. Is the EC2 instance always gets created in the default VPC if created using templates?

推荐答案

VpcId Ec2Instance中不受支持:属性

使用 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" : ""
},

这篇关于不允许为VPC创建EC2实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆