launchInstances method

Future<LaunchInstancesResult> launchInstances({
  1. required String autoScalingGroupName,
  2. required int requestedCapacity,
  3. List<String>? availabilityZoneIds,
  4. List<String>? availabilityZones,
  5. String? clientToken,
  6. RetryStrategy? retryStrategy,
  7. List<String>? subnetIds,
})

Launches a specified number of instances in an Auto Scaling group. Returns instance IDs and other details if launch is successful or error details if launch is unsuccessful.

May throw IdempotentParameterMismatchError. May throw ResourceContentionFault.

Parameter autoScalingGroupName : The name of the Auto Scaling group to launch instances into.

Parameter requestedCapacity : The number of instances to launch. Although this value can exceed 100 for instance weights, the actual instance count is limited to 100 instances per launch.

Parameter availabilityZoneIds : A list of Availability Zone IDs where instances should be launched. Must match or be included in the group's AZ configuration. You cannot specify both AvailabilityZones and AvailabilityZoneIds. Required for multi-AZ groups, optional for single-AZ groups.

Parameter availabilityZones : The Availability Zones for the instance launch. Must match or be included in the Auto Scaling group's Availability Zone configuration. Either AvailabilityZones or SubnetIds must be specified for groups with multiple Availability Zone configurations.

Parameter clientToken : A unique, case-sensitive identifier to ensure idempotency of the request.

Parameter retryStrategy : Specifies whether to retry asynchronously if the synchronous launch fails. Valid values are NONE (default, no async retry) and RETRY_WITH_GROUP_CONFIGURATION (increase desired capacity and retry with group configuration).

Parameter subnetIds : The subnet IDs for the instance launch. Either AvailabilityZones or SubnetIds must be specified. If both are specified, the subnets must reside in the specified Availability Zones.

Implementation

Future<LaunchInstancesResult> launchInstances({
  required String autoScalingGroupName,
  required int requestedCapacity,
  List<String>? availabilityZoneIds,
  List<String>? availabilityZones,
  String? clientToken,
  RetryStrategy? retryStrategy,
  List<String>? subnetIds,
}) async {
  _s.validateNumRange(
    'requestedCapacity',
    requestedCapacity,
    1,
    1152921504606846976,
    isRequired: true,
  );
  final $request = <String, String>{
    'AutoScalingGroupName': autoScalingGroupName,
    'RequestedCapacity': requestedCapacity.toString(),
    if (availabilityZoneIds != null)
      if (availabilityZoneIds.isEmpty)
        'AvailabilityZoneIds': ''
      else
        for (var i1 = 0; i1 < availabilityZoneIds.length; i1++)
          'AvailabilityZoneIds.member.${i1 + 1}': availabilityZoneIds[i1],
    if (availabilityZones != null)
      if (availabilityZones.isEmpty)
        'AvailabilityZones': ''
      else
        for (var i1 = 0; i1 < availabilityZones.length; i1++)
          'AvailabilityZones.member.${i1 + 1}': availabilityZones[i1],
    'ClientToken': clientToken ?? _s.generateIdempotencyToken(),
    if (retryStrategy != null) 'RetryStrategy': retryStrategy.value,
    if (subnetIds != null)
      if (subnetIds.isEmpty)
        'SubnetIds': ''
      else
        for (var i1 = 0; i1 < subnetIds.length; i1++)
          'SubnetIds.member.${i1 + 1}': subnetIds[i1],
  };
  final $result = await _protocol.send(
    $request,
    action: 'LaunchInstances',
    version: '2011-01-01',
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    resultWrapper: 'LaunchInstancesResult',
  );
  return LaunchInstancesResult.fromXml($result);
}