Keiros
Keiros

Reputation: 101

Invalid parameter combnation AWS

I am having trouble debugging an error I am getting.

botocore.exceptions.ClientError: An error occurred (InvalidParameterCombination) when calling the RunInstances operation: Network interfaces and an instance-level subnet ID may not be specified on the same request

This is the code.

    # Make EC2s with AWS Ubuntu 20
    instances = subnet.create_instances(ImageId='ami-0885b1f6bd170450c',
                                        InstanceType='m1.small',
                                        MaxCount=num,
                                        MinCount=num,
                                        Monitoring={'Enabled': True},
                                        KeyName=key_name,
                                        IamInstanceProfile={
                                            'Arn': 'arn goes here',
                                        },
                                        NetworkInterfaces=[{
                                            'DeviceIndex': 0,
                                            'SubnetId': subnet.subnet_id,
                                            'AssociatePublicIpAddress': True,
                                            'Groups': [security_group.group_id]
                                        }])

What is baffling me is that I do not specify a top level subnet id. And even when I remove subnet id entirely I get the error.

My guess is that something is being default set but I do not know how to stop that if it is the case.

Upvotes: 2

Views: 770

Answers (1)

Marcin
Marcin

Reputation: 238199

Your subnet is probably an instance of Subnet class from boto3. Thus by using this you are implicitly setting instance level subnet, resulting in your error.

Thus, I think you should consider using create_instances from boto3.resource('ec2') instead of your subnet.create_instances if you want to manipulate network interfaces:

ec2 = session.resource('ec2') # or boto3.resource('ec2')

instances = ec2.create_instances(
    ImageId='ami-0885b1f6bd170450c',
    InstanceType='m1.small',
    MaxCount=num,
    MinCount=num,
    Monitoring={'Enabled': True},
    KeyName=key_name,
    IamInstanceProfile={
        'Arn': 'arn goes here',
    },
    NetworkInterfaces=[{
        'DeviceIndex': 0,
        'SubnetId': subnet.subnet_id,
        'AssociatePublicIpAddress': True,
        'Groups': [security_group.group_id]
    }])

print(instances)

Upvotes: 2

Related Questions