无法修改 AWS 中现货车队的目标容量

Unable to modify target capacity of spot fleet in AWS

我使用 python lambda 函数通过以下代码终止 spot 队列实例,

import boto3
def lambda_handler(event, context):
    
    client = boto3.client('ec2')
      
    response = client.modify_spot_fleet_request(
        ExcessCapacityTerminationPolicy='default',
        SpotFleetRequestId='sfr-xxxxxxxx-593f-4444-9e99-nnnnnnnnnn',
        TargetCapacity=0
    )
    print(response)

但是代码抛出这样的错误,

{
  "errorMessage": "An error occurred (FleetNotInModifiableState) when calling the ModifySpotFleetRequest operation: Fleet Request: sfr-xxxxxxxx-593f-4444-9e99-nnnnnnnnnn is not a modifiable fleet request type.",
  "errorType": "ClientError",
  "requestId": "70e972c1-5d92-4642-93a8-b70cc799e591",
  "stackTrace": [
    "  File \"/var/task/lambda_function.py\", line 23, in lambda_handler\n    response = client.modify_spot_fleet_request(\n",
    "  File \"/var/runtime/botocore/client.py\", line 386, in _api_call\n    return self._make_api_call(operation_name, kwargs)\n",
    "  File \"/var/runtime/botocore/client.py\", line 705, in _make_api_call\n    raise error_class(parsed_response, operation_name)\n"
  ]
}

我该如何解决?

您只能在设置维护目标的情况下修改 SF。来自 docs:

You can't modify a one-time Spot Fleet request. You can only modify a Spot Fleet request if you selected Maintain target capacity when you created the Spot Fleet request.