I was using a python lambda function to terminate spot fleet instances using the below code,
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)
but the code throw error like this,
{
"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"
]
}
How can I resolve it?