class TableV2 (construct)
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.DynamoDB.TableV2 |
![]() | github.com/aws/aws-cdk-go/awscdk/v2/awsdynamodb#TableV2 |
![]() | software.amazon.awscdk.services.dynamodb.TableV2 |
![]() | aws_cdk.aws_dynamodb.TableV2 |
![]() | aws-cdk-lib » aws_dynamodb » TableV2 |
Implements
IConstruct
, IDependable
, IResource
, ITable
, ITable
, IResource
A DynamoDB Table.
Example
import * as cdk from 'aws-cdk-lib';
const app = new cdk.App();
const stack = new cdk.Stack(app, 'Stack', { env: { region: 'us-west-2' } });
const globalTable = new dynamodb.TableV2(stack, 'GlobalTable', {
partitionKey: { name: 'pk', type: dynamodb.AttributeType.STRING },
// applies to all replicas, i.e., us-west-2, us-east-1, us-east-2
removalPolicy: cdk.RemovalPolicy.DESTROY,
replicas: [
{ region: 'us-east-1' },
{ region: 'us-east-2' },
],
});
Initializer
new TableV2(scope: Construct, id: string, props: TablePropsV2)
Parameters
- scope
Construct
- id
string
- props
Table
Props V2
Construct Props
Name | Type | Description |
---|---|---|
partition | Attribute | Partition key attribute definition. |
billing? | Billing | The billing mode and capacity settings to apply to the table. |
contributor | boolean | Whether CloudWatch contributor insights is enabled. |
deletion | boolean | Whether deletion protection is enabled. |
dynamo | Stream | When an item in the table is modified, StreamViewType determines what information is written to the stream. |
encryption? | Table | The server-side encryption. |
global | Global [] | Global secondary indexes. |
kinesis | IStream | Kinesis Data Stream to capture item level changes. |
local | Local [] | Local secondary indexes. |
point | boolean | Whether point-in-time recovery is enabled. |
point | Point | Whether point-in-time recovery is enabled and recoveryPeriodInDays is set. |
removal | Removal | The removal policy applied to the table. |
replicas? | Replica [] | Replica tables to deploy with the primary table. |
resource | Policy | Resource policy to assign to DynamoDB Table. |
sort | Attribute | Sort key attribute definition. |
table | Table | The table class. |
table | string | The name of the table. |
tags? | Cfn [] | Tags to be applied to the primary table (default replica table). |
time | string | The name of the TTL attribute. |
warm | Warm | The warm throughput configuration for the table. |
partitionKey
Type:
Attribute
Partition key attribute definition.
billing?
Type:
Billing
(optional, default: Billing.onDemand())
The billing mode and capacity settings to apply to the table.
contributorInsights?
Type:
boolean
(optional, default: false)
Whether CloudWatch contributor insights is enabled.
deletionProtection?
Type:
boolean
(optional, default: false)
Whether deletion protection is enabled.
dynamoStream?
Type:
Stream
(optional, default: streams are disabled if replicas are not configured and this property is
not specified. If this property is not specified when replicas are configured, then
NEW_AND_OLD_IMAGES will be the StreamViewType for all replicas)
When an item in the table is modified, StreamViewType determines what information is written to the stream.
encryption?
Type:
Table
(optional, default: TableEncryptionV2.dynamoOwnedKey())
The server-side encryption.
globalSecondaryIndexes?
Type:
Global
[]
(optional, default: no global secondary indexes)
Global secondary indexes.
Note: You can provide a maximum of 20 global secondary indexes.
kinesisStream?
Type:
IStream
(optional, default: no Kinesis Data Stream)
Kinesis Data Stream to capture item level changes.
localSecondaryIndexes?
Type:
Local
[]
(optional, default: no local secondary indexes)
Local secondary indexes.
Note: You can only provide a maximum of 5 local secondary indexes.
pointInTimeRecovery?
⚠️ Deprecated: use pointInTimeRecoverySpecification
instead
Type:
boolean
(optional, default: false - point in time recovery is not enabled.)
Whether point-in-time recovery is enabled.
pointInTimeRecoverySpecification?
Type:
Point
(optional, default: point in time recovery is not enabled.)
Whether point-in-time recovery is enabled and recoveryPeriodInDays is set.
removalPolicy?
Type:
Removal
(optional, default: RemovalPolicy.RETAIN)
The removal policy applied to the table.
replicas?
Type:
Replica
[]
(optional, default: no replica tables)
Replica tables to deploy with the primary table.
Note: Adding replica tables allows you to use your table as a global table. You cannot specify a replica table in the region that the primary table will be deployed to. Replica tables will only be supported if the stack deployment region is defined.
resourcePolicy?
Type:
Policy
(optional, default: No resource policy statements are added to the created table.)
Resource policy to assign to DynamoDB Table.
sortKey?
Type:
Attribute
(optional, default: no sort key)
Sort key attribute definition.
tableClass?
Type:
Table
(optional, default: TableClass.STANDARD)
The table class.
tableName?
Type:
string
(optional, default: generated by CloudFormation)
The name of the table.
tags?
Type:
Cfn
[]
(optional, default: no tags)
Tags to be applied to the primary table (default replica table).
timeToLiveAttribute?
Type:
string
(optional, default: TTL is disabled)
The name of the TTL attribute.
warmThroughput?
Type:
Warm
(optional, default: no warm throughput is configured)
The warm throughput configuration for the table.
Properties
Name | Type | Description |
---|---|---|
env | Resource | The environment this resource belongs to. |
has | boolean | |
node | Node | The tree node. |
region | string | |
stack | Stack | The stack in which this resource is defined. |
table | string | The ARN of the table. |
table | string | The name of the table. |
tags | Tag | |
encryption | IKey | The KMS encryption key for the table. |
resource | Policy | The resource policy for the table. |
table | string | The ID of the table. |
table | string | The stream ARN of the table. |
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
node
Type:
Node
The tree node.
region
Type:
string
stack
Type:
Stack
The stack in which this resource is defined.
tableArn
Type:
string
The ARN of the table.
tableName
Type:
string
The name of the table.
tags
Type:
Tag
encryptionKey?
Type:
IKey
(optional)
The KMS encryption key for the table.
resourcePolicy?
Type:
Policy
(optional)
The resource policy for the table.
tableId?
Type:
string
(optional)
The ID of the table.
tableStreamArn?
Type:
string
(optional)
The stream ARN of the table.
Methods
Name | Description |
---|---|
add | Add a global secondary index to the table. |
add | Add a local secondary index to the table. |
add | Add a replica table. |
add | Adds a statement to the resource policy associated with this file system. |
apply | Apply the given removal policy to this resource. |
grant(grantee, ...actions) | Adds an IAM policy statement associated with this table to an IAM principal's policy. |
grant | Permits an IAM principal to all DynamoDB operations ('dynamodb:*') on this table. |
grant | Permits an IAM principal all data read operations on this table. |
grant | Permits an IAM principal to all data read/write operations on this table. |
grant | Adds an IAM policy statement associated with this table to an IAM principal's policy. |
grant | Adds an IAM policy statement associated with this table to an IAM principal's policy. |
grant | Permits an IAM principal to list streams attached to this table. |
grant | Permits an IAM principal all data write operations on this table. |
metric(metricName, props?) | Return the given named metric for this table. |
metric | Metric for the conditional check failed requests for this table. |
metric | Metric for the consumed read capacity units for this table. |
metric | Metric for the consumed write capacity units for this table. |
metric | Metric for the successful request latency for this table. |
metric | Metric for the system errors this table. |
metric | Metric for the system errors for this table. This will sum errors across all possible operations. |
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. This will sum errors across all possible operations. |
metric | Metric for the user errors for this table. |
replica(region) | Retrieve a replica table. |
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: GlobalSecondaryIndexPropsV2): void
Parameters
- props
Global
— the properties of the global secondary index.Secondary Index Props V2
Add a global secondary index to the table.
Note: Global secondary indexes will be inherited by all replica tables.
addLocalSecondaryIndex(props)
public addLocalSecondaryIndex(props: LocalSecondaryIndexProps): void
Parameters
- props
Local
— the properties of the local secondary index.Secondary Index Props
Add a local secondary index to the table.
Note: Local secondary indexes will be inherited by all replica tables.
addReplica(props)
public addReplica(props: ReplicaTableProps): void
Parameters
- props
Replica
— the properties of the replica table to add.Table Props
Add a replica table.
Note: Adding a replica table will allow you to use your table as a global 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
).
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', etc.).
Returns
Adds an IAM policy statement associated with this table to an IAM principal's policy.
Note: 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 an IAM principal to all DynamoDB operations ('dynamodb:*') on this table.
Note: Appropriate grants will also be added to the customer-managed KMS keys associated with this table 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 on this table.
Actions: BatchGetItem, GetRecords, GetShardIterator, Query, GetItem, Scan, DescribeTable.
Note: Appropriate grants will also be added to the customer-managed KMS keys associated with this table 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 on this table.
Actions: BatchGetItem, GetRecords, GetShardIterator, Query, GetItem, Scan, BatchWriteItem, PutItem, UpdateItem, DeleteItem, DescribeTable.
Note: Appropriate grants will also be added to the customer-managed KMS keys associated with this table 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', etc.).
Returns
Adds an IAM policy statement associated with this table to an IAM principal's policy.
Note: 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
Adds an IAM policy statement associated with this table to an IAM principal's policy.
Actions: DescribeStream, GetRecords, GetShardIterator, ListStreams.
Note: Appropriate grants will also be added to the customer-managed KMS keys associated with this table if one was configured.
grantTableListStreams(grantee)
public grantTableListStreams(grantee: IGrantable): Grant
Parameters
- grantee
IGrantable
— the principal to grant access to.
Returns
Permits an IAM principal to list streams attached to this 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 on this table.
Actions: BatchWriteItem, PutItem, UpdateItem, DeleteItem, DescribeTable.
Note: Appropriate grants will also be added to the customer-managed KMS keys associated with this table 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 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.
metricConsumedReadCapacityUnits(props?)
public metricConsumedReadCapacityUnits(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Metric for the consumed read capacity units 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.
metricConsumedWriteCapacityUnits(props?)
public metricConsumedWriteCapacityUnits(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Metric for the consumed write capacity units 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.
metricSuccessfulRequestLatency(props?)
public metricSuccessfulRequestLatency(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Metric for the successful request latency for 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 for this table. This will sum errors across all possible operations.
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.
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.
metricThrottledRequestsForOperation(operation, props?)
public metricThrottledRequestsForOperation(operation: string, props?: OperationsMetricOptions): IMetric
Parameters
- operation
string
- props
Operations
Metric Options
Returns
How many requests are throttled on this table for the given operation.
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.
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.
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 for this table.
Note: 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.
replica(region)
public replica(region: string): ITableV2
Parameters
- region
string
— the region of the replica table.
Returns
Retrieve a replica table.
Note: Replica tables are not supported in a region agnostic stack.
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): ITableV2
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: TableAttributesV2): ITableV2
Parameters
- scope
Construct
— the parent creating construct (usuallythis
). - id
string
— the construct's name. - attrs
Table
— attributes of the table.Attributes V2
Returns
Creates a Table construct that represents an external table.
static fromTableName(scope, id, tableName)
public static fromTableName(scope: Construct, id: string, tableName: string): ITableV2
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.