Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
450 views
in Technique[技术] by (71.8m points)

amazon web services - 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...