Table

class aws_cdk.aws_dynamodb.Table(scope, id, *, table_name=None, partition_key, billing_mode=None, point_in_time_recovery=None, read_capacity=None, removal_policy=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, point_in_time_recovery=None, read_capacity=None, removal_policy=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

  • 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

  • server_side_encryption (Optional[bool]) – Whether server-side encryption with an AWS managed customer master key is enabled. 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

  • 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.

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.

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.

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

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.

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.

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.

Parameters

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

Return type

Grant

to_string()

Returns a string representation of this construct.

Return type

str

Attributes

node

Construct tree node which offers APIs for interacting with the construct tree.

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

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, *, table_arn=None, table_name=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.

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

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

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