class DatabaseCluster (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.RDS.DatabaseCluster |
Java | software.amazon.awscdk.services.rds.DatabaseCluster |
Python | aws_cdk.aws_rds.DatabaseCluster |
TypeScript (source) | @aws-cdk/aws-rds » DatabaseCluster |
Implements
IConstruct
, IConstruct
, IDependable
, IResource
, IDatabase
, IConnectable
, ISecret
Create a clustered database with a given number of instances.
Example
declare const vpc: ec2.Vpc;
const cluster = new rds.DatabaseCluster(this, 'Database', {
engine: rds.DatabaseClusterEngine.AURORA,
instanceProps: { vpc },
});
const proxy = new rds.DatabaseProxy(this, 'Proxy', {
proxyTarget: rds.ProxyTarget.fromCluster(cluster),
secrets: [cluster.secret!],
vpc,
});
const role = new iam.Role(this, 'DBProxyRole', { assumedBy: new iam.AccountPrincipal(this.account) });
proxy.grantConnect(role, 'admin'); // Grant the role connection access to the DB Proxy for database user 'admin'.
Initializer
new DatabaseCluster(scope: Construct, id: string, props: DatabaseClusterProps)
Parameters
- scope
Construct
- id
string
- props
Database
Cluster Props
Construct Props
Name | Type | Description |
---|---|---|
engine | ICluster | What kind of database to start. |
instance | Instance | Settings for the individual instances that are launched. |
backtrack | Duration | The number of seconds to set a cluster's target backtrack window to. |
backup? | Backup | Backup settings. |
cloudwatch | string[] | The list of log types that need to be enabled for exporting to CloudWatch Logs. |
cloudwatch | Retention | The number of days log events are kept in CloudWatch Logs. |
cloudwatch | IRole | The IAM role for the Lambda function associated with the custom resource that sets the retention policy. |
cluster | string | An optional identifier for the cluster. |
copy | boolean | Whether to copy tags to the snapshot when a snapshot is created. |
credentials? | Credentials | Credentials for the administrative user. |
default | string | Name of a database which is automatically created inside the cluster. |
deletion | boolean | Indicates whether the DB cluster should have deletion protection enabled. |
iam | boolean | Whether to enable mapping of AWS Identity and Access Management (IAM) accounts to database accounts. |
instance | string | Base identifier for instances. |
instances? | number | How many replicas/instances to create. |
monitoring | Duration | The interval, in seconds, between points when Amazon RDS collects enhanced monitoring metrics for the DB instances. |
monitoring | IRole | Role that will be used to manage DB instances monitoring. |
parameter | IParameter | Additional parameters to pass to the database engine. |
parameters? | { [string]: string } | The parameters in the DBClusterParameterGroup to create automatically. |
port? | number | What port to listen on. |
preferred | string | A preferred maintenance window day/time range. Should be specified as a range ddd:hh24:mi-ddd:hh24:mi (24H Clock UTC). |
removal | Removal | The removal policy to apply when the cluster and its instances are removed from the stack or replaced during an update. |
s3 | IBucket [] | S3 buckets that you want to load data into. This feature is only supported by the Aurora database engine. |
s3 | IRole | Role that will be associated with this DB cluster to enable S3 export. |
s3 | IBucket [] | S3 buckets that you want to load data from. This feature is only supported by the Aurora database engine. |
s3 | IRole | Role that will be associated with this DB cluster to enable S3 import. |
storage | boolean | Whether to enable storage encryption. |
storage | IKey | The KMS key for storage encryption. |
subnet | ISubnet | Existing subnet group for the cluster. |
engine
Type:
ICluster
What kind of database to start.
instanceProps
Type:
Instance
Settings for the individual instances that are launched.
backtrackWindow?
Type:
Duration
(optional, default: 0 seconds (no backtrack))
The number of seconds to set a cluster's target backtrack window to.
This feature is only supported by the Aurora MySQL database engine and cannot be enabled on existing clusters.
See also: https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Managing.Backtrack.html
backup?
Type:
Backup
(optional, 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.)
Backup settings.
cloudwatchLogsExports?
Type:
string[]
(optional, default: no log exports)
The list of log types that need to be enabled for exporting to CloudWatch Logs.
cloudwatchLogsRetention?
Type:
Retention
(optional, default: logs never expire)
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 to Infinity
.
cloudwatchLogsRetentionRole?
Type:
IRole
(optional, default: a new role is created.)
The IAM role for the Lambda function associated with the custom resource that sets the retention policy.
clusterIdentifier?
Type:
string
(optional, default: A name is automatically generated.)
An optional identifier for the cluster.
copyTagsToSnapshot?
Type:
boolean
(optional, default: true)
Whether to copy tags to the snapshot when a snapshot is created.
credentials?
Type:
Credentials
(optional, default: A username of 'admin' (or 'postgres' for PostgreSQL) and SecretsManager-generated password)
Credentials for the administrative user.
defaultDatabaseName?
Type:
string
(optional, default: Database is not created in cluster.)
Name of a database which is automatically created inside the cluster.
deletionProtection?
Type:
boolean
(optional, default: true if removalPolicy
is RETAIN, false otherwise)
Indicates whether the DB cluster should have deletion protection enabled.
iamAuthentication?
Type:
boolean
(optional, default: false)
Whether to enable mapping of AWS Identity and Access Management (IAM) accounts to database accounts.
instanceIdentifierBase?
Type:
string
(optional, default: clusterIdentifier is used with the word "Instance" appended.
If clusterIdentifier is not provided, the identifier is automatically generated.)
Base identifier for instances.
Every replica is named by appending the replica number to this string, 1-based.
instances?
Type:
number
(optional, default: 2)
How many replicas/instances to create.
Has to be at least 1.
monitoringInterval?
Type:
Duration
(optional, default: no enhanced monitoring)
The interval, in seconds, between points when Amazon RDS collects enhanced monitoring metrics for the DB instances.
monitoringRole?
Type:
IRole
(optional, default: A role is automatically created for you)
Role that will be used to manage DB instances monitoring.
parameterGroup?
Type:
IParameter
(optional, default: No parameter group.)
Additional parameters to pass to the database engine.
parameters?
Type:
{ [string]: string }
(optional, default: None)
The parameters in the DBClusterParameterGroup to create automatically.
You can only specify parameterGroup or parameters but not both. You need to use a versioned engine to auto-generate a DBClusterParameterGroup.
port?
Type:
number
(optional, default: The default for the engine is used.)
What port to listen on.
preferredMaintenanceWindow?
Type:
string
(optional, 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.)
A preferred maintenance window day/time range. Should be specified as a range ddd:hh24:mi-ddd:hh24:mi (24H Clock UTC).
Example: 'Sun:23:45-Mon:00:15'
removalPolicy?
Type:
Removal
(optional, default: RemovalPolicy.SNAPSHOT (remove the cluster and instances, but retain a snapshot of the data))
The removal policy to apply when the cluster and its instances are removed from the stack or replaced during an update.
s3ExportBuckets?
Type:
IBucket
[]
(optional, default: None)
S3 buckets that you want to load data into. This feature is only supported by the Aurora database engine.
This property must not be used if s3ExportRole
is used.
For MySQL:
See also: https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/postgresql-s3-export.html
s3ExportRole?
Type:
IRole
(optional, default: New role is created if s3ExportBuckets
is set, no role is defined otherwise)
Role that will be associated with this DB cluster to enable S3 export.
This feature is only supported by the Aurora database engine.
This property must not be used if s3ExportBuckets
is used.
For MySQL:
See also: https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/postgresql-s3-export.html
s3ImportBuckets?
Type:
IBucket
[]
(optional, default: None)
S3 buckets that you want to load data from. This feature is only supported by the Aurora database engine.
This property must not be used if s3ImportRole
is used.
For MySQL:
See also: https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraPostgreSQL.Migrating.html
s3ImportRole?
Type:
IRole
(optional, default: New role is created if s3ImportBuckets
is set, no role is defined otherwise)
Role that will be associated with this DB cluster to enable S3 import.
This feature is only supported by the Aurora database engine.
This property must not be used if s3ImportBuckets
is used.
For MySQL:
See also: https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraPostgreSQL.Migrating.html
storageEncrypted?
Type:
boolean
(optional, default: true if storageEncryptionKey is provided, false otherwise)
Whether to enable storage encryption.
storageEncryptionKey?
Type:
IKey
(optional, default: if storageEncrypted is true then the default master key, no key otherwise)
The KMS key for storage encryption.
If specified, {@link storageEncrypted} will be set to true
.
subnetGroup?
Type:
ISubnet
(optional, default: a new subnet group will be created.)
Existing subnet group for the cluster.
Properties
Name | Type | Description |
---|---|---|
cluster | Endpoint | The endpoint to use for read/write operations. |
cluster | string | Identifier of the cluster. |
cluster | Endpoint | Endpoint to use for load-balanced read-only operations. |
connections | Connections | Access to the network connections. |
env | Resource | The environment this resource belongs to. |
instance | Endpoint [] | Endpoints which address each individual replica. |
instance | string[] | Identifiers of the replicas. |
multi | Secret | Application for multi user rotation to this cluster. |
new | Cfn | |
node | Construct | The construct tree node associated with this construct. |
security | ISecurity [] | |
single | Secret | Application for single user rotation of the master password to this cluster. |
stack | Stack | The stack in which this resource is defined. |
subnet | ISubnet | |
vpc | IVpc | The VPC network to place the cluster in. |
engine? | ICluster | The engine for this Cluster. |
secret? | ISecret | The secret attached to this cluster. |
vpc | Subnet | The cluster's subnets. |
clusterEndpoint
Type:
Endpoint
The endpoint to use for read/write operations.
clusterIdentifier
Type:
string
Identifier of the cluster.
clusterReadEndpoint
Type:
Endpoint
Endpoint to use for load-balanced read-only operations.
connections
Type:
Connections
Access to the network connections.
env
Type:
Resource
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.
instanceEndpoints
Type:
Endpoint
[]
Endpoints which address each individual replica.
instanceIdentifiers
Type:
string[]
Identifiers of the replicas.
multiUserRotationApplication
Type:
Secret
Application for multi user rotation to this cluster.
newCfnProps
Type:
Cfn
node
Type:
Construct
The construct tree node associated with this construct.
securityGroups
Type:
ISecurity
[]
singleUserRotationApplication
Type:
Secret
Application for single user rotation of the master password to this cluster.
stack
Type:
Stack
The stack in which this resource is defined.
subnetGroup
Type:
ISubnet
vpc
Type:
IVpc
The VPC network to place the cluster in.
engine?
Type:
ICluster
(optional)
The engine for this Cluster.
Never undefined.
secret?
Type:
ISecret
(optional)
The secret attached to this cluster.
vpcSubnets?
Type:
Subnet
(optional)
The cluster's subnets.
Methods
Name | Description |
---|---|
add | Add a new db proxy to this cluster. |
add | Adds the multi user rotation to this cluster. |
add | Adds the single user rotation of the master password to this cluster. |
apply | Apply the given removal policy to this resource. |
as | Renders the secret attachment target specifications. |
metric(metricName, props?) | Return the given named metric for this DBCluster. |
metric | The percentage of CPU utilization. |
metric | The number of database connections in use. |
metric | The average number of deadlocks in the database per second. |
metric | The amount of time that the instance has been running, in seconds. |
metric | The amount of local storage available, in bytes. |
metric | The amount of available random access memory, in bytes. |
metric | The amount of network throughput received from clients by each instance, in bytes per second. |
metric | The amount of network throughput both received from and transmitted to clients by each instance, in bytes per second. |
metric | The amount of network throughput sent to clients by each instance, in bytes per second. |
metric | The total amount of backup storage in bytes consumed by all Aurora snapshots outside its backup retention window. |
metric | The total amount of backup storage in bytes for which you are billed. |
metric | The amount of storage used by your Aurora DB instance, in bytes. |
metric | The number of billed read I/O operations from a cluster volume, reported at 5-minute intervals. |
metric | The number of write disk I/O operations to the cluster volume, reported at 5-minute intervals. |
to | Returns a string representation of this construct. |
static from | Import an existing DatabaseCluster from properties. |
Proxy(id, options)
addpublic addProxy(id: string, options: DatabaseProxyOptions): DatabaseProxy
Parameters
- id
string
- options
Database
Proxy Options
Returns
Add a new db proxy to this cluster.
RotationMultiUser(id, options)
addpublic addRotationMultiUser(id: string, options: RotationMultiUserOptions): SecretRotation
Parameters
- id
string
- options
Rotation
Multi User Options
Returns
Adds the multi user rotation to this cluster.
RotationSingleUser(options?)
addpublic addRotationSingleUser(options?: RotationSingleUserOptions): SecretRotation
Parameters
- options
Rotation
Single User Options
Returns
Adds the single user rotation of the master password to this cluster.
RemovalPolicy(policy)
applypublic applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
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
).
SecretAttachmentTarget()
aspublic asSecretAttachmentTarget(): SecretAttachmentTargetProps
Returns
Renders the secret attachment target specifications.
metric(metricName, props?)
public metric(metricName: string, props?: MetricOptions): Metric
Parameters
- metricName
string
- props
Metric
Options
Returns
Return the given named metric for this DBCluster.
CPUUtilization(props?)
metricpublic metricCPUUtilization(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The percentage of CPU utilization.
Average over 5 minutes
DatabaseConnections(props?)
metricpublic metricDatabaseConnections(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The number of database connections in use.
Average over 5 minutes
Deadlocks(props?)
metricpublic metricDeadlocks(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The average number of deadlocks in the database per second.
Average over 5 minutes
EngineUptime(props?)
metricpublic metricEngineUptime(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The amount of time that the instance has been running, in seconds.
Average over 5 minutes
FreeLocalStorage(props?)
metricpublic metricFreeLocalStorage(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The amount of local storage available, in bytes.
Average over 5 minutes
FreeableMemory(props?)
metricpublic metricFreeableMemory(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The amount of available random access memory, in bytes.
Average over 5 minutes
NetworkReceiveThroughput(props?)
metricpublic metricNetworkReceiveThroughput(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The amount of network throughput received from clients by each instance, in bytes per second.
Average over 5 minutes
NetworkThroughput(props?)
metricpublic metricNetworkThroughput(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The amount of network throughput both received from and transmitted to clients by each instance, in bytes per second.
Average over 5 minutes
NetworkTransmitThroughput(props?)
metricpublic metricNetworkTransmitThroughput(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The amount of network throughput sent to clients by each instance, in bytes per second.
Average over 5 minutes
SnapshotStorageUsed(props?)
metricpublic metricSnapshotStorageUsed(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The total amount of backup storage in bytes consumed by all Aurora snapshots outside its backup retention window.
Average over 5 minutes
TotalBackupStorageBilled(props?)
metricpublic metricTotalBackupStorageBilled(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The total amount of backup storage in bytes for which you are billed.
Average over 5 minutes
VolumeBytesUsed(props?)
metricpublic metricVolumeBytesUsed(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The amount of storage used by your Aurora DB instance, in bytes.
Average over 5 minutes
VolumeReadIOPs(props?)
metricpublic metricVolumeReadIOPs(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The number of billed read I/O operations from a cluster volume, reported at 5-minute intervals.
Average over 5 minutes
VolumeWriteIOPs(props?)
metricpublic metricVolumeWriteIOPs(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The number of write disk I/O operations to the cluster volume, reported at 5-minute intervals.
Average over 5 minutes
String()
topublic toString(): string
Returns
string
Returns a string representation of this construct.
DatabaseClusterAttributes(scope, id, attrs)
static frompublic static fromDatabaseClusterAttributes(scope: Construct, id: string, attrs: DatabaseClusterAttributes): IDatabaseCluster
Parameters
- scope
Construct
- id
string
- attrs
Database
Cluster Attributes
Returns
Import an existing DatabaseCluster from properties.