Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
此用户没有使用.net SDK的默认vpc_.net_Amazon Web Services_Amazon Ec2_Amazon Vpc - Fatal编程技术网

此用户没有使用.net SDK的默认vpc

此用户没有使用.net SDK的默认vpc,.net,amazon-web-services,amazon-ec2,amazon-vpc,.net,Amazon Web Services,Amazon Ec2,Amazon Vpc,我正在尝试构建一个简单的web表单来加速EC2实例。但是当DescripteSecurityGroup响应附加到ec2client对象时,我得到了一个错误。此用户没有默认VPC 任何想法、代码片段: protected void Button_Build_Click(object sender, EventArgs e) { var ec2client = new AmazonEC2Client(RegionEndpoint.USWest1);

我正在尝试构建一个简单的web表单来加速EC2实例。但是当DescripteSecurityGroup响应附加到ec2client对象时,我得到了一个错误。此用户没有默认VPC 任何想法、代码片段:

    protected void Button_Build_Click(object sender, EventArgs e)
    {
        var ec2client = new AmazonEC2Client(RegionEndpoint.USWest1);


        DescribeVpcsRequest foo1 = new DescribeVpcsRequest()
        {
            VpcIds = new List<string> { "vpc-XXXXXX" }
        };

        DescribeVpcsResponse foo2 = ec2client.DescribeVpcs(foo1);
        ec2client.DescribeVpcs(foo1);            
        var secGroupRequest = new DescribeSecurityGroupsRequest()


        {
            GroupNames = new List<String> { securitygroup }

        };


        DescribeSecurityGroupsResponse secGroupResponse = ec2client.DescribeSecurityGroups(secGroupRequest);

       SecurityGroup secGroup = secGroupResponse.SecurityGroups[0]; 



       var runInstancesRequest = new RunInstancesRequest()
       {
           ImageId = ami,
           InstanceType = size,
           MinCount = 1,
           MaxCount = 1,
           KeyName = keypair,
           SubnetId = subnetid



       };
       runInstancesRequest.SecurityGroups.Add(securitygroup);
       runInstancesRequest.SubnetId = subnetid;

请参见AWS文档中的示例代码:

特别是,您需要创建InstanceNetworkInterfaceSpecification对象并将其添加到RunInstanceRequest

1创建对象

List<string> groups = new List<string>() { secGroup.GroupId };
var eni = new InstanceNetworkInterfaceSpecification()
{
    DeviceIndex = 0,
    SubnetId = subnetID,
    Groups = groups,
    AssociatePublicIpAddress = true
};
List<InstanceNetworkInterfaceSpecification> enis = new List<InstanceNetworkInterfaceSpecification>() {eni};
   var runInstancesRequest = new RunInstancesRequest()
   {
       ImageId = ami,
       InstanceType = size,
       MinCount = 1,
       MaxCount = 1,
       KeyName = keypair,
       SubnetId = subnetid,

       //***created above***
       NetworkInterfaces = enis

   };