createInstances method

Future<CreateInstancesResult> createInstances({
  1. required String availabilityZone,
  2. required String blueprintId,
  3. required String bundleId,
  4. required List<String> instanceNames,
  5. List<AddOnRequest>? addOns,
  6. String? customImageName,
  7. String? keyPairName,
  8. List<Tag>? tags,
  9. String? userData,
})

Creates one or more Amazon Lightsail instances.

The create instances operation supports tag-based access control via request tags. For more information, see the Lightsail Dev Guide.

May throw ServiceException. May throw InvalidInputException. May throw NotFoundException. May throw OperationFailureException. May throw AccessDeniedException. May throw AccountSetupInProgressException. May throw UnauthenticatedException.

Parameter availabilityZone : The Availability Zone in which to create your instance. Use the following format: us-east-2a (case sensitive). You can get a list of Availability Zones by using the get regions operation. Be sure to add the include Availability Zones parameter to your request.

Parameter blueprintId : The ID for a virtual private server image (e.g., app_wordpress_4_4 or app_lamp_7_0). Use the get blueprints operation to return a list of available images (or blueprints).

Parameter bundleId : The bundle of specification information for your virtual private server (or instance), including the pricing plan (e.g., micro_1_0).

Parameter instanceNames : The names to use for your new Lightsail instances. Separate multiple values using quotation marks and commas, for example: "MyFirstInstance","MySecondInstance"

Parameter addOns : An array of objects representing the add-ons to enable for the new instance.

Parameter customImageName : (Deprecated) The name for your custom image.

Parameter keyPairName : The name of your key pair.

Parameter tags : The tag keys and optional values to add to the resource during create.

Use the TagResource action to tag a resource after it's created.

Parameter userData : A launch script you can create that configures a server with additional user data. For example, you might want to run apt-get -y update.

Implementation

Future<CreateInstancesResult> createInstances({
  required String availabilityZone,
  required String blueprintId,
  required String bundleId,
  required List<String> instanceNames,
  List<AddOnRequest>? addOns,
  String? customImageName,
  String? keyPairName,
  List<Tag>? tags,
  String? userData,
}) async {
  ArgumentError.checkNotNull(availabilityZone, 'availabilityZone');
  ArgumentError.checkNotNull(blueprintId, 'blueprintId');
  ArgumentError.checkNotNull(bundleId, 'bundleId');
  ArgumentError.checkNotNull(instanceNames, 'instanceNames');
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'Lightsail_20161128.CreateInstances'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'availabilityZone': availabilityZone,
      'blueprintId': blueprintId,
      'bundleId': bundleId,
      'instanceNames': instanceNames,
      if (addOns != null) 'addOns': addOns,
      if (customImageName != null) 'customImageName': customImageName,
      if (keyPairName != null) 'keyPairName': keyPairName,
      if (tags != null) 'tags': tags,
      if (userData != null) 'userData': userData,
    },
  );

  return CreateInstancesResult.fromJson(jsonResponse.body);
}