updateFleetCapacity method
Updates capacity settings for a fleet. Use this operation to specify the number of EC2 instances (hosts) that you want this fleet to contain. Before calling this operation, you may want to call DescribeEC2InstanceLimits to get the maximum capacity based on the fleet's EC2 instance type.
Specify minimum and maximum number of instances. Amazon GameLift will not change fleet capacity to values fall outside of this range. This is particularly important when using auto-scaling (see PutScalingPolicy) to allow capacity to adjust based on player demand while imposing limits on automatic adjustments.
To update fleet capacity, specify the fleet ID and the number of instances you want the fleet to host. If successful, Amazon GameLift starts or terminates instances so that the fleet's active instance count matches the desired instance count. You can view a fleet's current capacity information by calling DescribeFleetCapacity. If the desired instance count is higher than the instance type's limit, the "Limit Exceeded" exception occurs.
Learn more
Related operations
- CreateFleet
- ListFleets
- DeleteFleet
- DescribeFleetAttributes
- Update fleets:
- StartFleetActions or StopFleetActions
May throw NotFoundException. May throw ConflictException. May throw LimitExceededException. May throw InvalidFleetStatusException. May throw InternalServiceException. May throw InvalidRequestException. May throw UnauthorizedException.
Parameter fleetId
:
A unique identifier for a fleet to update capacity for. You can use either
the fleet ID or ARN value.
Parameter desiredInstances
:
Number of EC2 instances you want this fleet to host.
Parameter maxSize
:
The maximum value allowed for the fleet's instance count. Default if not
set is 1.
Parameter minSize
:
The minimum value allowed for the fleet's instance count. Default if not
set is 0.
Implementation
Future<UpdateFleetCapacityOutput> updateFleetCapacity({
required String fleetId,
int? desiredInstances,
int? maxSize,
int? minSize,
}) async {
ArgumentError.checkNotNull(fleetId, 'fleetId');
_s.validateNumRange(
'desiredInstances',
desiredInstances,
0,
1152921504606846976,
);
_s.validateNumRange(
'maxSize',
maxSize,
0,
1152921504606846976,
);
_s.validateNumRange(
'minSize',
minSize,
0,
1152921504606846976,
);
final headers = <String, String>{
'Content-Type': 'application/x-amz-json-1.1',
'X-Amz-Target': 'GameLift.UpdateFleetCapacity'
};
final jsonResponse = await _protocol.send(
method: 'POST',
requestUri: '/',
exceptionFnMap: _exceptionFns,
// TODO queryParams
headers: headers,
payload: {
'FleetId': fleetId,
if (desiredInstances != null) 'DesiredInstances': desiredInstances,
if (maxSize != null) 'MaxSize': maxSize,
if (minSize != null) 'MinSize': minSize,
},
);
return UpdateFleetCapacityOutput.fromJson(jsonResponse.body);
}