Table

class aws_cdk.aws_dynamodb.Table(scope, id, *, table_name=None, partition_key, billing_mode=None, encryption=None, encryption_key=None, point_in_time_recovery=None, read_capacity=None, removal_policy=None, replication_regions=None, server_side_encryption=None, sort_key=None, stream=None, time_to_live_attribute=None, write_capacity=None)

Bases: aws_cdk.core.Resource

Provides a DynamoDB table.

__init__(scope, id, *, table_name=None, partition_key, billing_mode=None, encryption=None, encryption_key=None, point_in_time_recovery=None, read_capacity=None, removal_policy=None, replication_regions=None, server_side_encryption=None, sort_key=None, stream=None, time_to_live_attribute=None, write_capacity=None)
Parameters
  • scope (Construct) –

  • id (str) –

  • table_name (Optional[str]) – Enforces a particular physical table name. Default:

  • partition_key (Attribute) – Partition key attribute definition.

  • billing_mode (Optional[BillingMode]) – Specify how you are charged for read and write throughput and how you manage capacity. Default: PROVISIONED if replicationRegions is not specified, PAY_PER_REQUEST otherwise

  • encryption (Optional[TableEncryption]) – Whether server-side encryption with an AWS managed customer master key is enabled. This property cannot be set if serverSideEncryption is set. Default: - server-side encryption is enabled with an AWS owned customer master key

  • encryption_key (Optional[IKey]) – External KMS key to use for table encryption. This property can only be set if encryption is set to TableEncryption.CUSTOMER_MANAGED. Default: - If encryption is set to TableEncryption.CUSTOMER_MANAGED and this property is undefined, a new KMS key will be created and associated with this table.

  • point_in_time_recovery (Optional[bool]) – Whether point-in-time recovery is enabled. Default: - point-in-time recovery is disabled

  • read_capacity (Union[int, float, None]) – The read capacity for the table. Careful if you add Global Secondary Indexes, as those will share the table’s provisioned throughput. Can only be provided if billingMode is Provisioned. Default: 5

  • removal_policy (Optional[RemovalPolicy]) – The removal policy to apply to the DynamoDB Table. Default: RemovalPolicy.RETAIN

  • replication_regions (Optional[List[str]]) – Regions where replica tables will be created. Default: - no replica tables are created

  • server_side_encryption (Optional[bool]) – Whether server-side encryption with an AWS managed customer master key is enabled. This property cannot be set if encryption and/or encryptionKey is set. Default: - server-side encryption is enabled with an AWS owned customer master key

  • sort_key (Optional[Attribute]) – Table sort key attribute definition. Default: no sort key

  • stream (Optional[StreamViewType]) – When an item in the table is modified, StreamViewType determines what information is written to the stream for this table. Default: - streams are disabled unless replicationRegions is specified

  • time_to_live_attribute (Optional[str]) – The name of TTL attribute. Default: - TTL is disabled

  • write_capacity (Union[int, float, None]) – The write capacity for the table. Careful if you add Global Secondary Indexes, as those will share the table’s provisioned throughput. Can only be provided if billingMode is Provisioned. Default: 5

Return type

None

Methods

add_global_secondary_index(*, partition_key, read_capacity=None, sort_key=None, write_capacity=None, index_name, non_key_attributes=None, projection_type=None)

Add a global secondary index of table.

Parameters
  • partition_key (Attribute) – The attribute of a partition key for the global secondary index.

  • read_capacity (Union[int, float, None]) – The read capacity for the global secondary index. Can only be provided if table billingMode is Provisioned or undefined. Default: 5

  • sort_key (Optional[Attribute]) – The attribute of a sort key for the global secondary index. Default: - No sort key

  • write_capacity (Union[int, float, None]) – The write capacity for the global secondary index. Can only be provided if table billingMode is Provisioned or undefined. Default: 5

  • index_name (str) – The name of the secondary index.

  • non_key_attributes (Optional[List[str]]) – The non-key attributes that are projected into the secondary index. Default: - No additional attributes

  • projection_type (Optional[ProjectionType]) – The set of attributes that are projected into the secondary index. Default: ALL

Return type

None

add_local_secondary_index(*, sort_key, index_name, non_key_attributes=None, projection_type=None)

Add a local secondary index of table.

Parameters
  • sort_key (Attribute) – The attribute of a sort key for the local secondary index.

  • index_name (str) – The name of the secondary index.

  • non_key_attributes (Optional[List[str]]) – The non-key attributes that are projected into the secondary index. Default: - No additional attributes

  • projection_type (Optional[ProjectionType]) – The set of attributes that are projected into the secondary index. Default: ALL

Return type

None

auto_scale_global_secondary_index_read_capacity(index_name, *, max_capacity, min_capacity)

Enable read capacity scaling for the given GSI.

Parameters
  • index_name (str) –

  • max_capacity (Union[int, float]) – Maximum capacity to scale to.

  • min_capacity (Union[int, float]) – Minimum capacity to scale to.

return :rtype: IScalableTableAttribute :return: An object to configure additional AutoScaling settings for this attribute

auto_scale_global_secondary_index_write_capacity(index_name, *, max_capacity, min_capacity)

Enable write capacity scaling for the given GSI.

Parameters
  • index_name (str) –

  • max_capacity (Union[int, float]) – Maximum capacity to scale to.

  • min_capacity (Union[int, float]) – Minimum capacity to scale to.

return :rtype: IScalableTableAttribute :return: An object to configure additional AutoScaling settings for this attribute

auto_scale_read_capacity(*, max_capacity, min_capacity)

Enable read capacity scaling for this table.

Parameters
  • max_capacity (Union[int, float]) – Maximum capacity to scale to.

  • min_capacity (Union[int, float]) – Minimum capacity to scale to.

return :rtype: IScalableTableAttribute :return: An object to configure additional AutoScaling settings

auto_scale_write_capacity(*, max_capacity, min_capacity)

Enable write capacity scaling for this table.

Parameters
  • max_capacity (Union[int, float]) – Maximum capacity to scale to.

  • min_capacity (Union[int, float]) – Minimum capacity to scale to.

return :rtype: IScalableTableAttribute :return: An object to configure additional AutoScaling settings for this attribute

grant(grantee, *actions)

Adds an IAM policy statement associated with this table to an IAM principal’s policy.

If encryptionKey is present, appropriate grants to the key needs to be added separately using the table.encryptionKey.grant* methods.

Parameters
  • grantee (IGrantable) – The principal (no-op if undefined).

  • actions (str) – The set of actions to allow (i.e. “dynamodb:PutItem”, “dynamodb:GetItem”, …).

Return type

Grant

grant_full_access(grantee)

Permits all DynamoDB operations (“dynamodb:*”) to an IAM principal.

Appropriate grants will also be added to the customer-managed KMS key if one was configured.

Parameters

grantee (IGrantable) – The principal to grant access to.

Return type

Grant

grant_read_data(grantee)

Permits an IAM principal all data read operations from this table: BatchGetItem, GetRecords, GetShardIterator, Query, GetItem, Scan.

Appropriate grants will also be added to the customer-managed KMS key if one was configured.

Parameters

grantee (IGrantable) – The principal to grant access to.

Return type

Grant

grant_read_write_data(grantee)

Permits an IAM principal to all data read/write operations to this table.

BatchGetItem, GetRecords, GetShardIterator, Query, GetItem, Scan, BatchWriteItem, PutItem, UpdateItem, DeleteItem

Appropriate grants will also be added to the customer-managed KMS key if one was configured.

Parameters

grantee (IGrantable) – The principal to grant access to.

Return type

Grant

grant_stream(grantee, *actions)

Adds an IAM policy statement associated with this table’s stream to an IAM principal’s policy.

If encryptionKey is present, appropriate grants to the key needs to be added separately using the table.encryptionKey.grant* methods.

Parameters
  • grantee (IGrantable) – The principal (no-op if undefined).

  • actions (str) – The set of actions to allow (i.e. “dynamodb:DescribeStream”, “dynamodb:GetRecords”, …).

Return type

Grant

grant_stream_read(grantee)

Permits an IAM principal all stream data read operations for this table’s stream: DescribeStream, GetRecords, GetShardIterator, ListStreams.

Appropriate grants will also be added to the customer-managed KMS key if one was configured.

Parameters

grantee (IGrantable) – The principal to grant access to.

Return type

Grant

grant_table_list_streams(grantee)

Permits an IAM Principal to list streams attached to current dynamodb table.

Parameters

grantee (IGrantable) – The principal (no-op if undefined).

Return type

Grant

grant_write_data(grantee)

Permits an IAM principal all data write operations to this table: BatchWriteItem, PutItem, UpdateItem, DeleteItem.

Appropriate grants will also be added to the customer-managed KMS key if one was configured.

Parameters

grantee (IGrantable) – The principal to grant access to.

Return type

Grant

metric(metric_name, *, account=None, color=None, dimensions=None, label=None, period=None, region=None, statistic=None, unit=None)

Return the given named metric for this Table.

Parameters
  • metric_name (str) –

  • account (Optional[str]) – Account which this metric comes from. Default: - Deployment account.

  • color (Optional[str]) – The hex color code, prefixed with ‘#’ (e.g. ‘#00ff00’), to use when this metric is rendered on a graph. The Color class has a set of standard colors that can be used here. Default: - Automatic color

  • dimensions (Optional[Mapping[str, Any]]) – Dimensions of the metric. Default: - No dimensions.

  • label (Optional[str]) – Label for this metric when added to a Graph in a Dashboard. Default: - No label

  • period (Optional[Duration]) – The period over which the specified statistic is applied. Default: Duration.minutes(5)

  • region (Optional[str]) – Region which this metric comes from. Default: - Deployment region.

  • statistic (Optional[str]) – What function to use for aggregating. Can be one of the following: - “Minimum” | “min” - “Maximum” | “max” - “Average” | “avg” - “Sum” | “sum” - “SampleCount | “n” - “pNN.NN” Default: Average

  • unit (Optional[Unit]) – Unit used to filter the metric stream. Only refer to datums emitted to the metric stream with the given unit and ignore all others. Only useful when datums are being emitted to the same metric stream under different units. The default is to use all matric datums in the stream, regardless of unit, which is recommended in nearly all cases. CloudWatch does not honor this property for graphs. Default: - All metric datums in the given metric stream

Return type

Metric

metric_conditional_check_failed_requests(*, account=None, color=None, dimensions=None, label=None, period=None, region=None, statistic=None, unit=None)

Metric for the conditional check failed requests this table.

Parameters
  • account (Optional[str]) – Account which this metric comes from. Default: - Deployment account.

  • color (Optional[str]) – The hex color code, prefixed with ‘#’ (e.g. ‘#00ff00’), to use when this metric is rendered on a graph. The Color class has a set of standard colors that can be used here. Default: - Automatic color

  • dimensions (Optional[Mapping[str, Any]]) – Dimensions of the metric. Default: - No dimensions.

  • label (Optional[str]) – Label for this metric when added to a Graph in a Dashboard. Default: - No label

  • period (Optional[Duration]) – The period over which the specified statistic is applied. Default: Duration.minutes(5)

  • region (Optional[str]) – Region which this metric comes from. Default: - Deployment region.

  • statistic (Optional[str]) – What function to use for aggregating. Can be one of the following: - “Minimum” | “min” - “Maximum” | “max” - “Average” | “avg” - “Sum” | “sum” - “SampleCount | “n” - “pNN.NN” Default: Average

  • unit (Optional[Unit]) – Unit used to filter the metric stream. Only refer to datums emitted to the metric stream with the given unit and ignore all others. Only useful when datums are being emitted to the same metric stream under different units. The default is to use all matric datums in the stream, regardless of unit, which is recommended in nearly all cases. CloudWatch does not honor this property for graphs. Default: - All metric datums in the given metric stream

default :default: sum over a minute

Return type

Metric

metric_consumed_read_capacity_units(*, account=None, color=None, dimensions=None, label=None, period=None, region=None, statistic=None, unit=None)

Metric for the consumed read capacity units this table.

Parameters
  • account (Optional[str]) – Account which this metric comes from. Default: - Deployment account.

  • color (Optional[str]) – The hex color code, prefixed with ‘#’ (e.g. ‘#00ff00’), to use when this metric is rendered on a graph. The Color class has a set of standard colors that can be used here. Default: - Automatic color

  • dimensions (Optional[Mapping[str, Any]]) – Dimensions of the metric. Default: - No dimensions.

  • label (Optional[str]) – Label for this metric when added to a Graph in a Dashboard. Default: - No label

  • period (Optional[Duration]) – The period over which the specified statistic is applied. Default: Duration.minutes(5)

  • region (Optional[str]) – Region which this metric comes from. Default: - Deployment region.

  • statistic (Optional[str]) – What function to use for aggregating. Can be one of the following: - “Minimum” | “min” - “Maximum” | “max” - “Average” | “avg” - “Sum” | “sum” - “SampleCount | “n” - “pNN.NN” Default: Average

  • unit (Optional[Unit]) – Unit used to filter the metric stream. Only refer to datums emitted to the metric stream with the given unit and ignore all others. Only useful when datums are being emitted to the same metric stream under different units. The default is to use all matric datums in the stream, regardless of unit, which is recommended in nearly all cases. CloudWatch does not honor this property for graphs. Default: - All metric datums in the given metric stream

default :default: sum over a minute

Return type

Metric

metric_consumed_write_capacity_units(*, account=None, color=None, dimensions=None, label=None, period=None, region=None, statistic=None, unit=None)

Metric for the consumed write capacity units this table.

Parameters
  • account (Optional[str]) – Account which this metric comes from. Default: - Deployment account.

  • color (Optional[str]) – The hex color code, prefixed with ‘#’ (e.g. ‘#00ff00’), to use when this metric is rendered on a graph. The Color class has a set of standard colors that can be used here. Default: - Automatic color

  • dimensions (Optional[Mapping[str, Any]]) – Dimensions of the metric. Default: - No dimensions.

  • label (Optional[str]) – Label for this metric when added to a Graph in a Dashboard. Default: - No label

  • period (Optional[Duration]) – The period over which the specified statistic is applied. Default: Duration.minutes(5)

  • region (Optional[str]) – Region which this metric comes from. Default: - Deployment region.

  • statistic (Optional[str]) – What function to use for aggregating. Can be one of the following: - “Minimum” | “min” - “Maximum” | “max” - “Average” | “avg” - “Sum” | “sum” - “SampleCount | “n” - “pNN.NN” Default: Average

  • unit (Optional[Unit]) – Unit used to filter the metric stream. Only refer to datums emitted to the metric stream with the given unit and ignore all others. Only useful when datums are being emitted to the same metric stream under different units. The default is to use all matric datums in the stream, regardless of unit, which is recommended in nearly all cases. CloudWatch does not honor this property for graphs. Default: - All metric datums in the given metric stream

default :default: sum over a minute

Return type

Metric

metric_successful_request_latency(*, account=None, color=None, dimensions=None, label=None, period=None, region=None, statistic=None, unit=None)

Metric for the successful request latency this table.

Parameters
  • account (Optional[str]) – Account which this metric comes from. Default: - Deployment account.

  • color (Optional[str]) – The hex color code, prefixed with ‘#’ (e.g. ‘#00ff00’), to use when this metric is rendered on a graph. The Color class has a set of standard colors that can be used here. Default: - Automatic color

  • dimensions (Optional[Mapping[str, Any]]) – Dimensions of the metric. Default: - No dimensions.

  • label (Optional[str]) – Label for this metric when added to a Graph in a Dashboard. Default: - No label

  • period (Optional[Duration]) – The period over which the specified statistic is applied. Default: Duration.minutes(5)

  • region (Optional[str]) – Region which this metric comes from. Default: - Deployment region.

  • statistic (Optional[str]) – What function to use for aggregating. Can be one of the following: - “Minimum” | “min” - “Maximum” | “max” - “Average” | “avg” - “Sum” | “sum” - “SampleCount | “n” - “pNN.NN” Default: Average

  • unit (Optional[Unit]) – Unit used to filter the metric stream. Only refer to datums emitted to the metric stream with the given unit and ignore all others. Only useful when datums are being emitted to the same metric stream under different units. The default is to use all matric datums in the stream, regardless of unit, which is recommended in nearly all cases. CloudWatch does not honor this property for graphs. Default: - All metric datums in the given metric stream

default :default: avg over a minute

Return type

Metric

metric_system_errors(*, account=None, color=None, dimensions=None, label=None, period=None, region=None, statistic=None, unit=None)

Metric for the system errors this table.

Parameters
  • account (Optional[str]) – Account which this metric comes from. Default: - Deployment account.

  • color (Optional[str]) – The hex color code, prefixed with ‘#’ (e.g. ‘#00ff00’), to use when this metric is rendered on a graph. The Color class has a set of standard colors that can be used here. Default: - Automatic color

  • dimensions (Optional[Mapping[str, Any]]) – Dimensions of the metric. Default: - No dimensions.

  • label (Optional[str]) – Label for this metric when added to a Graph in a Dashboard. Default: - No label

  • period (Optional[Duration]) – The period over which the specified statistic is applied. Default: Duration.minutes(5)

  • region (Optional[str]) – Region which this metric comes from. Default: - Deployment region.

  • statistic (Optional[str]) – What function to use for aggregating. Can be one of the following: - “Minimum” | “min” - “Maximum” | “max” - “Average” | “avg” - “Sum” | “sum” - “SampleCount | “n” - “pNN.NN” Default: Average

  • unit (Optional[Unit]) – Unit used to filter the metric stream. Only refer to datums emitted to the metric stream with the given unit and ignore all others. Only useful when datums are being emitted to the same metric stream under different units. The default is to use all matric datums in the stream, regardless of unit, which is recommended in nearly all cases. CloudWatch does not honor this property for graphs. Default: - All metric datums in the given metric stream

default :default: sum over a minute

Return type

Metric

metric_user_errors(*, account=None, color=None, dimensions=None, label=None, period=None, region=None, statistic=None, unit=None)

Metric for the user errors this table.

Parameters
  • account (Optional[str]) – Account which this metric comes from. Default: - Deployment account.

  • color (Optional[str]) – The hex color code, prefixed with ‘#’ (e.g. ‘#00ff00’), to use when this metric is rendered on a graph. The Color class has a set of standard colors that can be used here. Default: - Automatic color

  • dimensions (Optional[Mapping[str, Any]]) – Dimensions of the metric. Default: - No dimensions.

  • label (Optional[str]) – Label for this metric when added to a Graph in a Dashboard. Default: - No label

  • period (Optional[Duration]) – The period over which the specified statistic is applied. Default: Duration.minutes(5)

  • region (Optional[str]) – Region which this metric comes from. Default: - Deployment region.

  • statistic (Optional[str]) – What function to use for aggregating. Can be one of the following: - “Minimum” | “min” - “Maximum” | “max” - “Average” | “avg” - “Sum” | “sum” - “SampleCount | “n” - “pNN.NN” Default: Average

  • unit (Optional[Unit]) – Unit used to filter the metric stream. Only refer to datums emitted to the metric stream with the given unit and ignore all others. Only useful when datums are being emitted to the same metric stream under different units. The default is to use all matric datums in the stream, regardless of unit, which is recommended in nearly all cases. CloudWatch does not honor this property for graphs. Default: - All metric datums in the given metric stream

default :default: sum over a minute

Return type

Metric

to_string()

Returns a string representation of this construct.

Return type

str

Attributes

encryption_key

KMS encryption key, if this table uses a customer-managed encryption key.

Return type

Optional[IKey]

node

The construct tree node associated with this construct.

Return type

ConstructNode

stack

The stack in which this resource is defined.

Return type

Stack

table_arn

Arn of the dynamodb table.

attribute: :attribute:: true

Return type

str

table_name

Table name of the dynamodb table.

attribute: :attribute:: true

Return type

str

table_stream_arn

ARN of the table’s stream, if there is one.

attribute: :attribute:: true

Return type

Optional[str]

Static Methods

classmethod from_table_arn(scope, id, table_arn)

Creates a Table construct that represents an external table via table arn.

Parameters
  • scope (Construct) – The parent creating construct (usually this).

  • id (str) – The construct’s name.

  • table_arn (str) – The table’s ARN.

Return type

ITable

classmethod from_table_attributes(scope, id, *, encryption_key=None, global_indexes=None, local_indexes=None, table_arn=None, table_name=None, table_stream_arn=None)

Creates a Table construct that represents an external table.

Parameters
  • scope (Construct) – The parent creating construct (usually this).

  • id (str) – The construct’s name.

  • encryption_key (Optional[IKey]) – KMS encryption key, if this table uses a customer-managed encryption key. Default: - no key

  • global_indexes (Optional[List[str]]) – The name of the global indexes set for this Table. Note that you need to set either this property, or {@link localIndexes}, if you want methods like grantReadData() to grant permissions for indexes as well as the table itself. Default: - no global indexes

  • local_indexes (Optional[List[str]]) – The name of the local indexes set for this Table. Note that you need to set either this property, or {@link globalIndexes}, if you want methods like grantReadData() to grant permissions for indexes as well as the table itself. Default: - no local indexes

  • table_arn (Optional[str]) – The ARN of the dynamodb table. One of this, or {@link tableName}, is required. Default: - no table arn

  • table_name (Optional[str]) – The table name of the dynamodb table. One of this, or {@link tableArn}, is required. Default: - no table name

  • table_stream_arn (Optional[str]) – The ARN of the table’s stream. Default: - no table stream

Return type

ITable

classmethod from_table_name(scope, id, table_name)

Creates a Table construct that represents an external table via table name.

Parameters
  • scope (Construct) – The parent creating construct (usually this).

  • id (str) – The construct’s name.

  • table_name (str) – The table’s name.

Return type

ITable

classmethod grant_list_streams(grantee)

Permits an IAM Principal to list all DynamoDB Streams.

Parameters

grantee (IGrantable) – The principal (no-op if undefined).

deprecated :deprecated: Use {@link #grantTableListStreams} for more granular permission

stability :stability: deprecated

Return type

Grant

classmethod is_construct(x)

Return whether the given object is a Construct.

Parameters

x (Any) –

Return type

bool