代码之家  ›  专栏  ›  技术社区  ›  liorko

在不同区域中创建高程点实例

  •  0
  • liorko  · 技术社区  · 7 年前

    我正在尝试使用boto3在不同区域创建spot实例。

    botocore.exceptions.ClientError: An error occurred (InvalidParameterValue) when calling the RequestSpotInstances operation: Invalid availability zone: [eu-west-2b]
    

    使用此代码段创建的实例:

    for idx in range(len(regions)):
        client.request_spot_instances(
                DryRun=False,
                SpotPrice=price_bids,
                InstanceCount=number_of_instances,
                LaunchSpecification=
                {
                    'ImageId': ami_id,
                    'KeyName': 'matrix',
                    'SecurityGroupIds': ['sg-5f07f52c'],
                    'SecurityGroups': ['MatrixSG'],
                    'InstanceType': machine_type,
                    'Placement':
                        {
                            'AvailabilityZone': regions[idx],
                        },
                },
        )
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   John Rotenstein    7 年前

    我想你的 regions 可用性区域 'AvailabilityZone': regions[idx] ).

    每个AWS区域独立运行。连接到AWS服务时,必须连接到特定服务 .

    例如:

    client = boto3.client('ec2')
    

    默认区域 .

    或者,可以指定区域:

    client = boto3.client('ec2', region_name = 'eu-west-2')
    

    您正在收到 Invalid availability zone us-east-1 )但是正在引用位于不同区域的可用性区域(例如 eu-west-2b

    您的代码只创建了一次客户端,但正在尝试连接到多个区域。解决方案是 创建新的客户端连接 用于您希望使用的区域。如果循环连接到多个区域,则 client 在循环内 而不是在循环之外。