Skip to content

create_table async

create_table(
    keyspace_name: KeyspaceName,
    table_name: TableName,
    schema_definition: SchemaDefinition,
    *,
    config_overrides: Optional[AsyncKeyspacesClientConfig] = None,
    comment: Optional[Comment] = None,
    capacity_specification: Optional[CapacitySpecification] = None,
    encryption_specification: Optional[EncryptionSpecification] = None,
    point_in_time_recovery: Optional[PointInTimeRecovery] = None,
    ttl: Optional[TimeToLive] = None,
    default_time_to_live: Optional[DefaultTimeToLive] = None,
    tags: Optional[TagList] = None,
    client_side_timestamps: Optional[ClientSideTimestamps] = None,
    auto_scaling_specification: Optional[AutoScalingSpecification] = None,
    replica_specifications: Optional[ReplicaSpecificationList] = None,
    cdc_specification: Optional[CdcSpecification] = None,
    warm_throughput_specification: Optional[WarmThroughputSpecification] = None,
) -> CreateTableResponse

The CreateTable operation adds a new table to the specified keyspace. Within a keyspace, table names must be unique.

CreateTable is an asynchronous operation. When the request is received, the status of the table is set to CREATING. You can monitor the creation status of the new table by using the GetTable operation, which returns the current status of the table. You can start using a table when the status is ACTIVE.

For more information, see Create a table in the Amazon Keyspaces Developer Guide.

Parameters:

  • keyspace_name (KeyspaceName) –

    The name of the keyspace that the table is going to be created in.

  • table_name (TableName) –

    The name of the table.

  • schema_definition (SchemaDefinition) –

    The schemaDefinition consists of the following parameters.

    For each column to be created:

    • name - The name of the column.

    • type - An Amazon Keyspaces data type. For more information, see Data types in the Amazon Keyspaces Developer Guide.

    The primary key of the table consists of the following columns:

    • partitionKeys - The partition key can be a single column, or it can be a compound value composed of two or more columns. The partition key portion of the primary key is required and determines how Amazon Keyspaces stores your data.

    • name - The name of each partition key column.

    • clusteringKeys - The optional clustering column portion of your primary key determines how the data is clustered and sorted within each partition.

    • name - The name of the clustering column.

    • orderBy - Sets the ascendant (ASC) or descendant (DESC) order modifier.

      To define a column as static use staticColumns - Static columns store values that are shared by all rows in the same partition:

    • name - The name of the column.

    • type - An Amazon Keyspaces data type.

  • comment (Optional[Comment], default: None ) –

    This parameter allows to enter a description of the table.

  • capacity_specification (Optional[CapacitySpecification], default: None ) –

    Specifies the read/write throughput capacity mode for the table. The options are:

    • throughputMode:PAY_PER_REQUEST and

    • throughputMode:PROVISIONED - Provisioned capacity mode requires readCapacityUnits and writeCapacityUnits as input.

    The default is throughput_mode:PAY_PER_REQUEST.

    For more information, see Read/write capacity modes in the Amazon Keyspaces Developer Guide.

  • encryption_specification (Optional[EncryptionSpecification], default: None ) –

    Specifies how the encryption key for encryption at rest is managed for the table. You can choose one of the following KMS key (KMS key):

    • type:AWS_OWNED_KMS_KEY - This key is owned by Amazon Keyspaces.

    • type:CUSTOMER_MANAGED_KMS_KEY - This key is stored in your account and is created, owned, and managed by you. This option requires the kms_key_identifier of the KMS key in Amazon Resource Name (ARN) format as input.

    The default is type:AWS_OWNED_KMS_KEY.

    For more information, see Encryption at rest in the Amazon Keyspaces Developer Guide.

  • point_in_time_recovery (Optional[PointInTimeRecovery], default: None ) –

    Specifies if pointInTimeRecovery is enabled or disabled for the table. The options are:

    • status=ENABLED

    • status=DISABLED

    If it's not specified, the default is status=DISABLED.

    For more information, see Point-in-time recovery in the Amazon Keyspaces Developer Guide.

  • ttl (Optional[TimeToLive], default: None ) –

    Enables Time to Live custom settings for the table. The options are:

    • status:enabled

    • status:disabled

    The default is status:disabled. After ttl is enabled, you can't disable it for the table.

    For more information, see Expiring data by using Amazon Keyspaces Time to Live (TTL) in the Amazon Keyspaces Developer Guide.

  • default_time_to_live (Optional[DefaultTimeToLive], default: None ) –

    The default Time to Live setting in seconds for the table.

    For more information, see Setting the default TTL value for a table in the Amazon Keyspaces Developer Guide.

  • tags (Optional[TagList], default: None ) –

    A list of key-value pair tags to be attached to the resource.

    For more information, see Adding tags and labels to Amazon Keyspaces resources in the Amazon Keyspaces Developer Guide.

  • client_side_timestamps (Optional[ClientSideTimestamps], default: None ) –

    Enables client-side timestamps for the table. By default, the setting is disabled. You can enable client-side timestamps with the following option:

    • status: "enabled"

    Once client-side timestamps are enabled for a table, this setting cannot be disabled.

  • auto_scaling_specification (Optional[AutoScalingSpecification], default: None ) –

    The optional auto scaling settings for a table in provisioned capacity mode. Specifies if the service can manage throughput capacity automatically on your behalf.

    Auto scaling helps you provision throughput capacity for variable workloads efficiently by increasing and decreasing your table's read and write capacity automatically in response to application traffic. For more information, see Managing throughput capacity automatically with Amazon Keyspaces auto scaling in the Amazon Keyspaces Developer Guide.

    By default, auto scaling is disabled for a table.

  • replica_specifications (Optional[ReplicaSpecificationList], default: None ) –

    The optional Amazon Web Services Region specific settings of a multi-Region table. These settings overwrite the general settings of the table for the specified Region.

    For a multi-Region table in provisioned capacity mode, you can configure the table's read capacity differently for each Region's replica. The write capacity, however, remains synchronized between all replicas to ensure that there's enough capacity to replicate writes across all Regions. To define the read capacity for a table replica in a specific Region, you can do so by configuring the following parameters.

    • region: The Region where these settings are applied. (Required)

    • readCapacityUnits: The provisioned read capacity units. (Optional)

    • readCapacityAutoScaling: The read capacity auto scaling settings for the table. (Optional)

  • cdc_specification (Optional[CdcSpecification], default: None ) –

    The CDC stream settings of the table.

  • warm_throughput_specification (Optional[WarmThroughputSpecification], default: None ) –

    Specifies the warm throughput settings for the table. Pre-warming a table helps you avoid capacity exceeded exceptions by pre-provisioning read and write capacity units to reduce cold start latency when your table receives traffic.

    For more information about pre-warming in Amazon Keyspaces, see Pre-warm a table in Amazon Keyspaces in the Amazon Keyspaces Developer Guide.

Raises:

  • AccessDeniedException –

    You don't have sufficient access permissions to perform this action.

  • ConflictException –

    Amazon Keyspaces couldn't complete the requested action. This error may occur if you try to perform an action and the same or a different action is already in progress, or if you try to create a resource that already exists.

  • InternalServerException –

    Amazon Keyspaces was unable to fully process this request because of an internal server error.

  • ResourceNotFoundException –

    The operation tried to access a keyspace, table, or type that doesn't exist. The resource might not be specified correctly, or its status might not be ACTIVE.

  • ServiceQuotaExceededException –

    The operation exceeded the service quota for this resource. For more information on service quotas, see Quotas in the Amazon Keyspaces Developer Guide.

  • ValidationException –

    The operation failed due to an invalid or malformed request.

  • UnknownServiceError –

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

Source code in docs_src/capo_keyspaces/_services/async_keyspaces.py
async def create_table(
    self,
    keyspace_name: "capo_keyspaces.types.keyspace_name.KeyspaceName",
    table_name: "capo_keyspaces.types.table_name.TableName",
    schema_definition: "capo_keyspaces.types.schema_definition.SchemaDefinition",
    *,
    config_overrides: Optional[AsyncKeyspacesClientConfig] = None,
    comment: Optional["capo_keyspaces.types.comment.Comment"] = None,
    capacity_specification: Optional[
        "capo_keyspaces.types.capacity_specification.CapacitySpecification"
    ] = None,
    encryption_specification: Optional[
        "capo_keyspaces.types.encryption_specification.EncryptionSpecification"
    ] = None,
    point_in_time_recovery: Optional[
        "capo_keyspaces.types.point_in_time_recovery.PointInTimeRecovery"
    ] = None,
    ttl: Optional["capo_keyspaces.types.time_to_live.TimeToLive"] = None,
    default_time_to_live: Optional[
        "capo_keyspaces.types.default_time_to_live.DefaultTimeToLive"
    ] = None,
    tags: Optional["capo_keyspaces.types.tag_list.TagList"] = None,
    client_side_timestamps: Optional[
        "capo_keyspaces.types.client_side_timestamps.ClientSideTimestamps"
    ] = None,
    auto_scaling_specification: Optional[
        "capo_keyspaces.types.auto_scaling_specification.AutoScalingSpecification"
    ] = None,
    replica_specifications: Optional[
        "capo_keyspaces.types.replica_specification_list.ReplicaSpecificationList"
    ] = None,
    cdc_specification: Optional[
        "capo_keyspaces.types.cdc_specification.CdcSpecification"
    ] = None,
    warm_throughput_specification: Optional[
        "capo_keyspaces.types.warm_throughput_specification.WarmThroughputSpecification"
    ] = None,
) -> "capo_keyspaces.types.create_table_response.CreateTableResponse":
    """<p>The <code>CreateTable</code> operation adds a new table to the specified keyspace. Within a keyspace, table names must be unique.</p> <p> <code>CreateTable</code> is an asynchronous operation. When the request is received, the status of the table is set to <code>CREATING</code>. You can monitor the creation status of the new table by using the <code>GetTable</code> operation, which returns the current <code>status</code> of the table. You can start using a table when the status is <code>ACTIVE</code>.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/keyspaces/latest/devguide/getting-started.tables.html">Create a table</a> in the <i>Amazon Keyspaces Developer Guide</i>.</p>

    Args:
        keyspace_name: <p>The name of the keyspace that the table is going to be created in.</p>
        table_name: <p>The name of the table.</p>
        schema_definition: <p>The <code>schemaDefinition</code> consists of the following parameters.</p> <p>For each column to be created:</p> <ul> <li> <p> <code>name</code> - The name of the column.</p> </li> <li> <p> <code>type</code> - An Amazon Keyspaces data type. For more information, see <a href="https://docs.aws.amazon.com/keyspaces/latest/devguide/cql.elements.html#cql.data-types">Data types</a> in the <i>Amazon Keyspaces Developer Guide</i>.</p> </li> </ul> <p>The primary key of the table consists of the following columns:</p> <ul> <li> <p> <code>partitionKeys</code> - The partition key can be a single column, or it can be a compound value composed of two or more columns. The partition key portion of the primary key is required and determines how Amazon Keyspaces stores your data.</p> </li> <li> <p> <code>name</code> - The name of each partition key column.</p> </li> <li> <p> <code>clusteringKeys</code> - The optional clustering column portion of your primary key determines how the data is clustered and sorted within each partition.</p> </li> <li> <p> <code>name</code> - The name of the clustering column. </p> </li> <li> <p> <code>orderBy</code> - Sets the ascendant (<code>ASC</code>) or descendant (<code>DESC</code>) order modifier.</p> <p>To define a column as static use <code>staticColumns</code> - Static columns store values that are shared by all rows in the same partition:</p> </li> <li> <p> <code>name</code> - The name of the column.</p> </li> <li> <p> <code>type</code> - An Amazon Keyspaces data type.</p> </li> </ul>
        comment: <p>This parameter allows to enter a description of the table.</p>
        capacity_specification: <p>Specifies the read/write throughput capacity mode for the table. The options are:</p> <ul> <li> <p> <code>throughputMode:PAY_PER_REQUEST</code> and </p> </li> <li> <p> <code>throughputMode:PROVISIONED</code> - Provisioned capacity mode requires <code>readCapacityUnits</code> and <code>writeCapacityUnits</code> as input.</p> </li> </ul> <p>The default is <code>throughput_mode:PAY_PER_REQUEST</code>.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/keyspaces/latest/devguide/ReadWriteCapacityMode.html">Read/write capacity modes</a> in the <i>Amazon Keyspaces Developer Guide</i>.</p>
        encryption_specification: <p>Specifies how the encryption key for encryption at rest is managed for the table. You can choose one of the following KMS key (KMS key):</p> <ul> <li> <p> <code>type:AWS_OWNED_KMS_KEY</code> - This key is owned by Amazon Keyspaces. </p> </li> <li> <p> <code>type:CUSTOMER_MANAGED_KMS_KEY</code> - This key is stored in your account and is created, owned, and managed by you. This option requires the <code>kms_key_identifier</code> of the KMS key in Amazon Resource Name (ARN) format as input.</p> </li> </ul> <p>The default is <code>type:AWS_OWNED_KMS_KEY</code>.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/keyspaces/latest/devguide/EncryptionAtRest.html">Encryption at rest</a> in the <i>Amazon Keyspaces Developer Guide</i>.</p>
        point_in_time_recovery: <p>Specifies if <code>pointInTimeRecovery</code> is enabled or disabled for the table. The options are:</p> <ul> <li> <p> <code>status=ENABLED</code> </p> </li> <li> <p> <code>status=DISABLED</code> </p> </li> </ul> <p>If it's not specified, the default is <code>status=DISABLED</code>.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/keyspaces/latest/devguide/PointInTimeRecovery.html">Point-in-time recovery</a> in the <i>Amazon Keyspaces Developer Guide</i>.</p>
        ttl: <p>Enables Time to Live custom settings for the table. The options are:</p> <ul> <li> <p> <code>status:enabled</code> </p> </li> <li> <p> <code>status:disabled</code> </p> </li> </ul> <p>The default is <code>status:disabled</code>. After <code>ttl</code> is enabled, you can't disable it for the table.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/keyspaces/latest/devguide/TTL.html">Expiring data by using Amazon Keyspaces Time to Live (TTL)</a> in the <i>Amazon Keyspaces Developer Guide</i>.</p>
        default_time_to_live: <p>The default Time to Live setting in seconds for the table.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/keyspaces/latest/devguide/TTL-how-it-works.html#ttl-howitworks_default_ttl">Setting the default TTL value for a table</a> in the <i>Amazon Keyspaces Developer Guide</i>.</p>
        tags: <p>A list of key-value pair tags to be attached to the resource. </p> <p>For more information, see <a href="https://docs.aws.amazon.com/keyspaces/latest/devguide/tagging-keyspaces.html">Adding tags and labels to Amazon Keyspaces resources</a> in the <i>Amazon Keyspaces Developer Guide</i>.</p>
        client_side_timestamps: <p> Enables client-side timestamps for the table. By default, the setting is disabled. You can enable client-side timestamps with the following option:</p> <ul> <li> <p> <code>status: "enabled"</code> </p> </li> </ul> <p>Once client-side timestamps are enabled for a table, this setting cannot be disabled.</p>
        auto_scaling_specification: <p>The optional auto scaling settings for a table in provisioned capacity mode. Specifies if the service can manage throughput capacity automatically on your behalf.</p> <p>Auto scaling helps you provision throughput capacity for variable workloads efficiently by increasing and decreasing your table's read and write capacity automatically in response to application traffic. For more information, see <a href="https://docs.aws.amazon.com/keyspaces/latest/devguide/autoscaling.html">Managing throughput capacity automatically with Amazon Keyspaces auto scaling</a> in the <i>Amazon Keyspaces Developer Guide</i>.</p> <p>By default, auto scaling is disabled for a table. </p>
        replica_specifications: <p>The optional Amazon Web Services Region specific settings of a multi-Region table. These settings overwrite the general settings of the table for the specified Region. </p> <p>For a multi-Region table in provisioned capacity mode, you can configure the table's read capacity differently for each Region's replica. The write capacity, however, remains synchronized between all replicas to ensure that there's enough capacity to replicate writes across all Regions. To define the read capacity for a table replica in a specific Region, you can do so by configuring the following parameters.</p> <ul> <li> <p> <code>region</code>: The Region where these settings are applied. (Required)</p> </li> <li> <p> <code>readCapacityUnits</code>: The provisioned read capacity units. (Optional)</p> </li> <li> <p> <code>readCapacityAutoScaling</code>: The read capacity auto scaling settings for the table. (Optional) </p> </li> </ul>
        cdc_specification: <p>The CDC stream settings of the table.</p>
        warm_throughput_specification: <p>Specifies the warm throughput settings for the table. Pre-warming a table helps you avoid capacity exceeded exceptions by pre-provisioning read and write capacity units to reduce cold start latency when your table receives traffic.</p> <p>For more information about pre-warming in Amazon Keyspaces, see <a href="https://docs.aws.amazon.com/keyspaces/latest/devguide/warm-throughput.html">Pre-warm a table in Amazon Keyspaces</a> in the <i>Amazon Keyspaces Developer Guide</i>.</p>

    Raises:
        capo_keyspaces.errors.access_denied_exception.AccessDeniedException: <p>You don't have sufficient access permissions to perform this action. </p>
        capo_keyspaces.errors.conflict_exception.ConflictException: <p>Amazon Keyspaces couldn't complete the requested action. This error may occur if you try to perform an action and the same or a different action is already in progress, or if you try to create a resource that already exists. </p>
        capo_keyspaces.errors.internal_server_exception.InternalServerException: <p>Amazon Keyspaces was unable to fully process this request because of an internal server error.</p>
        capo_keyspaces.errors.resource_not_found_exception.ResourceNotFoundException: <p>The operation tried to access a keyspace, table, or type that doesn't exist. The resource might not be specified correctly, or its status might not be <code>ACTIVE</code>.</p>
        capo_keyspaces.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>The operation exceeded the service quota for this resource. For more information on service quotas, see <a href="https://docs.aws.amazon.com/keyspaces/latest/devguide/quotas.html">Quotas</a> in the <i>Amazon Keyspaces Developer Guide</i>.</p>
        capo_keyspaces.errors.validation_exception.ValidationException: <p>The operation failed due to an invalid or malformed request.</p>
        capo_keyspaces.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_keyspaces.types.create_table_request.CreateTableRequest]",
    ) -> AsyncOperationResponse[
        "capo_keyspaces.types.create_table_response.CreateTableResponse"
    ]:
        import capo_keyspaces._operations.keyspaces_service.create_table

        (
            output,
            http_response,
        ) = await capo_keyspaces._operations.keyspaces_service.create_table.async_create_table(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateTable")
    )
    input_: capo_keyspaces.types.create_table_request.CreateTableRequest = {
        "keyspace_name": keyspace_name,
        "table_name": table_name,
        "schema_definition": schema_definition,
    }
    if comment is not None:
        input_["comment"] = comment
    if capacity_specification is not None:
        input_["capacity_specification"] = capacity_specification
    if encryption_specification is not None:
        input_["encryption_specification"] = encryption_specification
    if point_in_time_recovery is not None:
        input_["point_in_time_recovery"] = point_in_time_recovery
    if ttl is not None:
        input_["ttl"] = ttl
    if default_time_to_live is not None:
        input_["default_time_to_live"] = default_time_to_live
    if tags is not None:
        input_["tags"] = tags
    if client_side_timestamps is not None:
        input_["client_side_timestamps"] = client_side_timestamps
    if auto_scaling_specification is not None:
        input_["auto_scaling_specification"] = auto_scaling_specification
    if replica_specifications is not None:
        input_["replica_specifications"] = replica_specifications
    if cdc_specification is not None:
        input_["cdc_specification"] = cdc_specification
    if warm_throughput_specification is not None:
        input_["warm_throughput_specification"] = warm_throughput_specification

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