Skip to content
GitHubXDiscordRSS

DBCluster

Learn how to create, update, and manage AWS DocDB DBClusters using Alchemy Cloud Control.

The DBCluster resource allows you to create and manage AWS DocumentDB (with MongoDB compatibility) DBClusters, providing a scalable and highly available database solution.

Create a basic DBCluster with required properties and a common optional setting for storage encryption.

import AWS from "alchemy/aws/control";
const docDBCluster = await AWS.DocDB.DBCluster("myDocDBCluster", {
DBClusterIdentifier: "my-docdb-cluster",
MasterUsername: "adminUser",
MasterUserPassword: "securePassword123!",
StorageEncrypted: true,
VpcSecurityGroupIds: ["sg-0123456789abcdef0"],
DBSubnetGroupName: "my-docdb-subnet-group"
});

Configure a DBCluster with advanced settings such as backup retention period and maintenance windows.

const advancedDocDBCluster = await AWS.DocDB.DBCluster("advancedDocDBCluster", {
DBClusterIdentifier: "advanced-docdb-cluster",
MasterUsername: "adminUser",
MasterUserPassword: "anotherSecurePassword456!",
StorageEncrypted: true,
BackupRetentionPeriod: 7,
PreferredBackupWindow: "03:00-03:30",
PreferredMaintenanceWindow: "sun:05:00-sun:05:30",
VpcSecurityGroupIds: ["sg-0123456789abcdef0"],
DBSubnetGroupName: "my-docdb-subnet-group"
});

This example demonstrates how to restore a DBCluster from a snapshot.

const restoredDocDBCluster = await AWS.DocDB.DBCluster("restoredDocDBCluster", {
DBClusterIdentifier: "restored-docdb-cluster",
SnapshotIdentifier: "my-snapshot-id",
VpcSecurityGroupIds: ["sg-0123456789abcdef0"],
DBSubnetGroupName: "my-docdb-subnet-group"
});

Create a DBCluster using serverless V2 scaling configuration for optimal resource management.

const serverlessDocDBCluster = await AWS.DocDB.DBCluster("serverlessDocDBCluster", {
DBClusterIdentifier: "serverless-docdb-cluster",
MasterUsername: "adminUser",
MasterUserPassword: "securePassword789!",
ServerlessV2ScalingConfiguration: {
MinCapacity: 2,
MaxCapacity: 8
},
VpcSecurityGroupIds: ["sg-0123456789abcdef0"],
DBSubnetGroupName: "my-docdb-subnet-group"
});