in packages/aws-cdk-lib/aws-dynamodb/lib/table.ts [1199:1295]
constructor(scope: Construct, id: string, props: TableProps) {
super(scope, id, {
physicalName: props.tableName,
});
// Enhanced CDK Analytics Telemetry
addConstructMetadata(this, props);
const { sseSpecification, encryptionKey } = this.parseEncryption(props);
const pointInTimeRecoverySpecification = this.validatePitr(props);
let streamSpecification: CfnTable.StreamSpecificationProperty | undefined;
if (props.replicationRegions) {
if (props.stream && props.stream !== StreamViewType.NEW_AND_OLD_IMAGES) {
throw new ValidationError('`stream` must be set to `NEW_AND_OLD_IMAGES` when specifying `replicationRegions`', this);
}
streamSpecification = { streamViewType: StreamViewType.NEW_AND_OLD_IMAGES };
this.billingMode = props.billingMode ?? BillingMode.PAY_PER_REQUEST;
} else {
this.billingMode = props.billingMode ?? BillingMode.PROVISIONED;
if (props.stream) {
streamSpecification = { streamViewType: props.stream };
}
}
this.validateProvisioning(props);
const kinesisStreamSpecification = props.kinesisStream
? {
streamArn: props.kinesisStream.streamArn,
...(props.kinesisPrecisionTimestamp && { approximateCreationDateTimePrecision: props.kinesisPrecisionTimestamp }),
}
: undefined;
this.table = new CfnTable(this, 'Resource', {
tableName: this.physicalName,
keySchema: this.keySchema,
attributeDefinitions: this.attributeDefinitions,
globalSecondaryIndexes: Lazy.any({ produce: () => this.globalSecondaryIndexes }, { omitEmptyArray: true }),
localSecondaryIndexes: Lazy.any({ produce: () => this.localSecondaryIndexes }, { omitEmptyArray: true }),
pointInTimeRecoverySpecification: pointInTimeRecoverySpecification,
billingMode: this.billingMode === BillingMode.PAY_PER_REQUEST ? this.billingMode : undefined,
provisionedThroughput: this.billingMode === BillingMode.PAY_PER_REQUEST ? undefined : {
readCapacityUnits: props.readCapacity || 5,
writeCapacityUnits: props.writeCapacity || 5,
},
...(props.maxReadRequestUnits || props.maxWriteRequestUnits ?
{
onDemandThroughput: this.billingMode === BillingMode.PROVISIONED ? undefined : {
maxReadRequestUnits: props.maxReadRequestUnits || undefined,
maxWriteRequestUnits: props.maxWriteRequestUnits || undefined,
},
} : undefined),
sseSpecification,
streamSpecification,
tableClass: props.tableClass,
timeToLiveSpecification: props.timeToLiveAttribute ? { attributeName: props.timeToLiveAttribute, enabled: true } : undefined,
contributorInsightsSpecification: props.contributorInsightsEnabled !== undefined ? { enabled: props.contributorInsightsEnabled } : undefined,
kinesisStreamSpecification: kinesisStreamSpecification,
deletionProtectionEnabled: props.deletionProtection,
importSourceSpecification: this.renderImportSourceSpecification(props.importSource),
resourcePolicy: props.resourcePolicy
? { policyDocument: props.resourcePolicy }
: undefined,
warmThroughput: props.warmThroughput?? undefined,
});
this.table.applyRemovalPolicy(props.removalPolicy);
this.encryptionKey = encryptionKey;
this.tableArn = this.getResourceArnAttribute(this.table.attrArn, {
service: 'dynamodb',
resource: 'table',
resourceName: this.physicalName,
});
this.tableName = this.getResourceNameAttribute(this.table.ref);
if (props.tableName) { this.node.addMetadata('aws:cdk:hasPhysicalName', this.tableName); }
this.tableStreamArn = streamSpecification ? this.table.attrStreamArn : undefined;
this.scalingRole = this.makeScalingRole();
this.addKey(props.partitionKey, HASH_KEY_TYPE);
this.tablePartitionKey = props.partitionKey;
if (props.sortKey) {
this.addKey(props.sortKey, RANGE_KEY_TYPE);
this.tableSortKey = props.sortKey;
}
if (props.replicationRegions && props.replicationRegions.length > 0) {
this.createReplicaTables(props.replicationRegions, props.replicationTimeout, props.waitForReplicationToFinish, props.replicaRemovalPolicy);
}
this.node.addValidation({ validate: () => this.validateTable() });
}