class Table (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.DynamoDB.Table |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awsdynamodb#Table |
Java | software.amazon.awscdk.services.dynamodb.Table |
Python | aws_cdk.aws_dynamodb.Table |
TypeScript (source) | aws-cdk-lib » aws_dynamodb » Table |
Implements
IConstruct
, IDependable
, IResource
, ITable
, IResource
Provides a DynamoDB table.
Example
import * as eventsources from 'aws-cdk-lib/aws-lambda-event-sources';
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
import { Key } from 'aws-cdk-lib/aws-kms';
declare const fn: lambda.Function;
const table = new dynamodb.Table(this, 'Table', {
partitionKey: {
name: 'id',
type: dynamodb.AttributeType.STRING,
},
stream: dynamodb.StreamViewType.NEW_IMAGE,
});
// Your self managed KMS key
const myKey = Key.fromKeyArn(
this,
'SourceBucketEncryptionKey',
'arn:aws:kms:us-east-1:123456789012:key/<key-id>',
);
fn.addEventSource(new eventsources.DynamoEventSource(table, {
startingPosition: lambda.StartingPosition.LATEST,
filters: [lambda.FilterCriteria.filter({ eventName: lambda.FilterRule.isEqual('INSERT') })],
filterEncryption: myKey,
}));
Initializer
new Table(scope: Construct, id: string, props: TableProps)
Parameters
- scope
Construct
- id
string
- props
Table
Props
Construct Props
Name | Type | Description |
---|---|---|
partition | Attribute | Partition key attribute definition. |
billing | Billing | Specify how you are charged for read and write throughput and how you manage capacity. |
contributor | boolean | Whether CloudWatch contributor insights is enabled. |
deletion | boolean | Enables deletion protection for the table. |
encryption? | Table | Whether server-side encryption with an AWS managed customer master key is enabled. |
encryption | IKey | External KMS key to use for table encryption. |
import | Import | The properties of data being imported from the S3 bucket source to the table. |
kinesis | Approximate | Kinesis Data Stream approximate creation timestamp prescision. |
kinesis | IStream | Kinesis Data Stream to capture item-level changes for the table. |
max | number | The maximum read request units for the table. |
max | number | The write request units for the table. |
point | boolean | Whether point-in-time recovery is enabled. |
read | number | The read capacity for the table. |
removal | Removal | The removal policy to apply to the DynamoDB Table. |
replication | string[] | Regions where replica tables will be created. |
replication | Duration | The timeout for a table replication operation in a single region. |
resource | Policy | Resource policy to assign to table. |
sort | Attribute | Sort key attribute definition. |
stream? | Stream | When an item in the table is modified, StreamViewType determines what information is written to the stream for this table. |
table | Table | Specify the table class. |
table | string | Enforces a particular physical table name. |
time | string | The name of TTL attribute. |
wait | boolean | [WARNING: Use this flag with caution, misusing this flag may cause deleting existing replicas, refer to the detailed documentation for more information] Indicates whether CloudFormation stack waits for replication to finish. |
warm | Warm | Specify values to pre-warm you DynamoDB Table Warm Throughput feature is not available for Global Table replicas using the Table construct. |
write | number | The write capacity for the table. |
partitionKey
Type:
Attribute
Partition key attribute definition.
billingMode?
Type:
Billing
(optional, default: PROVISIONED if replicationRegions
is not specified, PAY_PER_REQUEST otherwise)
Specify how you are charged for read and write throughput and how you manage capacity.
contributorInsightsEnabled?
Type:
boolean
(optional, default: false)
Whether CloudWatch contributor insights is enabled.
deletionProtection?
Type:
boolean
(optional, default: false)
Enables deletion protection for the table.
encryption?
Type:
Table
(optional, default: The table is encrypted with an encryption key managed by DynamoDB, and you are not charged any fee for using it.)
Whether server-side encryption with an AWS managed customer master key is enabled.
This property cannot be set if serverSideEncryption
is set.
NOTE: if you set this to
CUSTOMER_MANAGED
andencryptionKey
is not specified, the key that the Tablet generates for you will be created with default permissions. If you are using CDKv2, these permissions will be sufficient to enable the key for use with DynamoDB tables. If you are using CDKv1, make sure the feature flag@aws-cdk/aws-kms:defaultKeyPolicies
is set totrue
in yourcdk.json
.
encryptionKey?
Type:
IKey
(optional, 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.
If encryption
and this property are both undefined, then the table is encrypted with
an encryption key managed by DynamoDB, and you are not charged any fee for using it.)
External KMS key to use for table encryption.
This property can only be set if encryption
is set to TableEncryption.CUSTOMER_MANAGED
.
importSource?
Type:
Import
(optional, default: no data import from the S3 bucket)
The properties of data being imported from the S3 bucket source to the table.
kinesisPrecisionTimestamp?
Type:
Approximate
(optional, default: ApproximateCreationDateTimePrecision.MICROSECOND)
Kinesis Data Stream approximate creation timestamp prescision.
kinesisStream?
Type:
IStream
(optional, default: no Kinesis Data Stream)
Kinesis Data Stream to capture item-level changes for the table.
maxReadRequestUnits?
Type:
number
(optional, default: on-demand throughput is disabled)
The maximum read request units for the table.
Careful if you add Global Secondary Indexes, as those will share the table's maximum on-demand throughput.
Can only be provided if billingMode is PAY_PER_REQUEST.
maxWriteRequestUnits?
Type:
number
(optional, default: on-demand throughput is disabled)
The write request units for the table.
Careful if you add Global Secondary Indexes, as those will share the table's maximum on-demand throughput.
Can only be provided if billingMode is PAY_PER_REQUEST.
pointInTimeRecovery?
Type:
boolean
(optional, default: point-in-time recovery is disabled)
Whether point-in-time recovery is enabled.
readCapacity?
Type:
number
(optional, default: 5)
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.
removalPolicy?
Type:
Removal
(optional, default: RemovalPolicy.RETAIN)
The removal policy to apply to the DynamoDB Table.
replicationRegions?
Type:
string[]
(optional, default: no replica tables are created)
Regions where replica tables will be created.
replicationTimeout?
Type:
Duration
(optional, default: Duration.minutes(30))
The timeout for a table replication operation in a single region.
resourcePolicy?
Type:
Policy
(optional, default: No resource policy statement)
Resource policy to assign to table.
sortKey?
Type:
Attribute
(optional, default: no sort key)
Sort key attribute definition.
stream?
Type:
Stream
(optional, default: streams are disabled unless replicationRegions
is specified)
When an item in the table is modified, StreamViewType determines what information is written to the stream for this table.
tableClass?
Type:
Table
(optional, default: STANDARD)
Specify the table class.
tableName?
Type:
string
(optional, default:
Enforces a particular physical table name.
timeToLiveAttribute?
Type:
string
(optional, default: TTL is disabled)
The name of TTL attribute.
waitForReplicationToFinish?
Type:
boolean
(optional, default: true)
[WARNING: Use this flag with caution, misusing this flag may cause deleting existing replicas, refer to the detailed documentation for more information] Indicates whether CloudFormation stack waits for replication to finish.
If set to false, the CloudFormation resource will mark the resource as created and replication will be completed asynchronously. This property is ignored if replicationRegions property is not set.
WARNING: DO NOT UNSET this property if adding/removing multiple replicationRegions in one deployment, as CloudFormation only supports one region replication at a time. CDK overcomes this limitation by waiting for replication to finish before starting new replicationRegion.
If the custom resource which handles replication has a physical resource
ID with the format region
instead of tablename-region
(this would happen
if the custom resource hasn't received an event since v1.91.0), DO NOT SET
this property to false without making a change to the table name.
This will cause the existing replicas to be deleted.
warmThroughput?
Type:
Warm
(optional, default: warm throughput is not configured)
Specify values to pre-warm you DynamoDB Table Warm Throughput feature is not available for Global Table replicas using the Table
construct.
To enable Warm Throughput, use the TableV2
construct instead.
writeCapacity?
Type:
number
(optional, default: 5)
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.
Properties
Name | Type | Description |
---|---|---|
env | Resource | The environment this resource belongs to. |
has | boolean | Whether this table has indexes. |
node | Node | The tree node. |
stack | Stack | The stack in which this resource is defined. |
table | string | Arn of the dynamodb table. |
table | string | Table name of the dynamodb table. |
encryption | IKey | KMS encryption key, if this table uses a customer-managed encryption key. |
resource | Policy | Resource policy to assign to DynamoDB Table. |
table | string | ARN of the table's stream, if there is one. |
env
Type:
Resource
The environment this resource belongs to.
For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.
hasIndex
Type:
boolean
Whether this table has indexes.
node
Type:
Node
The tree node.
stack
Type:
Stack
The stack in which this resource is defined.
tableArn
Type:
string
Arn of the dynamodb table.
tableName
Type:
string
Table name of the dynamodb table.
encryptionKey?
Type:
IKey
(optional)
KMS encryption key, if this table uses a customer-managed encryption key.
resourcePolicy?
Type:
Policy
(optional, default: No resource policy statements are added to the created table.)
Resource policy to assign to DynamoDB Table.
tableStreamArn?
Type:
string
(optional)
ARN of the table's stream, if there is one.
Methods
Name | Description |
---|---|
add | Add a global secondary index of table. |
add | Add a local secondary index of table. |
add | Adds a statement to the resource policy associated with this file system. |
apply | Apply the given removal policy to this resource. |
auto | Enable read capacity scaling for the given GSI. |
auto | Enable write capacity scaling for the given GSI. |
auto | Enable read capacity scaling for this table. |
auto | Enable write capacity scaling for this table. |
grant(grantee, ...actions) | Adds an IAM policy statement associated with this table to an IAM principal's policy. |
grant | Permits all DynamoDB operations ("dynamodb:*") to an IAM principal. |
grant | Permits an IAM principal all data read operations from this table: BatchGetItem, GetRecords, GetShardIterator, Query, GetItem, Scan, DescribeTable. |
grant | Permits an IAM principal to all data read/write operations to this table. |
grant | Adds an IAM policy statement associated with this table's stream to an IAM principal's policy. |
grant | Permits an IAM principal all stream data read operations for this table's stream: DescribeStream, GetRecords, GetShardIterator, ListStreams. |
grant | Permits an IAM Principal to list streams attached to current dynamodb table. |
grant | Permits an IAM principal all data write operations to this table: BatchWriteItem, PutItem, UpdateItem, DeleteItem, DescribeTable. |
metric(metricName, props?) | Return the given named metric for this Table. |
metric | Metric for the conditional check failed requests this table. |
metric | Metric for the consumed read capacity units this table. |
metric | Metric for the consumed write capacity units this table. |
metric | Metric for the successful request latency this table. |
metric | Metric for the system errors this table. |
metric | Metric for the system errors this table. |
metric | How many requests are throttled on this table. |
metric | How many requests are throttled on this table, for the given operation. |
metric | How many requests are throttled on this table. |
metric | Metric for the user errors. |
schema(indexName?) | Get schema attributes of table or index. |
to | Returns a string representation of this construct. |
static from | Creates a Table construct that represents an external table via table arn. |
static from | Creates a Table construct that represents an external table. |
static from | Creates a Table construct that represents an external table via table name. |
addGlobalSecondaryIndex(props)
public addGlobalSecondaryIndex(props: GlobalSecondaryIndexProps): void
Parameters
- props
Global
— the property of global secondary index.Secondary Index Props
Add a global secondary index of table.
addLocalSecondaryIndex(props)
public addLocalSecondaryIndex(props: LocalSecondaryIndexProps): void
Parameters
- props
Local
— the property of local secondary index.Secondary Index Props
Add a local secondary index of table.
addToResourcePolicy(statement)
public addToResourcePolicy(statement: PolicyStatement): AddToResourcePolicyResult
Parameters
- statement
Policy
— The policy statement to add.Statement
Returns
Adds a statement to the resource policy associated with this file system.
A resource policy will be automatically created upon the first call to addToResourcePolicy
.
Note that this does not work with imported file systems.
applyRemovalPolicy(policy)
public applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
Apply the given removal policy to this resource.
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY
), or left in your AWS
account for data recovery and cleanup later (RemovalPolicy.RETAIN
).
autoScaleGlobalSecondaryIndexReadCapacity(indexName, props)
public autoScaleGlobalSecondaryIndexReadCapacity(indexName: string, props: EnableScalingProps): IScalableTableAttribute
Parameters
- indexName
string
- props
Enable
Scaling Props
Returns
Enable read capacity scaling for the given GSI.
autoScaleGlobalSecondaryIndexWriteCapacity(indexName, props)
public autoScaleGlobalSecondaryIndexWriteCapacity(indexName: string, props: EnableScalingProps): IScalableTableAttribute
Parameters
- indexName
string
- props
Enable
Scaling Props
Returns
Enable write capacity scaling for the given GSI.
autoScaleReadCapacity(props)
public autoScaleReadCapacity(props: EnableScalingProps): IScalableTableAttribute
Parameters
- props
Enable
Scaling Props
Returns
Enable read capacity scaling for this table.
autoScaleWriteCapacity(props)
public autoScaleWriteCapacity(props: EnableScalingProps): IScalableTableAttribute
Parameters
- props
Enable
Scaling Props
Returns
Enable write capacity scaling for this table.
grant(grantee, ...actions)
public grant(grantee: IGrantable, ...actions: string[]): Grant
Parameters
- grantee
IGrantable
— The principal (no-op if undefined). - actions
string
— The set of actions to allow (i.e. "dynamodb:PutItem", "dynamodb:GetItem", ...).
Returns
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.
grantFullAccess(grantee)
public grantFullAccess(grantee: IGrantable): Grant
Parameters
- grantee
IGrantable
— The principal to grant access to.
Returns
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.
grantReadData(grantee)
public grantReadData(grantee: IGrantable): Grant
Parameters
- grantee
IGrantable
— The principal to grant access to.
Returns
Permits an IAM principal all data read operations from this table: BatchGetItem, GetRecords, GetShardIterator, Query, GetItem, Scan, DescribeTable.
Appropriate grants will also be added to the customer-managed KMS key if one was configured.
grantReadWriteData(grantee)
public grantReadWriteData(grantee: IGrantable): Grant
Parameters
- grantee
IGrantable
— The principal to grant access to.
Returns
Permits an IAM principal to all data read/write operations to this table.
BatchGetItem, GetRecords, GetShardIterator, Query, GetItem, Scan, BatchWriteItem, PutItem, UpdateItem, DeleteItem, DescribeTable
Appropriate grants will also be added to the customer-managed KMS key if one was configured.
grantStream(grantee, ...actions)
public grantStream(grantee: IGrantable, ...actions: string[]): Grant
Parameters
- grantee
IGrantable
— The principal (no-op if undefined). - actions
string
— The set of actions to allow (i.e. "dynamodb:DescribeStream", "dynamodb:GetRecords", ...).
Returns
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.
grantStreamRead(grantee)
public grantStreamRead(grantee: IGrantable): Grant
Parameters
- grantee
IGrantable
— The principal to grant access to.
Returns
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.
grantTableListStreams(grantee)
public grantTableListStreams(grantee: IGrantable): Grant
Parameters
- grantee
IGrantable
— The principal (no-op if undefined).
Returns
Permits an IAM Principal to list streams attached to current dynamodb table.
grantWriteData(grantee)
public grantWriteData(grantee: IGrantable): Grant
Parameters
- grantee
IGrantable
— The principal to grant access to.
Returns
Permits an IAM principal all data write operations to this table: BatchWriteItem, PutItem, UpdateItem, DeleteItem, DescribeTable.
Appropriate grants will also be added to the customer-managed KMS key if one was configured.
metric(metricName, props?)
public metric(metricName: string, props?: MetricOptions): Metric
Parameters
- metricName
string
- props
Metric
Options
Returns
Return the given named metric for this Table.
By default, the metric will be calculated as a sum over a period of 5 minutes.
You can customize this by using the statistic
and period
properties.
metricConditionalCheckFailedRequests(props?)
public metricConditionalCheckFailedRequests(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Metric for the conditional check failed requests this table.
By default, the metric will be calculated as a sum over a period of 5 minutes.
You can customize this by using the statistic
and period
properties.
metricConsumedReadCapacityUnits(props?)
public metricConsumedReadCapacityUnits(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Metric for the consumed read capacity units this table.
By default, the metric will be calculated as a sum over a period of 5 minutes.
You can customize this by using the statistic
and period
properties.
metricConsumedWriteCapacityUnits(props?)
public metricConsumedWriteCapacityUnits(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Metric for the consumed write capacity units this table.
By default, the metric will be calculated as a sum over a period of 5 minutes.
You can customize this by using the statistic
and period
properties.
metricSuccessfulRequestLatency(props?)
public metricSuccessfulRequestLatency(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Metric for the successful request latency this table.
By default, the metric will be calculated as an average over a period of 5 minutes.
You can customize this by using the statistic
and period
properties.
metricSystemErrors(props?)
public metricSystemErrors(props?: MetricOptions): Metric
⚠️ Deprecated: use metricSystemErrorsForOperations
.
Parameters
- props
Metric
Options
Returns
Metric for the system errors this table.
metricSystemErrorsForOperations(props?)
public metricSystemErrorsForOperations(props?: SystemErrorsForOperationsMetricOptions): IMetric
Parameters
Returns
Metric for the system errors this table.
This will sum errors across all possible operations.
Note that by default, each individual metric will be calculated as a sum over a period of 5 minutes.
You can customize this by using the statistic
and period
properties.
metricThrottledRequests(props?)
public metricThrottledRequests(props?: MetricOptions): Metric
⚠️ Deprecated: Do not use this function. It returns an invalid metric. Use metricThrottledRequestsForOperation
instead.
Parameters
- props
Metric
Options
Returns
How many requests are throttled on this table.
Default: sum over 5 minutes
metricThrottledRequestsForOperation(operation, props?)
public metricThrottledRequestsForOperation(operation: string, props?: MetricOptions): Metric
Parameters
- operation
string
- props
Metric
Options
Returns
How many requests are throttled on this table, for the given operation.
Default: sum over 5 minutes
metricThrottledRequestsForOperations(props?)
public metricThrottledRequestsForOperations(props?: OperationsMetricOptions): IMetric
Parameters
- props
Operations
Metric Options
Returns
How many requests are throttled on this table.
This will sum errors across all possible operations.
Note that by default, each individual metric will be calculated as a sum over a period of 5 minutes.
You can customize this by using the statistic
and period
properties.
metricUserErrors(props?)
public metricUserErrors(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Metric for the user errors.
Note that this metric reports user errors across all the tables in the account and region the table resides in.
By default, the metric will be calculated as a sum over a period of 5 minutes.
You can customize this by using the statistic
and period
properties.
schema(indexName?)
public schema(indexName?: string): SchemaOptions
Parameters
- indexName
string
Returns
Get schema attributes of table or index.
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.
static fromTableArn(scope, id, tableArn)
public static fromTableArn(scope: Construct, id: string, tableArn: string): ITable
Parameters
- scope
Construct
— The parent creating construct (usuallythis
). - id
string
— The construct's name. - tableArn
string
— The table's ARN.
Returns
Creates a Table construct that represents an external table via table arn.
static fromTableAttributes(scope, id, attrs)
public static fromTableAttributes(scope: Construct, id: string, attrs: TableAttributes): ITable
Parameters
- scope
Construct
— The parent creating construct (usuallythis
). - id
string
— The construct's name. - attrs
Table
— AAttributes TableAttributes
object.
Returns
Creates a Table construct that represents an external table.
static fromTableName(scope, id, tableName)
public static fromTableName(scope: Construct, id: string, tableName: string): ITable
Parameters
- scope
Construct
— The parent creating construct (usuallythis
). - id
string
— The construct's name. - tableName
string
— The table's name.
Returns
Creates a Table construct that represents an external table via table name.