createDataSource method

Future<CreateDataSourceResponse> createDataSource({
  1. required String indexId,
  2. required String name,
  3. required DataSourceType type,
  4. String? clientToken,
  5. DataSourceConfiguration? configuration,
  6. String? description,
  7. String? roleArn,
  8. String? schedule,
  9. List<Tag>? tags,
})

Creates a data source that you use to with an Amazon Kendra index.

You specify a name, data source connector type and description for your data source. You also specify configuration information such as document metadata (author, source URI, and so on) and user context information.

CreateDataSource is a synchronous operation. The operation returns 200 if the data source was successfully created. Otherwise, an exception is raised.

May throw ValidationException. May throw ConflictException. May throw ResourceNotFoundException. May throw ResourceAlreadyExistException. May throw ServiceQuotaExceededException. May throw ThrottlingException. May throw AccessDeniedException. May throw InternalServerException.

Parameter indexId : The identifier of the index that should be associated with this data source.

Parameter name : A unique name for the data source. A data source name can't be changed without deleting and recreating the data source.

Parameter type : The type of repository that contains the data source.

Parameter clientToken : A token that you provide to identify the request to create a data source. Multiple calls to the CreateDataSource operation with the same client token will create only one data source.

Parameter configuration : The connector configuration information that is required to access the repository.

You can't specify the Configuration parameter when the Type parameter is set to CUSTOM. If you do, you receive a ValidationException exception.

The Configuration parameter is required for all other data sources.

Parameter description : A description for the data source.

Parameter roleArn : The Amazon Resource Name (ARN) of a role with permission to access the data source. For more information, see IAM Roles for Amazon Kendra.

You can't specify the RoleArn parameter when the Type parameter is set to CUSTOM. If you do, you receive a ValidationException exception.

The RoleArn parameter is required for all other data sources.

Parameter schedule : Sets the frequency that Amazon Kendra will check the documents in your repository and update the index. If you don't set a schedule Amazon Kendra will not periodically update the index. You can call the StartDataSourceSyncJob operation to update the index.

You can't specify the Schedule parameter when the Type parameter is set to CUSTOM. If you do, you receive a ValidationException exception.

Parameter tags : A list of key-value pairs that identify the data source. You can use the tags to identify and organize your resources and to control access to resources.

Implementation

Future<CreateDataSourceResponse> createDataSource({
  required String indexId,
  required String name,
  required DataSourceType type,
  String? clientToken,
  DataSourceConfiguration? configuration,
  String? description,
  String? roleArn,
  String? schedule,
  List<Tag>? tags,
}) async {
  ArgumentError.checkNotNull(indexId, 'indexId');
  _s.validateStringLength(
    'indexId',
    indexId,
    36,
    36,
    isRequired: true,
  );
  ArgumentError.checkNotNull(name, 'name');
  _s.validateStringLength(
    'name',
    name,
    1,
    1000,
    isRequired: true,
  );
  ArgumentError.checkNotNull(type, 'type');
  _s.validateStringLength(
    'clientToken',
    clientToken,
    1,
    100,
  );
  _s.validateStringLength(
    'description',
    description,
    0,
    1000,
  );
  _s.validateStringLength(
    'roleArn',
    roleArn,
    1,
    1284,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'AWSKendraFrontendService.CreateDataSource'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'IndexId': indexId,
      'Name': name,
      'Type': type.toValue(),
      'ClientToken': clientToken ?? _s.generateIdempotencyToken(),
      if (configuration != null) 'Configuration': configuration,
      if (description != null) 'Description': description,
      if (roleArn != null) 'RoleArn': roleArn,
      if (schedule != null) 'Schedule': schedule,
      if (tags != null) 'Tags': tags,
    },
  );

  return CreateDataSourceResponse.fromJson(jsonResponse.body);
}