AWS Fundamentals Logo
AWS Fundamentals
L2 Construct

DatabaseCluster

Create a clustered database with a given number of instances.

Import

import { DatabaseCluster } from 'aws-cdk-lib/aws-docdb';

Or use the module namespace:

import * as docdb from 'aws-cdk-lib/aws-docdb';
// docdb.DatabaseCluster

Properties

Configuration passed to the constructor as DatabaseClusterProps.

masterUserRequired
Login

Username and password for the administrative user.

vpcRequired
IVpc

What subnets to run the DocumentDB instances in. Must be at least 2 subnets in two different AZs.

backupOptional
BackupProps

Backup settings.

Default: - Backup retention period for automated backups is 1 day. Backup preferred window is set to a 30-minute window selected at random from an 8-hour block of time for each AWS Region, occurring on a random day of the week.

caCertificateOptional
CaCertificate

The identifier of the CA certificate used for the instances. Specifying or updating this property triggers a reboot.

Default: - DocumentDB will choose a certificate authority

cloudWatchLogsRetentionOptional
RetentionDays

The number of days log events are kept in CloudWatch Logs. When updating this property, unsetting it doesn't remove the log retention policy. To remove the retention policy, set the value to `Infinity`.

Default: - logs never expire

cloudWatchLogsRetentionRoleOptional
IRole

The IAM role for the Lambda function associated with the custom resource that sets the retention policy.

Default: - a new role is created.

copyTagsToSnapshotOptional
boolean

Whether to copy tags to the snapshot when a snapshot is created.

Default: - false

dbClusterNameOptional
string

An optional identifier for the cluster.

Default: - A name is automatically generated.

deletionProtectionOptional
boolean

Specifies whether this cluster can be deleted. If deletionProtection is enabled, the cluster cannot be deleted unless it is modified and deletionProtection is disabled. deletionProtection protects clusters from being accidentally deleted.

Default: - false

enablePerformanceInsightsOptional
boolean

A value that indicates whether to enable Performance Insights for the instances in the DB Cluster.

Default: - false

engineVersionOptional
string

What version of the database to start.

Default: - the latest major version

exportAuditLogsToCloudWatchOptional
boolean

Whether the audit logs should be exported to CloudWatch. Note that you also have to configure the audit log export in the Cluster's Parameter Group.

Default: false

exportProfilerLogsToCloudWatchOptional
boolean

Whether the profiler logs should be exported to CloudWatch. Note that you also have to configure the profiler log export in the Cluster's Parameter Group.

Default: false

instanceIdentifierBaseOptional
string

Base identifier for instances. Every replica is named by appending the replica number to this string, 1-based. Only applicable for provisioned clusters.

Default: - `dbClusterName` is used with the word "Instance" appended. If `dbClusterName` is not provided, the identifier is automatically generated.

instanceRemovalPolicyOptional
RemovalPolicy

The removal policy to apply to the cluster's instances. Cannot be set to `SNAPSHOT`.

Default: - `RemovalPolicy.DESTROY` when `removalPolicy` is set to `SNAPSHOT`, `removalPolicy` otherwise.

instancesOptional
number

Number of DocDB compute instances.

Default: 1

instanceTypeOptional
InstanceType

What type of instance to start for the replicas. Required for provisioned clusters, not applicable for serverless clusters.

Default: None

kmsKeyOptional
IKey

The KMS key for storage encryption.

Default: - default master key.

parameterGroupOptional
IDBClusterParameterGroupRef

The DB parameter group to associate with the instance.

Default: no parameter group

portOptional
number

The port the DocumentDB cluster will listen on.

Default: DatabaseCluster.DEFAULT_PORT

preferredMaintenanceWindowOptional
string

A weekly time range in which maintenance should preferably execute. Must be at least 30 minutes long. Example: 'tue:04:17-tue:04:47'

Default: - 30-minute window selected at random from an 8-hour block of time for each AWS Region, occurring on a random day of the week.

removalPolicyOptional
RemovalPolicy

The removal policy to apply when the cluster and its instances are removed or replaced during a stack update, or when the stack is deleted. This removal policy also applies to the implicit security group created for the cluster if one is not supplied as a parameter. When set to `SNAPSHOT`, the removal policy for the instances and the security group will default to `DESTROY` as those resources do not support the policy. Use the `instanceRemovalPolicy` and `securityGroupRemovalPolicy` to change the behavior.

Default: - Retain cluster.

securityGroupOptional
ISecurityGroup

Security group.

Default: a new security group is created.

securityGroupRemovalPolicyOptional
RemovalPolicy

The removal policy to apply to the cluster's security group. Cannot be set to `SNAPSHOT`.

Default: - `RemovalPolicy.DESTROY` when `removalPolicy` is set to `SNAPSHOT`, `removalPolicy` otherwise.

serverlessV2ScalingConfigurationOptional
ServerlessV2ScalingConfiguration

ServerlessV2 scaling configuration. When specified, the cluster will be created as a serverless cluster.

Default: None

storageEncryptedOptional
boolean

Whether to enable storage encryption.

Default: true

storageTypeOptional
StorageType

The storage type of the DocDB cluster. I/O-optimized storage is supported starting with engine version 5.0.0.

Default: StorageType.STANDARD

vpcSubnetsOptional
SubnetSelection

Where to place the instances within the VPC.

Default: private subnets

Learn AWS the Practical Way

Our bi-weekly newsletter teaches hands-on AWS fundamentals. No certification fluff - just practical knowledge.

Subscribe to Newsletter