amazon-web-services - 不允许为 VPC 创建 EC2 实例

标签 amazon-web-services amazon-ec2 aws-sdk aws-cloudformation amazon-vpc

是否可以将 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/

相关文章:

python - 如何在python变量中存储aws组织单元ID和scp策略ID?

amazon-ec2 - 如何在多个ec2实例上更改应用程序?

amazon-web-services - 无法连接到 Docker 容器 : Connection Refused

amazon-ec2 - 我可以从使用实例存储作为根设备的正在运行的实例创建 AMI 吗?

javascript - Aws s3 putObject 同时执行选项请求和放置请求

linux - 如何在AWS卷之间传输数据?

performance - AWS Elastic Beanstalk 偶尔会失败的健康检查

amazon-web-services - Jumpbox 的 AWS CloudFormation 用户数据

amazon-web-services - 在 CloudFormation 中指定要停止而不是终止的 SpotFleet 实例

aws-sdk - 在 aws SageMaker 容器中设置 env 变量(自带容器)