Skip to content

create_data_source_from_redshift async

create_data_source_from_redshift(
    data_source_id: EntityId,
    data_spec: RedshiftDataSpec,
    role_arn: RoleARN,
    *,
    config_overrides: Optional[AsyncMachineLearningClientConfig] = None,
    data_source_name: Optional[EntityName] = None,
    compute_statistics: Optional[ComputeStatistics] = None,
) -> CreateDataSourceFromRedshiftOutput

Creates a DataSource from a database hosted on an Amazon Redshift cluster. A DataSource references data that can be used to perform either CreateMLModel, CreateEvaluation, or CreateBatchPrediction operations.

CreateDataSourceFromRedshift is an asynchronous operation. In response to CreateDataSourceFromRedshift, Amazon Machine Learning (Amazon ML) immediately returns and sets the DataSource status to PENDING. After the DataSource is created and ready for use, Amazon ML sets the Status parameter to COMPLETED. DataSource in COMPLETED or PENDING states can be used to perform only CreateMLModel, CreateEvaluation, or CreateBatchPrediction operations.

If Amazon ML can't accept the input source, it sets the Status parameter to FAILED and includes an error message in the Message attribute of the GetDataSource operation response.

The observations should be contained in the database hosted on an Amazon Redshift cluster and should be specified by a SelectSqlQuery query. Amazon ML executes an Unload command in Amazon Redshift to transfer the result set of the SelectSqlQuery query to S3StagingLocation.

After the DataSource has been created, it's ready for use in evaluations and batch predictions. If you plan to use the DataSource to train an MLModel, the DataSource also requires a recipe. A recipe describes how each input variable will be used in training an MLModel. Will the variable be included or excluded from training? Will the variable be manipulated; for example, will it be combined with another variable or will it be split apart into word combinations? The recipe provides answers to these questions.

You can't change an existing datasource, but you can copy and modify the settings from an existing Amazon Redshift datasource to create a new datasource. To do so, call GetDataSource for an existing datasource and copy the values to a CreateDataSource call. Change the settings that you want to change and make sure that all required fields have the appropriate values.

Parameters:

  • data_source_id (EntityId) –

    A user-supplied ID that uniquely identifies the DataSource.

  • data_source_name (Optional[EntityName], default: None ) –

    A user-supplied name or description of the DataSource.

  • data_spec (RedshiftDataSpec) –

    The data specification of an Amazon Redshift DataSource:

    • DatabaseInformation -

      • DatabaseName - The name of the Amazon Redshift database.

      • ClusterIdentifier - The unique ID for the Amazon Redshift cluster.

    • DatabaseCredentials - The AWS Identity and Access Management (IAM) credentials that are used to connect to the Amazon Redshift database.

    • SelectSqlQuery - The query that is used to retrieve the observation data for the Datasource.

    • S3StagingLocation - The Amazon Simple Storage Service (Amazon S3) location for staging Amazon Redshift data. The data retrieved from Amazon Redshift using the SelectSqlQuery query is stored in this location.

    • DataSchemaUri - The Amazon S3 location of the DataSchema.

    • DataSchema - A JSON string representing the schema. This is not required if DataSchemaUri is specified.

    • DataRearrangement - A JSON string that represents the splitting and rearrangement requirements for the DataSource.

      Sample - "{\"splitting\":{\"percentBegin\":10,\"percentEnd\":60}}"

  • role_arn (RoleARN) –

    A fully specified role Amazon Resource Name (ARN). Amazon ML assumes the role on behalf of the user to create the following:

    • A security group to allow Amazon ML to execute the SelectSqlQuery query on an Amazon Redshift cluster

    • An Amazon S3 bucket policy to grant Amazon ML read/write permissions on the S3StagingLocation

  • compute_statistics (Optional[ComputeStatistics], default: None ) –

    The compute statistics for a DataSource. The statistics are generated from the observation data referenced by a DataSource. Amazon ML uses the statistics internally during MLModel training. This parameter must be set to true if the DataSource needs to be used for MLModel training.

Raises:

  • IdempotentParameterMismatchException –

    A second request to use or change an object was not allowed. This can result from retrying a request using a parameter that was not present in the original request.

  • InternalServerException –

    An error on the server occurred when trying to process a request.

  • InvalidInputException –

    An error on the client occurred. Typically, the cause is an invalid input value.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_machine_learning/_services/async_machine_learning.py
async def create_data_source_from_redshift(
    self,
    data_source_id: "capo_machine_learning.types.entity_id.EntityId",
    data_spec: "capo_machine_learning.types.redshift_data_spec.RedshiftDataSpec",
    role_arn: "capo_machine_learning.types.role_arn.RoleARN",
    *,
    config_overrides: Optional[AsyncMachineLearningClientConfig] = None,
    data_source_name: Optional[
        "capo_machine_learning.types.entity_name.EntityName"
    ] = None,
    compute_statistics: Optional[
        "capo_machine_learning.types.compute_statistics.ComputeStatistics"
    ] = None,
) -> "capo_machine_learning.types.create_data_source_from_redshift_output.CreateDataSourceFromRedshiftOutput":
    r"""<p>Creates a <code>DataSource</code> from a database hosted on an Amazon Redshift cluster. A <code>DataSource</code> references data that can be used to perform either <code>CreateMLModel</code>, <code>CreateEvaluation</code>, or <code>CreateBatchPrediction</code> operations.</p> <p> <code>CreateDataSourceFromRedshift</code> is an asynchronous operation. In response to <code>CreateDataSourceFromRedshift</code>, Amazon Machine Learning (Amazon ML) immediately returns and sets the <code>DataSource</code> status to <code>PENDING</code>. After the <code>DataSource</code> is created and ready for use, Amazon ML sets the <code>Status</code> parameter to <code>COMPLETED</code>. <code>DataSource</code> in <code>COMPLETED</code> or <code>PENDING</code> states can be used to perform only <code>CreateMLModel</code>, <code>CreateEvaluation</code>, or <code>CreateBatchPrediction</code> operations. </p> <p> If Amazon ML can't accept the input source, it sets the <code>Status</code> parameter to <code>FAILED</code> and includes an error message in the <code>Message</code> attribute of the <code>GetDataSource</code> operation response. </p> <p>The observations should be contained in the database hosted on an Amazon Redshift cluster and should be specified by a <code>SelectSqlQuery</code> query. Amazon ML executes an <code>Unload</code> command in Amazon Redshift to transfer the result set of the <code>SelectSqlQuery</code> query to <code>S3StagingLocation</code>.</p> <p>After the <code>DataSource</code> has been created, it's ready for use in evaluations and batch predictions. If you plan to use the <code>DataSource</code> to train an <code>MLModel</code>, the <code>DataSource</code> also requires a recipe. A recipe describes how each input variable will be used in training an <code>MLModel</code>. Will the variable be included or excluded from training? Will the variable be manipulated; for example, will it be combined with another variable or will it be split apart into word combinations? The recipe provides answers to these questions.</p> <p>You can't change an existing datasource, but you can copy and modify the settings from an existing Amazon Redshift datasource to create a new datasource. To do so, call <code>GetDataSource</code> for an existing datasource and copy the values to a <code>CreateDataSource</code> call. Change the settings that you want to change and make sure that all required fields have the appropriate values.</p>

    Args:
        data_source_id: <p>A user-supplied ID that uniquely identifies the <code>DataSource</code>.</p>
        data_source_name: <p>A user-supplied name or description of the <code>DataSource</code>. </p>
        data_spec: <p>The data specification of an Amazon Redshift <code>DataSource</code>:</p> <ul> <li> <p>DatabaseInformation -</p> <ul> <li> <p> <code>DatabaseName</code> - The name of the Amazon Redshift database.</p> </li> <li> <p> <code> ClusterIdentifier</code> - The unique ID for the Amazon Redshift cluster.</p> </li> </ul> </li> <li> <p>DatabaseCredentials - The AWS Identity and Access Management (IAM) credentials that are used to connect to the Amazon Redshift database.</p> </li> <li> <p>SelectSqlQuery - The query that is used to retrieve the observation data for the <code>Datasource</code>.</p> </li> <li> <p>S3StagingLocation - The Amazon Simple Storage Service (Amazon S3) location for staging Amazon Redshift data. The data retrieved from Amazon Redshift using the <code>SelectSqlQuery</code> query is stored in this location.</p> </li> <li> <p>DataSchemaUri - The Amazon S3 location of the <code>DataSchema</code>.</p> </li> <li> <p>DataSchema - A JSON string representing the schema. This is not required if <code>DataSchemaUri</code> is specified. </p> </li> <li> <p>DataRearrangement - A JSON string that represents the splitting and rearrangement requirements for the <code>DataSource</code>.</p> <p> Sample - <code> "{\"splitting\":{\"percentBegin\":10,\"percentEnd\":60}}"</code> </p> </li> </ul>
        role_arn: <p>A fully specified role Amazon Resource Name (ARN). Amazon ML assumes the role on behalf of the user to create the following:</p> <ul> <li> <p>A security group to allow Amazon ML to execute the <code>SelectSqlQuery</code> query on an Amazon Redshift cluster</p> </li> <li> <p>An Amazon S3 bucket policy to grant Amazon ML read/write permissions on the <code>S3StagingLocation</code> </p> </li> </ul>
        compute_statistics: <p>The compute statistics for a <code>DataSource</code>. The statistics are generated from the observation data referenced by a <code>DataSource</code>. Amazon ML uses the statistics internally during <code>MLModel</code> training. This parameter must be set to <code>true</code> if the <code>DataSource</code> needs to be used for <code>MLModel</code> training.</p>

    Raises:
        capo_machine_learning.errors.idempotent_parameter_mismatch_exception.IdempotentParameterMismatchException: <p>A second request to use or change an object was not allowed. This can result from retrying a request using a parameter that was not present in the original request.</p>
        capo_machine_learning.errors.internal_server_exception.InternalServerException: <p>An error on the server occurred when trying to process a request.</p>
        capo_machine_learning.errors.invalid_input_exception.InvalidInputException: <p>An error on the client occurred. Typically, the cause is an invalid input value.</p>
        capo_machine_learning.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_machine_learning.types.create_data_source_from_redshift_input.CreateDataSourceFromRedshiftInput]",
    ) -> AsyncOperationResponse[
        "capo_machine_learning.types.create_data_source_from_redshift_output.CreateDataSourceFromRedshiftOutput"
    ]:
        import capo_machine_learning._operations.amazon_ml_20141212.create_data_source_from_redshift

        (
            output,
            http_response,
        ) = await capo_machine_learning._operations.amazon_ml_20141212.create_data_source_from_redshift.async_create_data_source_from_redshift(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_machine_learning.types.create_data_source_from_redshift_input.CreateDataSourceFromRedshiftInput",
    ) -> dict[str, Any]:
        import capo_machine_learning.types.create_data_source_from_redshift_input

        return capo_machine_learning.types.create_data_source_from_redshift_input.redact_sensitive(
            input_
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "CreateDataSourceFromRedshift", redact_input=_redact_input
        ),
    )
    input_: capo_machine_learning.types.create_data_source_from_redshift_input.CreateDataSourceFromRedshiftInput = {
        "data_source_id": data_source_id,
        "data_spec": data_spec,
        "role_arn": role_arn,
    }
    if data_source_name is not None:
        input_["data_source_name"] = data_source_name
    if compute_statistics is not None:
        input_["compute_statistics"] = compute_statistics

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output