createOrganization method

Future<CreateOrganizationResponse> createOrganization({
  1. required String alias,
  2. String? clientToken,
  3. String? directoryId,
  4. List<Domain>? domains,
  5. bool? enableInteroperability,
  6. String? kmsKeyArn,
})

Creates a new Amazon WorkMail organization. Optionally, you can choose to associate an existing AWS Directory Service directory with your organization. If an AWS Directory Service directory ID is specified, the organization alias must match the directory alias. If you choose not to associate an existing directory with your organization, then we create a new Amazon WorkMail directory for you. For more information, see Adding an organization in the Amazon WorkMail Administrator Guide.

You can associate multiple email domains with an organization, then set your default email domain from the Amazon WorkMail console. You can also associate a domain that is managed in an Amazon Route 53 public hosted zone. For more information, see Adding a domain and Choosing the default domain in the Amazon WorkMail Administrator Guide.

Optionally, you can use a customer managed master key from AWS Key Management Service (AWS KMS) to encrypt email for your organization. If you don't associate an AWS KMS key, Amazon WorkMail creates a default AWS managed master key for you.

May throw InvalidParameterException. May throw DirectoryInUseException. May throw DirectoryUnavailableException. May throw LimitExceededException. May throw NameAvailabilityException.

Parameter alias : The organization alias.

Parameter clientToken : The idempotency token associated with the request.

Parameter directoryId : The AWS Directory Service directory ID.

Parameter domains : The email domains to associate with the organization.

Parameter enableInteroperability : When true, allows organization interoperability between Amazon WorkMail and Microsoft Exchange. Can only be set to true if an AD Connector directory ID is included in the request.

Parameter kmsKeyArn : The Amazon Resource Name (ARN) of a customer managed master key from AWS KMS.

Implementation

Future<CreateOrganizationResponse> createOrganization({
  required String alias,
  String? clientToken,
  String? directoryId,
  List<Domain>? domains,
  bool? enableInteroperability,
  String? kmsKeyArn,
}) async {
  ArgumentError.checkNotNull(alias, 'alias');
  _s.validateStringLength(
    'alias',
    alias,
    1,
    62,
    isRequired: true,
  );
  _s.validateStringLength(
    'clientToken',
    clientToken,
    1,
    128,
  );
  _s.validateStringLength(
    'directoryId',
    directoryId,
    12,
    12,
  );
  _s.validateStringLength(
    'kmsKeyArn',
    kmsKeyArn,
    20,
    2048,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'WorkMailService.CreateOrganization'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'Alias': alias,
      'ClientToken': clientToken ?? _s.generateIdempotencyToken(),
      if (directoryId != null) 'DirectoryId': directoryId,
      if (domains != null) 'Domains': domains,
      if (enableInteroperability != null)
        'EnableInteroperability': enableInteroperability,
      if (kmsKeyArn != null) 'KmsKeyArn': kmsKeyArn,
    },
  );

  return CreateOrganizationResponse.fromJson(jsonResponse.body);
}