【问题标题】:Invalid parameter combnation AWS无效的参数组合 AWS
【发布时间】:2020-12-31 07:41:40
【问题描述】:

我在调试遇到的错误时遇到问题。

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

这是代码。

    # 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]
                                        }])

令我困惑的是我没有指定顶级子网 ID。即使我完全删除了子网 ID,我也会收到错误消息。

我的猜测是默认设置了某些东西,但如果是这种情况,我不知道如何停止。

【问题讨论】:

  • Boto3 有一个子网对象 - 看来他正在调用这个方法:boto3.amazonaws.com/v1/documentation/api/latest/reference/… 我的第一个想法是,通过使用子网.create_instances,子网被无意中指定了两次,但奇怪的是文档似乎暗示尽管创建调用是通过特定的子网对象执行的,但未指定它将使用默认的 VPC 和子网。也许尝试离开 DeviceIndex?
  • 没用 :(

标签: amazon-web-services amazon-ec2


【解决方案1】:

您的subnet 可能是来自boto3Subnet 类的一个实例。因此,通过使用它,您将隐式设置实例级子网,从而导致您的错误。

因此,如果您想操作网络接口,我认为您应该考虑使用来自boto3.resource('ec2')create_instances 而不是您的subnet.create_instances

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)

【讨论】:

  • @Keiros 没问题。很少编辑问题以修复缩进。
猜你喜欢
  • 2019-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-24
  • 2019-08-31
  • 2019-10-22
  • 1970-01-01
  • 2019-12-23
相关资源
最近更新 更多