DatabaseCluster
- class aws_cdk.aws_docdb.DatabaseCluster(scope, id, *, instance_type, master_user, vpc, backup=None, cloud_watch_logs_retention=None, cloud_watch_logs_retention_role=None, db_cluster_name=None, deletion_protection=None, engine_version=None, export_audit_logs_to_cloud_watch=None, export_profiler_logs_to_cloud_watch=None, instance_identifier_base=None, instances=None, kms_key=None, parameter_group=None, port=None, preferred_maintenance_window=None, removal_policy=None, security_group=None, storage_encrypted=None, vpc_subnets=None)
Bases:
Resource
Create a clustered database with a given number of instances.
- Resource:
AWS::DocDB::DBCluster
- ExampleMetadata:
infused
Example:
# vpc: ec2.Vpc cluster = docdb.DatabaseCluster(self, "Database", master_user=docdb.Login( username="myuser", # NOTE: 'admin' is reserved by DocumentDB exclude_characters=""@/:", # optional, defaults to the set ""@/" and is also used for eventually created rotations secret_name="/myapp/mydocdb/masteruser" ), instance_type=ec2.InstanceType.of(ec2.InstanceClass.R5, ec2.InstanceSize.LARGE), vpc_subnets=ec2.SubnetSelection( subnet_type=ec2.SubnetType.PUBLIC ), vpc=vpc )
- Parameters:
scope (
Construct
)id (
str
)instance_type (
InstanceType
) – What type of instance to start for the replicas.master_user (
Union
[Login
,Dict
[str
,Any
]]) – Username and password for the administrative user.vpc (
IVpc
) – What subnets to run the DocumentDB instances in. Must be at least 2 subnets in two different AZs.backup (
Union
[BackupProps
,Dict
[str
,Any
],None
]) – 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.cloud_watch_logs_retention (
Optional
[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 toInfinity
. Default: - logs never expirecloud_watch_logs_retention_role (
Optional
[IRole
]) – The IAM role for the Lambda function associated with the custom resource that sets the retention policy. Default: - a new role is created.db_cluster_name (
Optional
[str
]) – An optional identifier for the cluster. Default: - A name is automatically generated.deletion_protection (
Optional
[bool
]) – 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: - falseengine_version (
Optional
[str
]) – What version of the database to start. Default: - The default engine version.export_audit_logs_to_cloud_watch (
Optional
[bool
]) – 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: falseexport_profiler_logs_to_cloud_watch (
Optional
[bool
]) – 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: falseinstance_identifier_base (
Optional
[str
]) – Base identifier for instances. Every replica is named by appending the replica number to this string, 1-based. Default: -dbClusterName
is used with the word “Instance” appended. IfdbClusterName
is not provided, the identifier is automatically generated.instances (
Union
[int
,float
,None
]) – Number of DocDB compute instances. Default: 1kms_key (
Optional
[IKey
]) – The KMS key for storage encryption. Default: - default master key.parameter_group (
Optional
[IClusterParameterGroup
]) – The DB parameter group to associate with the instance. Default: no parameter groupport (
Union
[int
,float
,None
]) – The port the DocumentDB cluster will listen on. Default: DatabaseCluster.DEFAULT_PORTpreferred_maintenance_window (
Optional
[str
]) – 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.removal_policy (
Optional
[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. Default: - Retain cluster.security_group (
Optional
[ISecurityGroup
]) – Security group. Default: a new security group is created.storage_encrypted (
Optional
[bool
]) – Whether to enable storage encryption. Default: truevpc_subnets (
Union
[SubnetSelection
,Dict
[str
,Any
],None
]) – Where to place the instances within the VPC. Default: private subnets
Methods
- add_rotation_multi_user(id, *, secret, automatically_after=None)
Adds the multi user rotation to this cluster.
- Parameters:
id (
str
)secret (
ISecret
) – The secret to rotate. It must be a JSON string with the following format:: { “engine”: <required: must be set to ‘mongo’>, “host”: <required: instance host name>, “username”: <required: username>, “password”: <required: password>, “dbname”: <optional: database name>, “port”: <optional: if not specified, default port 27017 will be used>, “masterarn”: <required: the arn of the master secret which will be used to create users/change passwords> “ssl”: <optional: if not specified, defaults to false. This must be true if being used for DocumentDB rotations where the cluster has TLS enabled> }automatically_after (
Optional
[Duration
]) – Specifies the number of days after the previous rotation before Secrets Manager triggers the next automatic rotation. Default: Duration.days(30)
- Return type:
- add_rotation_single_user(automatically_after=None)
Adds the single user rotation of the master password to this cluster.
- Parameters:
automatically_after (
Optional
[Duration
]) – Specifies the number of days after the previous rotation before Secrets Manager triggers the next automatic rotation.- Return type:
- add_security_groups(*security_groups)
Adds security groups to this cluster.
- Parameters:
security_groups (
ISecurityGroup
) – The security groups to add.- Return type:
None
- apply_removal_policy(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
).- Parameters:
policy (
RemovalPolicy
)- Return type:
None
- as_secret_attachment_target()
Renders the secret attachment target specifications.
- Return type:
- to_string()
Returns a string representation of this construct.
- Return type:
str
Attributes
- DEFAULT_NUM_INSTANCES = 1
- DEFAULT_PORT = 27017
- cluster_endpoint
The endpoint to use for read/write operations.
- cluster_identifier
Identifier of the cluster.
- cluster_read_endpoint
Endpoint to use for load-balanced read-only operations.
- cluster_resource_identifier
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.
- Attribute:
ClusterResourceId
- connections
The connections object to implement IConnectable.
- env
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.
- instance_endpoints
Endpoints which address each individual replica.
- instance_identifiers
Identifiers of the replicas.
- node
The construct tree node associated with this construct.
- secret
The secret attached to this cluster.
- security_group_id
Security group identifier of this database.
- stack
The stack in which this resource is defined.
Static Methods
- classmethod from_database_cluster_attributes(scope, id, *, cluster_identifier, cluster_endpoint_address=None, instance_endpoint_addresses=None, instance_identifiers=None, port=None, reader_endpoint_address=None, security_group=None)
Import an existing DatabaseCluster from properties.
- Parameters:
scope (
Construct
)id (
str
)cluster_identifier (
str
) – Identifier for the cluster.cluster_endpoint_address (
Optional
[str
]) – Cluster endpoint address. Default: - no cluster endpoint addressinstance_endpoint_addresses (
Optional
[Sequence
[str
]]) – Endpoint addresses of individual instances. Default: - no instance endpoint addressesinstance_identifiers (
Optional
[Sequence
[str
]]) – Identifier for the instances. Default: - no instance identifiersport (
Union
[int
,float
,None
]) – The database port. Default: - nonereader_endpoint_address (
Optional
[str
]) – Reader endpoint address. Default: - no reader endpoint addresssecurity_group (
Optional
[ISecurityGroup
]) – The security group of the database cluster. Default: - no security groups
- Return type:
- classmethod is_construct(x)
Return whether the given object is a Construct.
- Parameters:
x (
Any
)- Return type:
bool
- classmethod is_resource(construct)
Check whether the given construct is a Resource.
- Parameters:
construct (
IConstruct
)- Return type:
bool