DatabaseCluster L2 construct
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,
deletionProtection: true, // Enable deletion protection.
});
# vpc: ec2.Vpc
cluster = docdb.DatabaseCluster(self, "Database",
master_user=docdb.Login(
username="myuser"
),
instance_type=ec2.InstanceType.of(ec2.InstanceClass.MEMORY5, ec2.InstanceSize.LARGE),
vpc_subnets=ec2.SubnetSelection(
subnet_type=ec2.SubnetType.PUBLIC
),
vpc=vpc,
deletion_protection=True
)
Vpc vpc;
DatabaseCluster cluster = DatabaseCluster.Builder.create(this, "Database")
.masterUser(Login.builder()
.username("myuser")
.build())
.instanceType(InstanceType.of(InstanceClass.MEMORY5, InstanceSize.LARGE))
.vpcSubnets(SubnetSelection.builder()
.subnetType(SubnetType.PUBLIC)
.build())
.vpc(vpc)
.deletionProtection(true)
.build();
// Install: dotnet add package Amazon.CDK.Lib
Vpc vpc;
var cluster = new DatabaseCluster(this, "Database", new DatabaseClusterProps {
MasterUser = new Login {
Username = "myuser"
},
InstanceType = InstanceType.Of(InstanceClass.MEMORY5, InstanceSize.LARGE),
VpcSubnets = new SubnetSelection {
SubnetType = SubnetType.PUBLIC
},
Vpc = vpc,
DeletionProtection = true
});
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var vpc Vpc
cluster := docdb.NewDatabaseCluster(this, jsii.String("Database"), &DatabaseClusterProps{
MasterUser: &Login{
Username: jsii.String("myuser"),
},
InstanceType: ec2.InstanceType_Of(ec2.InstanceClass_MEMORY5, ec2.InstanceSize_LARGE),
VpcSubnets: &SubnetSelection{
SubnetType: ec2.SubnetType_PUBLIC,
},
Vpc: Vpc,
DeletionProtection: jsii.Boolean(true),
})
Initializer
new DatabaseCluster(scope: Construct, id: string, props: DatabaseClusterProps)
DatabaseCluster(scope: Construct, id: str, props: DatabaseClusterProps)
new DatabaseCluster(Construct scope, String id, DatabaseClusterProps props)
new DatabaseCluster(Construct scope, string id, DatabaseClusterProps props)
NewDatabaseCluster(Scope Construct, Id *string, Props DatabaseClusterProps)
Construct Props
backupoptionalBackupPropsbackupoptionalBackupPropsbackupoptionalBackupPropsBackupoptionalBackupPropsBackupoptionalBackupProps#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.
caCertificateoptionalCaCertificateca_certificateoptionalCaCertificatecaCertificateoptionalCaCertificateCaCertificateoptionalCaCertificateCaCertificateoptionalCaCertificate#Default: DocumentDB will choose a certificate authority
Specifying or updating this property triggers a reboot.
cloudWatchLogsRetentionoptionalRetentionDayscloud_watch_logs_retentionoptionalRetentionDayscloudWatchLogsRetentionoptionalRetentionDaysCloudWatchLogsRetentionoptionalRetentionDaysCloudWatchLogsRetentionoptionalRetentionDays#Default: logs never expire
When updating this property, unsetting it doesn't remove the log retention policy. To remove the retention policy, set the value to Infinity.
cloudWatchLogsRetentionRoleoptionalIRolecloud_watch_logs_retention_roleoptionalIRolecloudWatchLogsRetentionRoleoptionalIRoleCloudWatchLogsRetentionRoleoptionalIRoleCloudWatchLogsRetentionRoleoptionalIRole#Default: a new role is created.
copyTagsToSnapshotoptionalbooleancopy_tags_to_snapshotoptionalboolcopyTagsToSnapshotoptionalBooleanCopyTagsToSnapshotoptionalboolCopyTagsToSnapshotoptional*bool= false#dbClusterNameoptionalstringdb_cluster_nameoptionalstrdbClusterNameoptionalStringDbClusterNameoptionalstringDbClusterNameoptional*string#Default: A name is automatically generated.
deletionProtectionoptionalbooleandeletion_protectionoptionalbooldeletionProtectionoptionalBooleanDeletionProtectionoptionalboolDeletionProtectionoptional*bool= false#If deletionProtection is enabled, the cluster cannot be deleted unless it is modified and deletionProtection is disabled. deletionProtection protects clusters from being accidentally deleted.
enablePerformanceInsightsoptionalbooleanenable_performance_insightsoptionalboolenablePerformanceInsightsoptionalBooleanEnablePerformanceInsightsoptionalboolEnablePerformanceInsightsoptional*bool= false#engineVersionoptionalstringengine_versionoptionalstrengineVersionoptionalStringEngineVersionoptionalstringEngineVersionoptional*string#Default: the latest major version
exportAuditLogsToCloudWatchoptionalbooleanexport_audit_logs_to_cloud_watchoptionalboolexportAuditLogsToCloudWatchoptionalBooleanExportAuditLogsToCloudWatchoptionalboolExportAuditLogsToCloudWatchoptional*bool= false#Note that you also have to configure the audit log export in the Cluster's Parameter Group.
exportProfilerLogsToCloudWatchoptionalbooleanexport_profiler_logs_to_cloud_watchoptionalboolexportProfilerLogsToCloudWatchoptionalBooleanExportProfilerLogsToCloudWatchoptionalboolExportProfilerLogsToCloudWatchoptional*bool= false#Note that you also have to configure the profiler log export in the Cluster's Parameter Group.
instanceIdentifierBaseoptionalstringinstance_identifier_baseoptionalstrinstanceIdentifierBaseoptionalStringInstanceIdentifierBaseoptionalstringInstanceIdentifierBaseoptional*string#Default: dbClusterName is used with the word "Instance" appended. If dbClusterName is not provided, the identifier is automatically generated.
Every replica is named by appending the replica number to this string, 1-based. Only applicable for provisioned clusters.
instanceMaintenanceWindowoptionalstringinstance_maintenance_windowoptionalstrinstanceMaintenanceWindowoptionalStringInstanceMaintenanceWindowoptionalstringInstanceMaintenanceWindowoptional*string#Default: 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.
notes
The cluster-level preferredMaintenanceWindow applies to cluster-wide maintenance events; this prop applies to each auto-created instance independently. To use the same window for both, set this prop to the same value as preferredMaintenanceWindow.
Format: ddd:hh24:mi-ddd:hh24:mi. Must be at least 30 minutes long. Example: 'sat:09:00-sat:09:30'
Only applicable to provisioned clusters; has no effect on serverless clusters because they do not create instances.
instanceRemovalPolicyoptionalRemovalPolicyinstance_removal_policyoptionalRemovalPolicyinstanceRemovalPolicyoptionalRemovalPolicyInstanceRemovalPolicyoptionalRemovalPolicyInstanceRemovalPolicyoptionalRemovalPolicy#Default: RemovalPolicy.DESTROY when removalPolicy is set to SNAPSHOT, removalPolicy otherwise.
Cannot be set to SNAPSHOT.
instancesoptionalnumberinstancesoptionalint | floatinstancesoptionalNumberInstancesoptionaldoubleInstancesoptional*float64= 1#instanceTypeoptionalInstanceTypeinstance_typeoptionalInstanceTypeinstanceTypeoptionalInstanceTypeInstanceTypeoptionalInstanceTypeInstanceTypeoptionalInstanceType= None#Required for provisioned clusters, not applicable for serverless clusters.
Default: default master key.
manageMasterUserPasswordoptionalbooleanmanage_master_user_passwordoptionalboolmanageMasterUserPasswordoptionalBooleanManageMasterUserPasswordoptionalboolManageMasterUserPasswordoptional*bool= false#notes
When set to true, Amazon DocumentDB will automatically generate and manage the master user password in AWS Secrets Manager. This provides enhanced security and automatic password rotation capabilities.
Constraint: You can't manage the master user password with AWS Secrets Manager if masterUser.password is specified.
The secret property of the cluster is not set when using this option. See the module README for how to access the managed secret.
masterUserSecretKmsKeyoptionalIKeymaster_user_secret_kms_keyoptionalIKeymasterUserSecretKmsKeyoptionalIKeyMasterUserSecretKmsKeyoptionalIKeyMasterUserSecretKmsKeyoptionalIKey#Default: default AWS managed key aws/secretsmanager
notes
This setting is valid only if the master user password is managed by Amazon DocumentDB in AWS Secrets Manager for the DB cluster (i.e. when manageMasterUserPassword is true). If you don't specify this property, then the aws/secretsmanager KMS key is used to encrypt the secret.
parameterGroupoptionalIDBClusterParameterGroupRefparameter_groupoptionalIDBClusterParameterGroupRefparameterGroupoptionalIDBClusterParameterGroupRefParameterGroupoptionalIDBClusterParameterGroupRefParameterGroupoptionalIDBClusterParameterGroupRef#Default: no parameter group
portoptionalnumberportoptionalint | floatportoptionalNumberPortoptionaldoublePortoptional*float64= DatabaseCluster.DEFAULT_PORT#preferredMaintenanceWindowoptionalstringpreferred_maintenance_windowoptionalstrpreferredMaintenanceWindowoptionalStringPreferredMaintenanceWindowoptionalstringPreferredMaintenanceWindowoptional*string#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.
Must be at least 30 minutes long.
Example: 'tue:04:17-tue:04:47'
removalPolicyoptionalRemovalPolicyremoval_policyoptionalRemovalPolicyremovalPolicyoptionalRemovalPolicyRemovalPolicyoptionalRemovalPolicyRemovalPolicyoptionalRemovalPolicy#Default: Retain cluster.
notes
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.
securityGroupoptionalISecurityGroupsecurity_groupoptionalISecurityGroupsecurityGroupoptionalISecurityGroupSecurityGroupoptionalISecurityGroupSecurityGroupoptionalISecurityGroup#Default: a new security group is created.
securityGroupRemovalPolicyoptionalRemovalPolicysecurity_group_removal_policyoptionalRemovalPolicysecurityGroupRemovalPolicyoptionalRemovalPolicySecurityGroupRemovalPolicyoptionalRemovalPolicySecurityGroupRemovalPolicyoptionalRemovalPolicy#Default: RemovalPolicy.DESTROY when removalPolicy is set to SNAPSHOT, removalPolicy otherwise.
Cannot be set to SNAPSHOT.
serverlessV2ScalingConfigurationoptionalServerlessV2ScalingConfigurationserverless_v2_scaling_configurationoptionalServerlessV2ScalingConfigurationserverlessV2ScalingConfigurationoptionalServerlessV2ScalingConfigurationServerlessV2ScalingConfigurationoptionalServerlessV2ScalingConfigurationServerlessV2ScalingConfigurationoptionalServerlessV2ScalingConfiguration= None#When specified, the cluster will be created as a serverless cluster.
storageEncryptedoptionalbooleanstorage_encryptedoptionalboolstorageEncryptedoptionalBooleanStorageEncryptedoptionalboolStorageEncryptedoptional*bool= true#storageTypeoptionalStorageTypestorage_typeoptionalStorageTypestorageTypeoptionalStorageTypeStorageTypeoptionalStorageTypeStorageTypeoptionalStorageType= StorageType.STANDARD#I/O-optimized storage is supported starting with engine version 5.0.0.
Must be at least 2 subnets in two different AZs.
vpcSubnetsoptionalSubnetSelectionvpc_subnetsoptionalSubnetSelectionvpcSubnetsoptionalSubnetSelectionVpcSubnetsoptionalSubnetSelectionVpcSubnetsoptionalSubnetSelection#Default: private subnets
Properties
clusterEndpointEndpointcluster_endpointEndpointclusterEndpointEndpointClusterEndpointEndpointClusterEndpointEndpointrequired#clusterIdentifierstringcluster_identifierstrclusterIdentifierStringClusterIdentifierstringClusterIdentifier*stringrequired#clusterReadEndpointEndpointcluster_read_endpointEndpointclusterReadEndpointEndpointClusterReadEndpointEndpointClusterReadEndpointEndpointrequired#clusterResourceIdentifierstringcluster_resource_identifierstrclusterResourceIdentifierStringClusterResourceIdentifierstringClusterResourceIdentifier*stringrequired#for example: cluster-ABCD1234EFGH5678IJKL90MNOP. The cluster ID uniquely identifies the cluster and is used in things like IAM authentication policies.
connectionsConnectionsconnectionsConnectionsconnectionsConnectionsConnectionsConnectionsConnectionsConnectionsrequired#dbClusterRefDBClusterReferencedb_cluster_refDBClusterReferencedbClusterRefDBClusterReferenceDbClusterRefDBClusterReferenceDbClusterRefDBClusterReferencerequired#DEFAULT_NUM_INSTANCESnumberdefault_num_instancesint | floatDEFAULT_NUM_INSTANCESNumberDEFAULT_NUM_INSTANCESdoubleDEFAULT_NUM_INSTANCES*float64requiredstatic#DEFAULT_PORTnumberdefault_portint | floatDEFAULT_PORTNumberDEFAULT_PORTdoubleDEFAULT_PORT*float64requiredstatic#envResourceEnvironmentenvResourceEnvironmentenvResourceEnvironmentEnvResourceEnvironmentEnvResourceEnvironmentrequired#notes
For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.
For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.
instanceEndpointsEndpoint[]instance_endpointstyping.List[Endpoint]instanceEndpointsList<Endpoint>InstanceEndpointsEndpoint[]InstanceEndpoints*[]Endpointrequired#instanceIdentifiersstring[]instance_identifierstyping.List[str]instanceIdentifiersList<String>InstanceIdentifiersstring[]InstanceIdentifiers*[]*stringrequired#PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#secretmay be undefinedISecretsecretmay be undefinedISecretsecretmay be undefinedISecretSecretmay be undefinedISecretSecretmay be undefinedISecret#securityGroupIdstringsecurity_group_idstrsecurityGroupIdStringSecurityGroupIdstringSecurityGroupId*stringrequired#Methods
addRotationMultiUser(id: string, options: RotationMultiUserOptions): SecretRotationdef add_rotation_multi_user(self, id: str, options: RotationMultiUserOptions) -> SecretRotationpublic SecretRotation addRotationMultiUser(String id, RotationMultiUserOptions options)public SecretRotation AddRotationMultiUser(string id, RotationMultiUserOptions options)func AddRotationMultiUser(Id *string, Options RotationMultiUserOptions) SecretRotation#addRotationSingleUser(automaticallyAfter?: Duration): SecretRotationdef add_rotation_single_user(self, automatically_after: typing.Optional[Duration] = None) -> SecretRotationpublic SecretRotation addRotationSingleUser(Duration automaticallyAfter)public SecretRotation AddRotationSingleUser(Duration? automaticallyAfter = null)func AddRotationSingleUser(AutomaticallyAfter Duration) SecretRotation#1 parameter
Parameters
automaticallyAfterautomatically_afterautomaticallyAfterautomaticallyAfterAutomaticallyAfter— Specifies the number of days after the previous rotation before Secrets Manager triggers the next automatic rotation.
addSecurityGroups(...securityGroups: ISecurityGroup[]): voiddef add_security_groups(self, security_groups: ISecurityGroup) -> Nonepublic void addSecurityGroups(ISecurityGroup securityGroups)public void AddSecurityGroups(ISecurityGroup securityGroups)func AddSecurityGroups(SecurityGroups ISecurityGroup)#1 parameter
Parameters
securityGroupssecurity_groupssecurityGroupssecurityGroupsSecurityGroups— The security groups to add.
applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#notes · 1 parameter
When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.
Parameters
strengthstrengthstrengthstrengthStrength— - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#notes
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).
asSecretAttachmentTarget(): SecretAttachmentTargetPropsdef as_secret_attachment_target(self, ) -> SecretAttachmentTargetPropspublic SecretAttachmentTargetProps asSecretAttachmentTarget()public SecretAttachmentTargetProps AsSecretAttachmentTarget()func AsSecretAttachmentTarget() SecretAttachmentTargetProps#fromDatabaseClusterAttributes(scope: Construct, id: string, attrs: DatabaseClusterAttributes): IDatabaseCluster@staticmethod def from_database_cluster_attributes(scope: Construct, id: str, attrs: DatabaseClusterAttributes) -> IDatabaseClusterpublic static IDatabaseCluster fromDatabaseClusterAttributes(Construct scope, String id, DatabaseClusterAttributes attrs)public static IDatabaseCluster FromDatabaseClusterAttributes(Construct scope, string id, DatabaseClusterAttributes attrs)func FromDatabaseClusterAttributes(Scope Construct, Id *string, Attrs DatabaseClusterAttributes) IDatabaseClusterstatic#isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#notes · 1 parameter · returns
Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.
Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.
Parameters
xxxxX— Any object.
Returns: true if x is an object created from a class which extends Construct.
isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.