DBCluster
The DBCluster resource allows you to create and manage AWS DocumentDB (with MongoDB compatibility) DBClusters, providing a scalable and highly available database solution.
Minimal Example
Section titled “Minimal Example”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"});
Advanced Configuration
Section titled “Advanced Configuration”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"});
Restoring from Snapshot
Section titled “Restoring from Snapshot”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"});
Using Serverless Configuration
Section titled “Using Serverless Configuration”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"});