class DatabaseCluster (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.DocDB.DatabaseCluster |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awsdocdb#DatabaseCluster |
Java | software.amazon.awscdk.services.docdb.DatabaseCluster |
Python | aws_cdk.aws_docdb.DatabaseCluster |
TypeScript (source) | aws-cdk-lib » aws_docdb » DatabaseCluster |
Implements
IConstruct
, IDependable
, IResource
, IDatabase
, IConnectable
, ISecret
Create a clustered database with a given number of instances.
Example
declare const vpc: ec2.Vpc;
const cluster = new docdb.DatabaseCluster(this, 'Database', {
masterUser: {
username: 'myuser',
},
instanceType: ec2.InstanceType.of(ec2.InstanceClass.MEMORY5, ec2.InstanceSize.LARGE),
vpcSubnets: {
subnetType: ec2.SubnetType.PUBLIC,
},
vpc,
removalPolicy: RemovalPolicy.SNAPSHOT,
});
Initializer
new DatabaseCluster(scope: Construct, id: string, props: DatabaseClusterProps)
Parameters
- scope
Construct
- id
string
- props
Database
Cluster Props
Construct Props
Name | Type | Description |
---|---|---|
instance | Instance | What type of instance to start for the replicas. |
master | Login | Username and password for the administrative user. |
vpc | IVpc | What subnets to run the DocumentDB instances in. |
backup? | Backup | Backup settings. |
ca | Ca | The identifier of the CA certificate used for the instances. |
cloud | Retention | The number of days log events are kept in CloudWatch Logs. |
cloud | IRole | The IAM role for the Lambda function associated with the custom resource that sets the retention policy. |
copy | boolean | Whether to copy tags to the snapshot when a snapshot is created. |
db | string | An optional identifier for the cluster. |
deletion | boolean | Specifies whether this cluster can be deleted. |
enable | boolean | A value that indicates whether to enable Performance Insights for the instances in the DB Cluster. |
engine | string | What version of the database to start. |
export | boolean | Whether the audit logs should be exported to CloudWatch. |
export | boolean | Whether the profiler logs should be exported to CloudWatch. |
instance | string | Base identifier for instances. |
instance | Removal | The removal policy to apply to the cluster's instances. |
instances? | number | Number of DocDB compute instances. |
kms | IKey | The KMS key for storage encryption. |
parameter | ICluster | The DB parameter group to associate with the instance. |
port? | number | The port the DocumentDB cluster will listen on. |
preferred | string | A weekly time range in which maintenance should preferably execute. |
removal | Removal | 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. |
security | ISecurity | Security group. |
security | Removal | The removal policy to apply to the cluster's security group. |
storage | boolean | Whether to enable storage encryption. |
storage | Storage | The storage type of the DocDB cluster. |
vpc | Subnet | Where to place the instances within the VPC. |
instanceType
Type:
Instance
What type of instance to start for the replicas.
masterUser
Type:
Login
Username and password for the administrative user.
vpc
Type:
IVpc
What subnets to run the DocumentDB instances in.
Must be at least 2 subnets in two different AZs.
backup?
Type:
Backup
(optional, 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.)
Backup settings.
caCertificate?
Type:
Ca
(optional, default: DocumentDB will choose a certificate authority)
The identifier of the CA certificate used for the instances.
Specifying or updating this property triggers a reboot.
cloudWatchLogsRetention?
Type:
Retention
(optional, default: logs never expire)
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
.
cloudWatchLogsRetentionRole?
Type:
IRole
(optional, default: a new role is created.)
The IAM role for the Lambda function associated with the custom resource that sets the retention policy.
copyTagsToSnapshot?
Type:
boolean
(optional, default: false)
Whether to copy tags to the snapshot when a snapshot is created.
dbClusterName?
Type:
string
(optional, default: A name is automatically generated.)
An optional identifier for the cluster.
deletionProtection?
Type:
boolean
(optional, default: false)
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.
enablePerformanceInsights?
Type:
boolean
(optional, default: false)
A value that indicates whether to enable Performance Insights for the instances in the DB Cluster.
engineVersion?
Type:
string
(optional, default: the latest major version)
What version of the database to start.
exportAuditLogsToCloudWatch?
Type:
boolean
(optional, default: false)
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.
exportProfilerLogsToCloudWatch?
Type:
boolean
(optional, default: false)
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.
instanceIdentifierBase?
Type:
string
(optional, default: dbClusterName
is used with the word "Instance" appended. If dbClusterName
is not provided, the
identifier is automatically generated.)
Base identifier for instances.
Every replica is named by appending the replica number to this string, 1-based.
instanceRemovalPolicy?
Type:
Removal
(optional, default: RemovalPolicy.DESTROY
when removalPolicy
is set to SNAPSHOT
, removalPolicy
otherwise.)
The removal policy to apply to the cluster's instances.
Cannot be set to SNAPSHOT
.
instances?
Type:
number
(optional, default: 1)
Number of DocDB compute instances.
kmsKey?
Type:
IKey
(optional, default: default master key.)
The KMS key for storage encryption.
parameterGroup?
Type:
ICluster
(optional, default: no parameter group)
The DB parameter group to associate with the instance.
port?
Type:
number
(optional, default: DatabaseCluster.DEFAULT_PORT)
The port the DocumentDB cluster will listen on.
preferredMaintenanceWindow?
Type:
string
(optional, 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.)
A weekly time range in which maintenance should preferably execute.
Must be at least 30 minutes long.
Example: 'tue:04:17-tue:04:47'
removalPolicy?
Type:
Removal
(optional, default: Retain cluster.)
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.
securityGroup?
Type:
ISecurity
(optional, default: a new security group is created.)
Security group.
securityGroupRemovalPolicy?
Type:
Removal
(optional, default: RemovalPolicy.DESTROY
when removalPolicy
is set to SNAPSHOT
, removalPolicy
otherwise.)
The removal policy to apply to the cluster's security group.
Cannot be set to SNAPSHOT
.
storageEncrypted?
Type:
boolean
(optional, default: true)
Whether to enable storage encryption.
storageType?
Type:
Storage
(optional, default: StorageType.STANDARD)
The storage type of the DocDB cluster.
I/O-optimized storage is supported starting with engine version 5.0.0.
vpcSubnets?
Type:
Subnet
(optional, default: private subnets)
Where to place the instances within the VPC.
Properties
Name | Type | Description |
---|---|---|
cluster | Endpoint | The endpoint to use for read/write operations. |
cluster | string | Identifier of the cluster. |
cluster | Endpoint | Endpoint to use for load-balanced read-only operations. |
cluster | string | The resource id for the cluster; |
connections | Connections | The connections object to implement IConnectable. |
env | Resource | The environment this resource belongs to. |
instance | Endpoint [] | Endpoints which address each individual replica. |
instance | string[] | Identifiers of the replicas. |
node | Node | The tree node. |
security | string | Security group identifier of this database. |
stack | Stack | The stack in which this resource is defined. |
secret? | ISecret | The secret attached to this cluster. |
static DEFAULT_NUM_INSTANCES | number | The default number of instances in the DocDB cluster if none are specified. |
static DEFAULT_PORT | number | The default port Document DB listens on. |
clusterEndpoint
Type:
Endpoint
The endpoint to use for read/write operations.
clusterIdentifier
Type:
string
Identifier of the cluster.
clusterReadEndpoint
Type:
Endpoint
Endpoint to use for load-balanced read-only operations.
clusterResourceIdentifier
Type:
string
The resource id for the cluster;
for example: cluster-ABCD1234EFGH5678IJKL90MNOP. The cluster ID uniquely identifies the cluster and is used in things like IAM authentication policies.
connections
Type:
Connections
The connections object to implement IConnectable.
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.
instanceEndpoints
Type:
Endpoint
[]
Endpoints which address each individual replica.
instanceIdentifiers
Type:
string[]
Identifiers of the replicas.
node
Type:
Node
The tree node.
securityGroupId
Type:
string
Security group identifier of this database.
stack
Type:
Stack
The stack in which this resource is defined.
secret?
Type:
ISecret
(optional)
The secret attached to this cluster.
static DEFAULT_NUM_INSTANCES
Type:
number
The default number of instances in the DocDB cluster if none are specified.
static DEFAULT_PORT
Type:
number
The default port Document DB listens on.
Methods
Name | Description |
---|---|
add | Adds the multi user rotation to this cluster. |
add | Adds the single user rotation of the master password to this cluster. |
add | Adds security groups to this cluster. |
apply | Apply the given removal policy to this resource. |
as | Renders the secret attachment target specifications. |
to | Returns a string representation of this construct. |
static from | Import an existing DatabaseCluster from properties. |
RotationMultiUser(id, options)
addpublic addRotationMultiUser(id: string, options: RotationMultiUserOptions): SecretRotation
Parameters
- id
string
- options
Rotation
Multi User Options
Returns
Adds the multi user rotation to this cluster.
RotationSingleUser(automaticallyAfter?)
addpublic addRotationSingleUser(automaticallyAfter?: Duration): SecretRotation
Parameters
- automaticallyAfter
Duration
— Specifies the number of days after the previous rotation before Secrets Manager triggers the next automatic rotation.
Returns
Adds the single user rotation of the master password to this cluster.
SecurityGroups(...securityGroups)
addpublic addSecurityGroups(...securityGroups: ISecurityGroup[]): void
Parameters
- securityGroups
ISecurity
— The security groups to add.Group
Adds security groups to this cluster.
RemovalPolicy(policy)
applypublic 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
).
SecretAttachmentTarget()
aspublic asSecretAttachmentTarget(): SecretAttachmentTargetProps
Returns
Renders the secret attachment target specifications.
String()
topublic toString(): string
Returns
string
Returns a string representation of this construct.
DatabaseClusterAttributes(scope, id, attrs)
static frompublic static fromDatabaseClusterAttributes(scope: Construct, id: string, attrs: DatabaseClusterAttributes): IDatabaseCluster
Parameters
- scope
Construct
- id
string
- attrs
Database
Cluster Attributes
Returns
Import an existing DatabaseCluster from properties.