createDataSource method

Future<CreateDataSourceResponse> createDataSource({
  1. required String apiId,
  2. required String name,
  3. required DataSourceType type,
  4. String? description,
  5. DynamodbDataSourceConfig? dynamodbConfig,
  6. ElasticsearchDataSourceConfig? elasticsearchConfig,
  7. EventBridgeDataSourceConfig? eventBridgeConfig,
  8. HttpDataSourceConfig? httpConfig,
  9. LambdaDataSourceConfig? lambdaConfig,
  10. DataSourceLevelMetricsConfig? metricsConfig,
  11. OpenSearchServiceDataSourceConfig? openSearchServiceConfig,
  12. RelationalDatabaseDataSourceConfig? relationalDatabaseConfig,
  13. String? serviceRoleArn,
})

Creates a DataSource object.

May throw BadRequestException. May throw ConcurrentModificationException. May throw InternalFailureException. May throw NotFoundException. May throw UnauthorizedException.

Parameter apiId : The API ID for the GraphQL API for the DataSource.

Parameter name : A user-supplied name for the DataSource.

Parameter type : The type of the DataSource.

Parameter description : A description of the DataSource.

Parameter dynamodbConfig : Amazon DynamoDB settings.

Parameter elasticsearchConfig : Amazon OpenSearch Service settings.

As of September 2021, Amazon Elasticsearch service is Amazon OpenSearch Service. This configuration is deprecated. For new data sources, use CreateDataSourceRequest$openSearchServiceConfig to create an OpenSearch data source.

Parameter eventBridgeConfig : Amazon EventBridge settings.

Parameter httpConfig : HTTP endpoint settings.

Parameter lambdaConfig : Lambda settings.

Parameter metricsConfig : Enables or disables enhanced data source metrics for specified data sources. Note that metricsConfig won't be used unless the dataSourceLevelMetricsBehavior value is set to PER_DATA_SOURCE_METRICS. If the dataSourceLevelMetricsBehavior is set to FULL_REQUEST_DATA_SOURCE_METRICS instead, metricsConfig will be ignored. However, you can still set its value.

metricsConfig can be ENABLED or DISABLED.

Parameter openSearchServiceConfig : Amazon OpenSearch Service settings.

Parameter relationalDatabaseConfig : Relational database settings.

Parameter serviceRoleArn : The Identity and Access Management (IAM) service role Amazon Resource Name (ARN) for the data source. The system assumes this role when accessing the data source.

Implementation

Future<CreateDataSourceResponse> createDataSource({
  required String apiId,
  required String name,
  required DataSourceType type,
  String? description,
  DynamodbDataSourceConfig? dynamodbConfig,
  ElasticsearchDataSourceConfig? elasticsearchConfig,
  EventBridgeDataSourceConfig? eventBridgeConfig,
  HttpDataSourceConfig? httpConfig,
  LambdaDataSourceConfig? lambdaConfig,
  DataSourceLevelMetricsConfig? metricsConfig,
  OpenSearchServiceDataSourceConfig? openSearchServiceConfig,
  RelationalDatabaseDataSourceConfig? relationalDatabaseConfig,
  String? serviceRoleArn,
}) async {
  final $payload = <String, dynamic>{
    'name': name,
    'type': type.value,
    if (description != null) 'description': description,
    if (dynamodbConfig != null) 'dynamodbConfig': dynamodbConfig,
    if (elasticsearchConfig != null)
      'elasticsearchConfig': elasticsearchConfig,
    if (eventBridgeConfig != null) 'eventBridgeConfig': eventBridgeConfig,
    if (httpConfig != null) 'httpConfig': httpConfig,
    if (lambdaConfig != null) 'lambdaConfig': lambdaConfig,
    if (metricsConfig != null) 'metricsConfig': metricsConfig.value,
    if (openSearchServiceConfig != null)
      'openSearchServiceConfig': openSearchServiceConfig,
    if (relationalDatabaseConfig != null)
      'relationalDatabaseConfig': relationalDatabaseConfig,
    if (serviceRoleArn != null) 'serviceRoleArn': serviceRoleArn,
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'POST',
    requestUri: '/v1/apis/${Uri.encodeComponent(apiId)}/datasources',
    exceptionFnMap: _exceptionFns,
  );
  return CreateDataSourceResponse.fromJson(response);
}