首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >使用公网IP将EC2实例启动到私有网络中

使用公网IP将EC2实例启动到私有网络中
EN

Stack Overflow用户
提问于 2014-04-04 02:19:59
回答 1查看 1.2K关注 0票数 2
代码语言:javascript
代码运行次数:0
运行
复制
InstanceNetworkInterfaceSpecification vpc = new InstanceNetworkInterfaceSpecification()
{
SubnetId = "subnet-sadfsadf",
    AssociatePublicIpAddress = true,
    DeleteOnTermination = false

};
List<InstanceNetworkInterfaceSpecification> temp= new List<InstanceNetworkInterfaceSpecification>();
            temp.Add(vpc);

//Create and initialize a RunInstanceRequest
RunInstancesRequest newInstanceRequest = new RunInstancesRequest()
{
   ImageId = appdbAMI,
   InstanceType = appdbType,
   MinCount = 1,
   MaxCount = appdbQuantity,
   KeyName = ec2Key,
   NetworkInsterfaces = temp,
   BlockDeviceMappings = resp.Images[0].BlockDeviceMappings
   //DisableApiTermination = true
};

这不会将实例启动到具有公网ip地址的私有网络中。它有什么问题?我想将一个实例启动到一个私有网络中,并为其分配一个公网ip地址。

EN

回答 1

Stack Overflow用户

发布于 2014-04-05 08:35:00

格式正确:我忘了在实例网络接口规范中添加设备索引。我创建了安全组的字符串列表。然后,我创建了createnetworkinterfacerequest对象,并添加了子网id和安全组。然后创建createnetworkinterfaceresponse对象并创建接口。接下来,我创建instancenetworkinterfacespecification项并将其添加到列表中。最后,我运行了runinstancerequest,然后,它成功了。

代码语言:javascript
代码运行次数:0
运行
复制
List<string> secgrps = new List<string>(new string[] { "sg-2143", "sg-1234" });
CreateNetworkInterfaceRequest cnireq = new CreateNetworkInterfaceRequest()
{ 
SubnetId = "subnet-1234", 
Groups = secgrps 
};
CreateNetworkInterfaceResponse cniresp = ec2Client.CreateNetworkInterface(cnireq);
InstanceNetworkInterfaceSpecification inis = new InstanceNetworkInterfaceSpecification()
{ 
SubnetId = cniresp.NetworkInterface.SubnetId, 
Groups = secgrps, 
AssociatePublicIpAddress = true, 
DeviceIndex=0 
};
List<InstanceNetworkInterfaceSpecification> inisList = new List<InstanceNetworkInterfaceSpecification>();
inisList.Add(inis);

//Create and initialize a RunInstanceRequest
RunInstancesRequest newInstanceRequest = new RunInstancesRequest()
{
    ImageId = appdbAMI,
    InstanceType = appdbType,
    MinCount = 1,
    MaxCount = appdbQuantity,
    KeyName = ec2Key,
    //SecurityGroups = appdbSecurity,
    NetworkInterfaces = inisList,
    BlockDeviceMappings = resp.Images[0].BlockDeviceMappings
    //DisableApiTermination = true
};
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22845799

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档