| Interface | Description |
|---|---|
| BackupProps |
(experimental) Backup configuration for DocumentDB databases.
|
| CfnDBClusterParameterGroupProps |
Properties for defining a `CfnDBClusterParameterGroup`.
|
| CfnDBClusterProps |
Properties for defining a `CfnDBCluster`.
|
| CfnDBInstanceProps |
Properties for defining a `CfnDBInstance`.
|
| CfnDBSubnetGroupProps |
Properties for defining a `CfnDBSubnetGroup`.
|
| ClusterParameterGroupProps |
(experimental) Properties for a cluster parameter group.
|
| DatabaseClusterAttributes |
(experimental) Properties that describe an existing cluster instance.
|
| DatabaseClusterProps |
(experimental) Properties for a new database cluster.
|
| DatabaseInstanceAttributes |
(experimental) Properties that describe an existing instance.
|
| DatabaseInstanceProps |
(experimental) Construction properties for a DatabaseInstanceNew.
|
| DatabaseSecretProps |
(experimental) Construction properties for a DatabaseSecret.
|
| IClusterParameterGroup |
(experimental) A parameter group.
|
| IClusterParameterGroup.Jsii$Default |
Internal default implementation for
IClusterParameterGroup. |
| IDatabaseCluster |
(experimental) Create a clustered database with a given number of instances.
|
| IDatabaseCluster.Jsii$Default |
Internal default implementation for
IDatabaseCluster. |
| IDatabaseInstance |
(experimental) A database instance.
|
| IDatabaseInstance.Jsii$Default |
Internal default implementation for
IDatabaseInstance. |
| Login |
(experimental) Login credentials for a database cluster.
|
| RotationMultiUserOptions |
(experimental) Options to add the multi user rotation.
|
To set up a clustered DocumentDB database, define a DatabaseCluster. You must
always launch a database in a VPC. Use the vpcSubnets attribute to control whether
your instances will be launched privately or publicly:
// Example automatically generated from non-compiling source. May contain errors.
Object cluster = DatabaseCluster.Builder.create(this, "Database")
.masterUser(Map.of(
"username", "myuser", // NOTE: 'admin' is reserved by DocumentDB
"excludeCharacters", "\"@/:", // optional, defaults to the set "\"@/" and is also used for eventually created rotations
"secretName", "/myapp/mydocdb/masteruser"))
.instanceType(ec2.InstanceType.of(ec2.getInstanceClass().getR5(), ec2.getInstanceSize().getLARGE()))
.vpcSubnets(Map.of(
"subnetType", ec2.getSubnetType().getPUBLIC()))
.vpc(vpc)
.build();
By default, the master password will be generated and stored in AWS Secrets Manager with auto-generated description.
Your cluster will be empty by default.
To control who can access the cluster, use the .connections attribute. DocumentDB databases have a default port, so
you don't need to specify the port:
// Example automatically generated from non-compiling source. May contain errors.
cluster.connections.allowDefaultPortFromAnyIpv4("Open to the world");
The endpoints to access your database cluster will be available as the .clusterEndpoint and .clusterReadEndpoint
attributes:
// Example automatically generated from non-compiling source. May contain errors. Object writeAddress = cluster.getClusterEndpoint().getSocketAddress();
If you have existing security groups you would like to add to the cluster, use the addSecurityGroups method. Security
groups added in this way will not be managed by the Connections object of the cluster.
// Example automatically generated from non-compiling source. May contain errors.
Object securityGroup = SecurityGroup.Builder.create(stack, "SecurityGroup")
.vpc(vpc)
.build();
cluster.addSecurityGroups(securityGroup);
Deletion protection can be enabled on an Amazon DocumentDB cluster to prevent accidental deletion of the cluster:
// Example automatically generated from non-compiling source. May contain errors.
Object cluster = DatabaseCluster.Builder.create(this, "Database")
.masterUser(Map.of(
"username", "myuser"))
.instanceType(ec2.InstanceType.of(ec2.getInstanceClass().getR5(), ec2.getInstanceSize().getLARGE()))
.vpcSubnets(Map.of(
"subnetType", ec2.getSubnetType().getPUBLIC()))
.vpc(vpc)
.deletionProtection(true)
.build();
When the master password is generated and stored in AWS Secrets Manager, it can be rotated automatically:
// Example automatically generated from non-compiling source. May contain errors. cluster.addRotationSingleUser();
example of setting up master password rotation for a cluster
The multi user rotation scheme is also available:
// Example automatically generated from non-compiling source. May contain errors.
cluster.addRotationMultiUser("MyUser", Map.of(
"secret", myImportedSecret));
It's also possible to create user credentials together with the cluster and add rotation:
// Example automatically generated from non-compiling source. May contain errors.
Object myUserSecret = DatabaseSecret.Builder.create(this, "MyUserSecret")
.username("myuser")
.masterSecret(cluster.getSecret())
.build();
Object myUserSecretAttached = myUserSecret.attach(cluster); // Adds DB connections information in the secret
cluster.addRotationMultiUser("MyUser", Map.of( // Add rotation using the multi user scheme
"secret", myUserSecretAttached));
Note: This user must be created manually in the database using the master credentials. The rotation will start as soon as this user exists.
See also @aws-cdk/aws-secretsmanager for credentials rotation of existing clusters.
Sending audit or profiler needs to be configured in two places:
DatabaseCluster:
// Example automatically generated from non-compiling source. May contain errors.
Object cluster = DatabaseCluster.Builder.create(this, "Database")...
.exportProfilerLogsToCloudWatch(true) // Enable sending profiler logs
.exportAuditLogsToCloudWatch(true) // Enable sending audit logs
.cloudWatchLogsRetention(logs.getRetentionDays().getTHREE_MONTHS()) // Optional - default is to never expire logs
.cloudWatchLogsRetentionRole(myLogsPublishingRole)
.build();
Copyright © 2022. All rights reserved.