如何在预先创建的 VPC 中启动一个实例,并且还应该为它提供 Public IP?

How to launch an instance in a pre created VPC and it should be provisioned with Public IP as well?

我正在使用下面的云形成模板在已创建的 VPC 中启动一个实例。此实例正在所需的 VPC 中创建。但是我也需要为这个实例提供 Public IP。试了很多方案都解决不了。请有人帮助我。

 {
 "AWSTemplateFormatVersion": "2010-09-09",
 "Description": "Ec2 block device mapping",
 "Resources": {
   "MyEC2Instance": {
     "Type": "AWS::EC2::Instance",
     "Properties": {
       "ImageId": "ami-0bbd146b",
       "AvailabilityZone": "us-west-2a",
       "SubnetId": "subnet-e1b24b86",
       "SecurityGroupIds": [ "sg-fad0c383" ],
       "KeyName": "TibcoBuild",
       "Tags": [{
         "Key": "Name",
           "Value": "VPCTest"
       }]
     }
   }
}
}

你尝试了什么?它实际上非常简单并记录在此处:http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance.html

"Ec2Instance" : {
  "Type" : "AWS::EC2::Instance",
  "Properties" : {
    "ImageId" : { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "AMI" ]},
    "KeyName" : { "Ref" : "KeyName" },
    "NetworkInterfaces": [ {
      "AssociatePublicIpAddress": "true",
      "DeviceIndex": "0",
      "GroupSet": [{ "Ref" : "myVPCEC2SecurityGroup" }],
      "SubnetId": { "Ref" : "PublicSubnet" }
    } ]
  }
}