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地址。
发布于 2014-04-05 08:35:00
格式正确:我忘了在实例网络接口规范中添加设备索引。我创建了安全组的字符串列表。然后,我创建了createnetworkinterfacerequest对象,并添加了子网id和安全组。然后创建createnetworkinterfaceresponse对象并创建接口。接下来,我创建instancenetworkinterfacespecification项并将其添加到列表中。最后,我运行了runinstancerequest,然后,它成功了。
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
};
https://stackoverflow.com/questions/22845799
复制相似问题