class CfnTable (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.DynamoDB.CfnTable |
Java | software.amazon.awscdk.services.dynamodb.CfnTable |
Python | aws_cdk.aws_dynamodb.CfnTable |
TypeScript | @aws-cdk/aws-dynamodb » CfnTable |
Implements
IConstruct
, IConstruct
, IDependable
, IInspectable
A CloudFormation AWS::DynamoDB::Table
.
The AWS::DynamoDB::Table
resource creates a DynamoDB table. For more information, see CreateTable in the Amazon DynamoDB API Reference .
You should be aware of the following behaviors when working with DynamoDB tables:
- AWS CloudFormation typically creates DynamoDB tables in parallel. However, if your template includes multiple DynamoDB tables with indexes, you must declare dependencies so that the tables are created sequentially. Amazon DynamoDB limits the number of tables with secondary indexes that are in the creating state. If you create multiple tables with indexes at the same time, DynamoDB returns an error and the stack operation fails. For an example, see DynamoDB Table with a DependsOn Attribute .
Our guidance is to use the latest schema documented here for your AWS CloudFormation templates. This schema supports the provisioning of all table settings below. When using this schema in your AWS CloudFormation templates, please ensure that your Identity and Access Management ( IAM ) policies are updated with appropriate permissions to allow for the authorization of these setting changes.
Example
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import * as dynamodb from '@aws-cdk/aws-dynamodb';
const cfnTable = new dynamodb.CfnTable(this, 'MyCfnTable', {
keySchema: [{
attributeName: 'attributeName',
keyType: 'keyType',
}],
// the properties below are optional
attributeDefinitions: [{
attributeName: 'attributeName',
attributeType: 'attributeType',
}],
billingMode: 'billingMode',
contributorInsightsSpecification: {
enabled: false,
},
deletionProtectionEnabled: false,
globalSecondaryIndexes: [{
indexName: 'indexName',
keySchema: [{
attributeName: 'attributeName',
keyType: 'keyType',
}],
projection: {
nonKeyAttributes: ['nonKeyAttributes'],
projectionType: 'projectionType',
},
// the properties below are optional
contributorInsightsSpecification: {
enabled: false,
},
provisionedThroughput: {
readCapacityUnits: 123,
writeCapacityUnits: 123,
},
}],
importSourceSpecification: {
inputFormat: 'inputFormat',
s3BucketSource: {
s3Bucket: 's3Bucket',
// the properties below are optional
s3BucketOwner: 's3BucketOwner',
s3KeyPrefix: 's3KeyPrefix',
},
// the properties below are optional
inputCompressionType: 'inputCompressionType',
inputFormatOptions: {
csv: {
delimiter: 'delimiter',
headerList: ['headerList'],
},
},
},
kinesisStreamSpecification: {
streamArn: 'streamArn',
},
localSecondaryIndexes: [{
indexName: 'indexName',
keySchema: [{
attributeName: 'attributeName',
keyType: 'keyType',
}],
projection: {
nonKeyAttributes: ['nonKeyAttributes'],
projectionType: 'projectionType',
},
}],
pointInTimeRecoverySpecification: {
pointInTimeRecoveryEnabled: false,
},
provisionedThroughput: {
readCapacityUnits: 123,
writeCapacityUnits: 123,
},
sseSpecification: {
sseEnabled: false,
// the properties below are optional
kmsMasterKeyId: 'kmsMasterKeyId',
sseType: 'sseType',
},
streamSpecification: {
streamViewType: 'streamViewType',
},
tableClass: 'tableClass',
tableName: 'tableName',
tags: [{
key: 'key',
value: 'value',
}],
timeToLiveSpecification: {
attributeName: 'attributeName',
enabled: false,
},
});
Initializer
new CfnTable(scope: Construct, id: string, props: CfnTableProps)
Parameters
- scope
Construct
— - scope in which this resource is defined. - id
string
— - scoped id of the resource. - props
Cfn
— - resource properties.Table Props
Create a new AWS::DynamoDB::Table
.
Construct Props
Name | Type | Description |
---|---|---|
key | IResolvable | IResolvable | Key [] | Specifies the attributes that make up the primary key for the table. |
attribute | IResolvable | IResolvable | Attribute [] | A list of attributes that describe the key schema for the table and indexes. |
billing | string | Specify how you are charged for read and write throughput and how you manage capacity. |
contributor | IResolvable | Contributor | The settings used to enable or disable CloudWatch Contributor Insights for the specified table. |
deletion | boolean | IResolvable | Determines if a table is protected from deletion. |
global | IResolvable | IResolvable | Global [] | Global secondary indexes to be created on the table. You can create up to 20 global secondary indexes. |
import | IResolvable | Import | Specifies the properties of data being imported from the S3 bucket source to the table. |
kinesis | IResolvable | Kinesis | The Kinesis Data Streams configuration for the specified table. |
local | IResolvable | IResolvable | Local [] | Local secondary indexes to be created on the table. |
point | IResolvable | Point | The settings used to enable point in time recovery. |
provisioned | IResolvable | Provisioned | Throughput for the specified table, which consists of values for ReadCapacityUnits and WriteCapacityUnits . |
sse | IResolvable | SSESpecification | Specifies the settings to enable server-side encryption. |
stream | IResolvable | Stream | The settings for the DynamoDB table stream, which capture changes to items stored in the table. |
table | string | The table class of the new table. |
table | string | A name for the table. |
tags? | Cfn [] | An array of key-value pairs to apply to this resource. |
time | IResolvable | Time | Specifies the Time to Live (TTL) settings for the table. |
keySchema
Type:
IResolvable
|
IResolvable
|
Key
[]
Specifies the attributes that make up the primary key for the table.
The attributes in the KeySchema
property must also be defined in the AttributeDefinitions
property.
attributeDefinitions?
Type:
IResolvable
|
IResolvable
|
Attribute
[]
(optional)
A list of attributes that describe the key schema for the table and indexes.
This property is required to create a DynamoDB table.
Update requires: Some interruptions . Replacement if you edit an existing AttributeDefinition.
billingMode?
Type:
string
(optional)
Specify how you are charged for read and write throughput and how you manage capacity.
Valid values include:
PROVISIONED
- We recommend usingPROVISIONED
for predictable workloads.PROVISIONED
sets the billing mode to Provisioned Mode .PAY_PER_REQUEST
- We recommend usingPAY_PER_REQUEST
for unpredictable workloads.PAY_PER_REQUEST
sets the billing mode to On-Demand Mode .
If not specified, the default is PROVISIONED
.
contributorInsightsSpecification?
Type:
IResolvable
|
Contributor
(optional)
The settings used to enable or disable CloudWatch Contributor Insights for the specified table.
deletionProtectionEnabled?
Type:
boolean |
IResolvable
(optional)
Determines if a table is protected from deletion.
When enabled, the table cannot be deleted by any user or process. This setting is disabled by default. For more information, see Using deletion protection in the Amazon DynamoDB Developer Guide .
globalSecondaryIndexes?
Type:
IResolvable
|
IResolvable
|
Global
[]
(optional)
Global secondary indexes to be created on the table. You can create up to 20 global secondary indexes.
If you update a table to include a new global secondary index, AWS CloudFormation initiates the index creation and then proceeds with the stack update. AWS CloudFormation doesn't wait for the index to complete creation because the backfilling phase can take a long time, depending on the size of the table. You can't use the index or update the table until the index's status is
ACTIVE
. You can track its status by using the DynamoDB DescribeTable command.If you add or delete an index during an update, we recommend that you don't update any other resources. If your stack fails to update and is rolled back while adding a new index, you must manually delete the index.
Updates are not supported. The following are exceptions:
- If you update either the contributor insights specification or the provisioned throughput values of global secondary indexes, you can update the table without interruption.
- You can delete or add one global secondary index without interruption. If you do both in the same update (for example, by changing the index's logical ID), the update fails.
importSourceSpecification?
Type:
IResolvable
|
Import
(optional)
Specifies the properties of data being imported from the S3 bucket source to the table.
If you specify the
ImportSourceSpecification
property, and also specify either theStreamSpecification
, theTableClass
property, or theDeletionProtectionEnabled
property, the IAM entity creating/updating stack must haveUpdateTable
permission.
kinesisStreamSpecification?
Type:
IResolvable
|
Kinesis
(optional)
The Kinesis Data Streams configuration for the specified table.
localSecondaryIndexes?
Type:
IResolvable
|
IResolvable
|
Local
[]
(optional)
Local secondary indexes to be created on the table.
You can create up to 5 local secondary indexes. Each index is scoped to a given hash key value. The size of each hash key can be up to 10 gigabytes.
pointInTimeRecoverySpecification?
Type:
IResolvable
|
Point
(optional)
The settings used to enable point in time recovery.
provisionedThroughput?
Type:
IResolvable
|
Provisioned
(optional)
Throughput for the specified table, which consists of values for ReadCapacityUnits
and WriteCapacityUnits
.
For more information about the contents of a provisioned throughput structure, see Amazon DynamoDB Table ProvisionedThroughput .
If you set BillingMode
as PROVISIONED
, you must specify this property. If you set BillingMode
as PAY_PER_REQUEST
, you cannot specify this property.
sseSpecification?
Type:
IResolvable
|
SSESpecification
(optional)
Specifies the settings to enable server-side encryption.
streamSpecification?
Type:
IResolvable
|
Stream
(optional)
The settings for the DynamoDB table stream, which capture changes to items stored in the table.
tableClass?
Type:
string
(optional)
The table class of the new table.
Valid values are STANDARD
and STANDARD_INFREQUENT_ACCESS
.
tableName?
Type:
string
(optional)
A name for the table.
If you don't specify a name, AWS CloudFormation generates a unique physical ID and uses that ID for the table name. For more information, see Name Type .
If you specify a name, you cannot perform updates that require replacement of this resource. You can perform updates that require no or some interruption. If you must replace the resource, specify a new name.
tags?
Type:
Cfn
[]
(optional)
An array of key-value pairs to apply to this resource.
For more information, see Tag .
timeToLiveSpecification?
Type:
IResolvable
|
Time
(optional)
Specifies the Time to Live (TTL) settings for the table.
For detailed information about the limits in DynamoDB, see Limits in Amazon DynamoDB in the Amazon DynamoDB Developer Guide.
Properties
Name | Type | Description |
---|---|---|
attr | string | The Amazon Resource Name (ARN) of the DynamoDB table, such as arn:aws:dynamodb:us-east-2:123456789012:table/myDynamoDBTable . |
attr | string | The ARN of the DynamoDB stream, such as arn:aws:dynamodb:us-east-1:123456789012:table/testddbstack-myDynamoDBTable-012A1SL7SMP5Q/stream/2015-11-30T20:10:00.000 . |
cfn | ICfn | Options for this resource, such as condition, update policy etc. |
cfn | { [string]: any } | |
cfn | string | AWS resource type. |
creation | string[] | |
key | IResolvable | IResolvable | Key [] | Specifies the attributes that make up the primary key for the table. |
logical | string | The logical ID for this CloudFormation stack element. |
node | Construct | The construct tree node associated with this construct. |
ref | string | Return a string that will be resolved to a CloudFormation { Ref } for this element. |
stack | Stack | The stack in which this element is defined. |
tags | Tag | An array of key-value pairs to apply to this resource. |
attribute | IResolvable | IResolvable | Attribute [] | A list of attributes that describe the key schema for the table and indexes. |
billing | string | Specify how you are charged for read and write throughput and how you manage capacity. |
contributor | IResolvable | Contributor | The settings used to enable or disable CloudWatch Contributor Insights for the specified table. |
deletion | boolean | IResolvable | Determines if a table is protected from deletion. |
global | IResolvable | IResolvable | Global [] | Global secondary indexes to be created on the table. You can create up to 20 global secondary indexes. |
import | IResolvable | Import | Specifies the properties of data being imported from the S3 bucket source to the table. |
kinesis | IResolvable | Kinesis | The Kinesis Data Streams configuration for the specified table. |
local | IResolvable | IResolvable | Local [] | Local secondary indexes to be created on the table. |
point | IResolvable | Point | The settings used to enable point in time recovery. |
provisioned | IResolvable | Provisioned | Throughput for the specified table, which consists of values for ReadCapacityUnits and WriteCapacityUnits . |
sse | IResolvable | SSESpecification | Specifies the settings to enable server-side encryption. |
stream | IResolvable | Stream | The settings for the DynamoDB table stream, which capture changes to items stored in the table. |
table | string | The table class of the new table. |
table | string | A name for the table. |
time | IResolvable | Time | Specifies the Time to Live (TTL) settings for the table. |
static CFN_RESOURCE_TYPE_NAME | string | The CloudFormation resource type name for this resource class. |
attrArn
Type:
string
The Amazon Resource Name (ARN) of the DynamoDB table, such as arn:aws:dynamodb:us-east-2:123456789012:table/myDynamoDBTable
.
attrStreamArn
Type:
string
The ARN of the DynamoDB stream, such as arn:aws:dynamodb:us-east-1:123456789012:table/testddbstack-myDynamoDBTable-012A1SL7SMP5Q/stream/2015-11-30T20:10:00.000
.
You must specify the
StreamSpecification
property to use this attribute.
cfnOptions
Type:
ICfn
Options for this resource, such as condition, update policy etc.
cfnProperties
Type:
{ [string]: any }
cfnResourceType
Type:
string
AWS resource type.
creationStack
Type:
string[]
keySchema
Type:
IResolvable
|
IResolvable
|
Key
[]
Specifies the attributes that make up the primary key for the table.
The attributes in the KeySchema
property must also be defined in the AttributeDefinitions
property.
logicalId
Type:
string
The logical ID for this CloudFormation stack element.
The logical ID of the element is calculated from the path of the resource node in the construct tree.
To override this value, use overrideLogicalId(newLogicalId)
.
node
Type:
Construct
The construct tree node associated with this construct.
ref
Type:
string
Return a string that will be resolved to a CloudFormation { Ref }
for this element.
If, by any chance, the intrinsic reference of a resource is not a string, you could
coerce it to an IResolvable through Lazy.any({ produce: resource.ref })
.
stack
Type:
Stack
The stack in which this element is defined.
CfnElements must be defined within a stack scope (directly or indirectly).
tags
Type:
Tag
An array of key-value pairs to apply to this resource.
For more information, see Tag .
attributeDefinitions?
Type:
IResolvable
|
IResolvable
|
Attribute
[]
(optional)
A list of attributes that describe the key schema for the table and indexes.
This property is required to create a DynamoDB table.
Update requires: Some interruptions . Replacement if you edit an existing AttributeDefinition.
billingMode?
Type:
string
(optional)
Specify how you are charged for read and write throughput and how you manage capacity.
Valid values include:
PROVISIONED
- We recommend usingPROVISIONED
for predictable workloads.PROVISIONED
sets the billing mode to Provisioned Mode .PAY_PER_REQUEST
- We recommend usingPAY_PER_REQUEST
for unpredictable workloads.PAY_PER_REQUEST
sets the billing mode to On-Demand Mode .
If not specified, the default is PROVISIONED
.
contributorInsightsSpecification?
Type:
IResolvable
|
Contributor
(optional)
The settings used to enable or disable CloudWatch Contributor Insights for the specified table.
deletionProtectionEnabled?
Type:
boolean |
IResolvable
(optional)
Determines if a table is protected from deletion.
When enabled, the table cannot be deleted by any user or process. This setting is disabled by default. For more information, see Using deletion protection in the Amazon DynamoDB Developer Guide .
globalSecondaryIndexes?
Type:
IResolvable
|
IResolvable
|
Global
[]
(optional)
Global secondary indexes to be created on the table. You can create up to 20 global secondary indexes.
If you update a table to include a new global secondary index, AWS CloudFormation initiates the index creation and then proceeds with the stack update. AWS CloudFormation doesn't wait for the index to complete creation because the backfilling phase can take a long time, depending on the size of the table. You can't use the index or update the table until the index's status is
ACTIVE
. You can track its status by using the DynamoDB DescribeTable command.If you add or delete an index during an update, we recommend that you don't update any other resources. If your stack fails to update and is rolled back while adding a new index, you must manually delete the index.
Updates are not supported. The following are exceptions:
- If you update either the contributor insights specification or the provisioned throughput values of global secondary indexes, you can update the table without interruption.
- You can delete or add one global secondary index without interruption. If you do both in the same update (for example, by changing the index's logical ID), the update fails.
importSourceSpecification?
Type:
IResolvable
|
Import
(optional)
Specifies the properties of data being imported from the S3 bucket source to the table.
If you specify the
ImportSourceSpecification
property, and also specify either theStreamSpecification
, theTableClass
property, or theDeletionProtectionEnabled
property, the IAM entity creating/updating stack must haveUpdateTable
permission.
kinesisStreamSpecification?
Type:
IResolvable
|
Kinesis
(optional)
The Kinesis Data Streams configuration for the specified table.
localSecondaryIndexes?
Type:
IResolvable
|
IResolvable
|
Local
[]
(optional)
Local secondary indexes to be created on the table.
You can create up to 5 local secondary indexes. Each index is scoped to a given hash key value. The size of each hash key can be up to 10 gigabytes.
pointInTimeRecoverySpecification?
Type:
IResolvable
|
Point
(optional)
The settings used to enable point in time recovery.
provisionedThroughput?
Type:
IResolvable
|
Provisioned
(optional)
Throughput for the specified table, which consists of values for ReadCapacityUnits
and WriteCapacityUnits
.
For more information about the contents of a provisioned throughput structure, see Amazon DynamoDB Table ProvisionedThroughput .
If you set BillingMode
as PROVISIONED
, you must specify this property. If you set BillingMode
as PAY_PER_REQUEST
, you cannot specify this property.
sseSpecification?
Type:
IResolvable
|
SSESpecification
(optional)
Specifies the settings to enable server-side encryption.
streamSpecification?
Type:
IResolvable
|
Stream
(optional)
The settings for the DynamoDB table stream, which capture changes to items stored in the table.
tableClass?
Type:
string
(optional)
The table class of the new table.
Valid values are STANDARD
and STANDARD_INFREQUENT_ACCESS
.
tableName?
Type:
string
(optional)
A name for the table.
If you don't specify a name, AWS CloudFormation generates a unique physical ID and uses that ID for the table name. For more information, see Name Type .
If you specify a name, you cannot perform updates that require replacement of this resource. You can perform updates that require no or some interruption. If you must replace the resource, specify a new name.
timeToLiveSpecification?
Type:
IResolvable
|
Time
(optional)
Specifies the Time to Live (TTL) settings for the table.
For detailed information about the limits in DynamoDB, see Limits in Amazon DynamoDB in the Amazon DynamoDB Developer Guide.
static CFN_RESOURCE_TYPE_NAME
Type:
string
The CloudFormation resource type name for this resource class.
Methods
Name | Description |
---|---|
add | Syntactic sugar for addOverride(path, undefined) . |
add | Indicates that this resource depends on another resource and cannot be provisioned unless the other resource has been successfully provisioned. |
add | Add a value to the CloudFormation Resource Metadata. |
add | Adds an override to the synthesized CloudFormation resource. |
add | Adds an override that deletes the value of a property from the resource definition. |
add | Adds an override to a resource property. |
apply | Sets the deletion policy of the resource based on the removal policy specified. |
get | Returns a token for an runtime attribute of this resource. |
get | Retrieve a value value from the CloudFormation Resource Metadata. |
inspect(inspector) | Examines the CloudFormation resource and discloses attributes. |
override | Overrides the auto-generated logical ID with a specific ID. |
to | Returns a string representation of this construct. |
protected render |
DeletionOverride(path)
addpublic addDeletionOverride(path: string): void
Parameters
- path
string
— The path of the value to delete.
Syntactic sugar for addOverride(path, undefined)
.
DependsOn(target)
addpublic addDependsOn(target: CfnResource): void
Parameters
- target
Cfn
Resource
Indicates that this resource depends on another resource and cannot be provisioned unless the other resource has been successfully provisioned.
This can be used for resources across stacks (or nested stack) boundaries and the dependency will automatically be transferred to the relevant scope.
Metadata(key, value)
addpublic addMetadata(key: string, value: any): void
Parameters
- key
string
- value
any
Add a value to the CloudFormation Resource Metadata.
Note that this is a different set of metadata from CDK node metadata; this metadata ends up in the stack template under the resource, whereas CDK node metadata ends up in the Cloud Assembly.](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/metadata-section-structure.html
Note that this is a different set of metadata from CDK node metadata; this metadata ends up in the stack template under the resource, whereas CDK node metadata ends up in the Cloud Assembly.)
Override(path, value)
addpublic addOverride(path: string, value: any): void
Parameters
- path
string
— - The path of the property, you can use dot notation to override values in complex types. - value
any
— - The value.
Adds an override to the synthesized CloudFormation resource.
To add a
property override, either use addPropertyOverride
or prefix path
with
"Properties." (i.e. Properties.TopicName
).
If the override is nested, separate each nested level using a dot (.) in the path parameter. If there is an array as part of the nesting, specify the index in the path.
To include a literal .
in the property name, prefix with a \
. In most
programming languages you will need to write this as "\\."
because the
\
itself will need to be escaped.
For example,
cfnResource.addOverride('Properties.GlobalSecondaryIndexes.0.Projection.NonKeyAttributes', ['myattribute']);
cfnResource.addOverride('Properties.GlobalSecondaryIndexes.1.ProjectionType', 'INCLUDE');
would add the overrides
"Properties": {
"GlobalSecondaryIndexes": [
{
"Projection": {
"NonKeyAttributes": [ "myattribute" ]
...
}
...
},
{
"ProjectionType": "INCLUDE"
...
},
]
...
}
The value
argument to addOverride
will not be processed or translated
in any way. Pass raw JSON values in here with the correct capitalization
for CloudFormation. If you pass CDK classes or structs, they will be
rendered with lowercased key names, and CloudFormation will reject the
template.
PropertyDeletionOverride(propertyPath)
addpublic addPropertyDeletionOverride(propertyPath: string): void
Parameters
- propertyPath
string
— The path to the property.
Adds an override that deletes the value of a property from the resource definition.
PropertyOverride(propertyPath, value)
addpublic addPropertyOverride(propertyPath: string, value: any): void
Parameters
- propertyPath
string
— The path of the property. - value
any
— The value.
Adds an override to a resource property.
Syntactic sugar for addOverride("Properties.<...>", value)
.
RemovalPolicy(policy?, options?)
applypublic applyRemovalPolicy(policy?: RemovalPolicy, options?: RemovalPolicyOptions): void
Parameters
- policy
Removal
Policy - options
Removal
Policy Options
Sets the deletion policy of the resource based on the removal policy specified.
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
).
Att(attributeName)
getpublic getAtt(attributeName: string): Reference
Parameters
- attributeName
string
— The name of the attribute.
Returns
Returns a token for an runtime attribute of this resource.
Ideally, use generated attribute accessors (e.g. resource.arn
), but this can be used for future compatibility
in case there is no generated attribute.
Metadata(key)
getpublic getMetadata(key: string): any
Parameters
- key
string
Returns
any
Retrieve a value value from the CloudFormation Resource Metadata.
Note that this is a different set of metadata from CDK node metadata; this metadata ends up in the stack template under the resource, whereas CDK node metadata ends up in the Cloud Assembly.](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/metadata-section-structure.html
Note that this is a different set of metadata from CDK node metadata; this metadata ends up in the stack template under the resource, whereas CDK node metadata ends up in the Cloud Assembly.)
inspect(inspector)
public inspect(inspector: TreeInspector): void
Parameters
- inspector
Tree
— - tree inspector to collect and process attributes.Inspector
Examines the CloudFormation resource and discloses attributes.
LogicalId(newLogicalId)
overridepublic overrideLogicalId(newLogicalId: string): void
Parameters
- newLogicalId
string
— The new logical ID to use for this stack element.
Overrides the auto-generated logical ID with a specific ID.
String()
topublic toString(): string
Returns
string
Returns a string representation of this construct.
Properties(props)
protected renderprotected renderProperties(props: { [string]: any }): { [string]: any }
Parameters
- props
{ [string]: any }
Returns
{ [string]: any }