Aws-sdk-php: error message: Network interfaces and an instance-level subnet ID may not be specified on the same request

Created on 13 Feb 2014  路  6Comments  路  Source: aws/aws-sdk-php

hi, i got that error when trying to launch an instance. here is my config:

$result = $ec2Client->runInstances(array(
    "DryRun" => false,
    "ImageId" => "ami-xxxxxxxx",
    "MinCount" => 1,
    "MaxCount" => 1,
    "KeyName" => "keypairname",
    "SecurityGroupIds" => array("sg-xxxxxxx"),
    "InstanceType" => "m1.medium",
    "Placement" => array(
        "AvailabilityZone" => "ap-southeast-1a",
        "Tenancy" => "default"
    ),
    "Monitoring" => array(
        "Enabled" => false,
    ),
    "SubnetId" => "subnet-xxxxxx",
    "DisableApiTermination" => false,
    "InstanceInitiatedShutdownBehavior" => "stop",
    "PrivateIpAddress" => "10.10.10.10",
    "NetworkInterfaces" => array(
        array(
            "DeviceIndex" => 0,
            "SubnetId" => "subnet-xxxxxx",
            "Description" => "primary",
            "PrivateIpAddress" => "10.10.10.10",
              "Groups" => array("sg-xxxxxxxx"),
            "DeleteOnTermination" => true,
            "PrivateIpAddresses" => array(
                array(
                    "PrivateIpAddress" => "10.10.10.10",
                    "Primary" => true,
                ),
            ),
            "AssociatePublicIpAddress" => true,
        ),

    ), 
    "EbsOptimized" => false,
));

and here is the full response:

PHP Fatal error:  Uncaught Aws\Ec2\Exception\Ec2Exception: AWS Error Code: InvalidParameterCombination, Status Code: 400, AWS Request ID: 4f46d35f-7604-4b97-bae3-8d20c00ac912, AWS Error Type: client, AWS Error Message: Network interfaces and an instance-level subnet ID may not be specified on the same request, User-Agent: aws-sdk-php2/2.5.2 Guzzle/3.8.1 curl/7.32.0 PHP/5.5.8

Most helpful comment

Based on the error message from Amazon EC2, I think you need to remove the outer parameter: "SubnetId" => "subnet-xxxxxx" but keep the one that you are using inside of the "NetworkInterfaces" setting.

All 6 comments

Based on the error message from Amazon EC2, I think you need to remove the outer parameter: "SubnetId" => "subnet-xxxxxx" but keep the one that you are using inside of the "NetworkInterfaces" setting.

I'll go ahead and resolve this issue. Feel free to reopen if you are still experiencing issues.

I think this bug might have regressed. I'm getting this error:

PHP Fatal error:  Uncaught Aws\Ec2\Exception\Ec2Exception: AWS Error Code: InvalidParameterCombination, Status Code: 400, AWS Request ID: e3deac8f-2a15-460b-bfed-de5db66d87a2, AWS Error Type: client, AWS Error Message: Network interfaces and an instance-level security groups may not be specified on the same request, User-Agent: aws-sdk-php2/2.8.6 Guzzle/3.9.3 curl/7.37.1 PHP/5.5.20
  thrown in phar:///usr/local/bin/aws.phar/Aws/Common/Exception/NamespaceExceptionFactory.php on line 91

And heres the code:

$response = $ec2Client -> runInstances(array(
    'ImageId' => 'ami-fd9cecc7',
    'MinCount' => '1',
    'MaxCount' => '1',
    'InstanceType' => 'c4.xlarge',
    'KeyName' => 'mykey',
    'NetworkInterfaces' => array(array(
        'DeviceIndex' => 0,
        'SubnetId' => 'subnet-xxxxxxxx',
        'AssociatePublicIpAddress' => true
    )),
    'SecurityGroupIds' => array('sg-xxxxxxxx','sg-xxxxxxxx'),
));

May I report what I have got using aws-sdk apiVersion: '2016-11-15' with node.js

message: 'Network interfaces and an instance-level security groups may not be specified on the same request',
code: 'InvalidParameterCombination',
time: 2017-02-22T04:09:22.463Z,
requestId: 'ed4f81ed-0447-4770-ac82-605fee6d5d28',
statusCode: 400,
retryable: false,

and this is my code:

var params = {
   ImageId: myConfig.ImageId, // use our own ami
   InstanceType: myConfig.InstanceType, // use our own type
   MinCount: 1,
   MaxCount: 1,
   KeyName: myConfig.KeyName,
   //SecurityGroupIds: myConfig.SecurityGroupIds, // which is string like "sg-123abc32"
   //[2017-02-22] commented out due to complaint of "Network interfaces and an instance-level security groups may not be specified on the same request"; it works without this key
   NetworkInterfaces: [
    {
      AssociatePublicIpAddress: false, // false here
      DeviceIndex: 0,
    }
  ]
};

Thanks it solved my issue. @mtdowling Thank you.

@mtdowling thank you for solving this prolem

Was this page helpful?
0 / 5 - 0 ratings