AWSCDK::RDS

162 types

Amazon Relational Database Service Construct Library

require 'aws-cdk-lib'

Starting a clustered database

To set up a clustered database (like Aurora), define a DatabaseCluster. You must always launch a database in a VPC. Use the vpc_subnets attribute to control whether your instances will be launched privately or publicly:

You must specify the instance to use as the writer, along with an optional list of readers (up to 15).

vpc = nil # AWSCDK::EC2::VPC

cluster = AWSCDK::RDS::DatabaseCluster.new(self, "Database", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_mysql({version: AWSCDK::RDS::AuroraMysqlEngineVersion.VER_3_01_0}),
    credentials: AWSCDK::RDS::Credentials.from_generated_secret("clusteradmin"),
     # Optional - will default to 'admin' username and generated password
    writer: AWSCDK::RDS::ClusterInstance.provisioned("writer", {
        publicly_accessible: false,
    }),
    readers: [
        AWSCDK::RDS::ClusterInstance.provisioned("reader1", {promotion_tier: 1}),
        AWSCDK::RDS::ClusterInstance.serverless_v2("reader2"),
    ],
    vpc_subnets: {
        subnet_type: AWSCDK::EC2::SubnetType::PRIVATE_WITH_EGRESS,
    },
    vpc: vpc,
})

To adopt Aurora I/O-Optimized, specify DBClusterStorageType.AURORA_IOPT1 on the storage_type property.

vpc = nil # AWSCDK::EC2::VPC

cluster = AWSCDK::RDS::DatabaseCluster.new(self, "Database", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_postgres({version: AWSCDK::RDS::AuroraPostgresEngineVersion.VER_15_2}),
    credentials: AWSCDK::RDS::Credentials.from_username("adminuser", {password: AWSCDK::SecretValue.unsafe_plain_text("7959866cacc02c2d243ecfe177464fe6")}),
    writer: AWSCDK::RDS::ClusterInstance.provisioned("writer", {
        publicly_accessible: false,
    }),
    readers: [
        AWSCDK::RDS::ClusterInstance.provisioned("reader"),
    ],
    storage_type: AWSCDK::RDS::DBClusterStorageType::AURORA_IOPT1,
    vpc_subnets: {
        subnet_type: AWSCDK::EC2::SubnetType::PRIVATE_WITH_EGRESS,
    },
    vpc: vpc,
})

If there isn't a constant for the exact version you want to use, all of the Version classes have a static of method that can be used to create an arbitrary version.

custom_engine_version = AWSCDK::RDS::AuroraMysqlEngineVersion.of("5.7.mysql_aurora.2.08.1")

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 add a default database upon construction, specify the default_database_name attribute.

When you create a DB instance in your cluster, Aurora automatically chooses an appropriate AZ for that instance if you don't specify an AZ. You can place each instance in fixed availability zone by specifying availability_zone property. For details, see Regions and Availability Zones.

vpc = nil # AWSCDK::EC2::VPC

cluster = AWSCDK::RDS::DatabaseCluster.new(self, "Database", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_mysql({version: AWSCDK::RDS::AuroraMysqlEngineVersion.VER_3_02_1}),
    writer: AWSCDK::RDS::ClusterInstance.provisioned("writer", {
        availability_zone: "us-east-1a",
    }),
    vpc: vpc,
})

To use dual-stack mode, specify NetworkType.DUAL on the network_type property:

vpc = nil # AWSCDK::EC2::VPC
# VPC and subnets must have IPv6 CIDR blocks
cluster = AWSCDK::RDS::DatabaseCluster.new(self, "Database", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_mysql({version: AWSCDK::RDS::AuroraMysqlEngineVersion.VER_3_02_1}),
    writer: AWSCDK::RDS::ClusterInstance.provisioned("writer", {
        publicly_accessible: false,
    }),
    vpc: vpc,
    network_type: AWSCDK::RDS::NetworkType::DUAL,
})

For more information about dual-stack mode, see Working with a DB cluster in a VPC.

If you want to issue read/write transactions directly on an Aurora Replica, you can use local write forwarding on Aurora MySQL and Aurora PostgreSQL. Local write forwarding allows read replicas to accept write transactions and forward them to the writer DB instance to be committed.

To enable local write forwarding, set the enable_local_write_forwarding property to true:

vpc = nil # AWSCDK::EC2::IVPC


AWSCDK::RDS::DatabaseCluster.new(self, "DatabaseCluster", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_mysql({version: AWSCDK::RDS::AuroraMysqlEngineVersion.VER_3_07_0}),
    writer: AWSCDK::RDS::ClusterInstance.serverless_v2("writerInstance"),
    readers: [
        AWSCDK::RDS::ClusterInstance.serverless_v2("readerInstance1"),
    ],
    vpc: vpc,
    enable_local_write_forwarding: true,
})

Note: Local write forwarding is supported only for Aurora MySQL 3.04 or higher, and for Aurora PostgreSQL 16.4 or higher (for version 16), 15.8 or higher (for version 15), and 14.13 or higher (for version 14).

Use DatabaseClusterFromSnapshot to create a cluster from a snapshot:

vpc = nil # AWSCDK::EC2::VPC

AWSCDK::RDS::DatabaseClusterFromSnapshot.new(self, "Database", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora({version: AWSCDK::RDS::AuroraEngineVersion.VER_1_22_2}),
    writer: AWSCDK::RDS::ClusterInstance.provisioned("writer"),
    vpc: vpc,
    snapshot_identifier: "mySnapshot",
})

By default, automatic minor version upgrades for the engine type are enabled in a cluster, but you can also disable this. To do so, set auto_minor_version_upgrade to false.

vpc = nil # AWSCDK::EC2::IVPC


AWSCDK::RDS::DatabaseCluster.new(self, "DatabaseCluster", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_mysql({version: AWSCDK::RDS::AuroraMysqlEngineVersion.VER_3_07_0}),
    writer: AWSCDK::RDS::ClusterInstance.serverless_v2("writerInstance"),
    vpc: vpc,
    auto_minor_version_upgrade: false,
})

Updating the database instances in a cluster

Database cluster instances may be updated in bulk or on a rolling basis.

An update to all instances in a cluster may cause significant downtime. To reduce the downtime, set the instance_update_behavior property in DatabaseClusterBaseProps to InstanceUpdateBehavior.ROLLING. This adds a dependency between each instance so the update is performed on only one instance at a time.

Use InstanceUpdateBehavior.BULK to update all instances at once.

vpc = nil # AWSCDK::EC2::VPC

cluster = AWSCDK::RDS::DatabaseCluster.new(self, "Database", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_mysql({version: AWSCDK::RDS::AuroraMysqlEngineVersion.VER_3_01_0}),
    writer: AWSCDK::RDS::ClusterInstance.provisioned("Instance", {
        instance_type: AWSCDK::EC2::InstanceType.of(AWSCDK::EC2::InstanceClass::BURSTABLE3, AWSCDK::EC2::InstanceSize::SMALL),
    }),
    readers: [AWSCDK::RDS::ClusterInstance.provisioned("reader")],
    instance_update_behaviour: AWSCDK::RDS::InstanceUpdateBehaviour::ROLLING,
    vpc: vpc,
})

Serverless V2 instances in a Cluster

It is possible to create an RDS cluster with both serverlessV2 and provisioned instances. For example, this will create a cluster with a provisioned writer and a serverless v2 reader.

Note Before getting starting with this type of cluster it is highly recommended that you read through the Developer Guide which goes into much more detail on the things you need to take into consideration.

vpc = nil # AWSCDK::EC2::VPC

cluster = AWSCDK::RDS::DatabaseCluster.new(self, "Database", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_mysql({version: AWSCDK::RDS::AuroraMysqlEngineVersion.VER_3_01_0}),
    writer: AWSCDK::RDS::ClusterInstance.provisioned("writer"),
    readers: [
        AWSCDK::RDS::ClusterInstance.serverless_v2("reader"),
    ],
    vpc: vpc,
})

Monitoring

There are some CloudWatch metrics that are important for Aurora Serverless v2.

vpc = nil # AWSCDK::EC2::VPC

cluster = AWSCDK::RDS::DatabaseCluster.new(self, "Database", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_mysql({version: AWSCDK::RDS::AuroraMysqlEngineVersion.VER_3_01_0}),
    writer: AWSCDK::RDS::ClusterInstance.provisioned("writer"),
    readers: [
        AWSCDK::RDS::ClusterInstance.serverless_v2("reader"),
    ],
    vpc: vpc,
})

cluster.metric_serverless_database_capacity({
    period: AWSCDK::Duration.minutes(10),
}).create_alarm(self, "capacity", {
    threshold: 1.5,
    evaluation_periods: 3,
})

cluster.metric_acu_utilization({
    period: AWSCDK::Duration.minutes(10),
}).create_alarm(self, "alarm", {
    evaluation_periods: 3,
    threshold: 90,
})

cluster.metric_volume_read_io_ps({
    period: AWSCDK::Duration.minutes(10),
}).create_alarm(self, "VolumeReadIOPsAlarm", {
    threshold: 1000,
    evaluation_periods: 3,
})

cluster.metric_volume_write_io_ps({
    period: AWSCDK::Duration.minutes(10),
}).create_alarm(self, "VolumeWriteIOPsAlarm", {
    threshold: 1000,
    evaluation_periods: 3,
})

instance = AWSCDK::RDS::DatabaseInstance.new(self, "Instance", {
    engine: AWSCDK::RDS::DatabaseInstanceEngine.postgres({version: AWSCDK::RDS::PostgresEngineVersion.VER_17_6}),
    vpc: vpc,
})

instance.metric_read_iops({
    period: AWSCDK::Duration.minutes(10),
}).create_alarm(self, "ReadIOPSAlarm", {
    threshold: 1000,
    evaluation_periods: 3,
})

instance.metric_write_iops({
    period: AWSCDK::Duration.minutes(10),
}).create_alarm(self, "WriteIOPSAlarm", {
    threshold: 1000,
    evaluation_periods: 3,
})

Capacity & Scaling

There are some things to take into consideration with Aurora Serverless v2.

To create a cluster that can support serverless v2 instances you configure a minimum and maximum capacity range on the cluster. This is an example showing the default values:

vpc = nil # AWSCDK::EC2::VPC

cluster = AWSCDK::RDS::DatabaseCluster.new(self, "Database", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_mysql({version: AWSCDK::RDS::AuroraMysqlEngineVersion.VER_3_01_0}),
    writer: AWSCDK::RDS::ClusterInstance.serverless_v2("writer"),
    serverless_v2_min_capacity: 0.5,
    serverless_v2_max_capacity: 2,
    vpc: vpc,
})

The capacity is defined as a number of Aurora capacity units (ACUs). You can specify in half-step increments (40, 40.5, 41, etc). Each serverless instance in the cluster inherits the capacity that is defined on the cluster. It is not possible to configure separate capacity at the instance level.

The maximum capacity is mainly used for budget control since it allows you to set a cap on how high your instance can scale.

The minimum capacity is a little more involved. This controls a couple different things.

Info More complete details can be found in the docs

You can also set minimum capacity to zero ACUs and automatically pause, if they don't have any connections initiated by user activity within a time period specified by serverless_v2_auto_pause_duration (300 seconds by default). For more information, see Scaling to Zero ACUs with automatic pause and resume for Aurora Serverless v2.

vpc = nil # AWSCDK::EC2::VPC

cluster = AWSCDK::RDS::DatabaseCluster.new(self, "Database", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_mysql({version: AWSCDK::RDS::AuroraMysqlEngineVersion.VER_3_08_0}),
    writer: AWSCDK::RDS::ClusterInstance.serverless_v2("writer"),
    serverless_v2_min_capacity: 0,
    serverless_v2_auto_pause_duration: AWSCDK::Duration.hours(1),
    vpc: vpc,
})

Another way that you control the capacity/scaling of your serverless v2 reader instances is based on the promotion tier which can be between 0-15. Any serverless v2 instance in the 0-1 tiers will scale alongside the writer even if the current read load does not require the capacity. This is because instances in the 0-1 tier are first priority for failover and Aurora wants to ensure that in the event of a failover the reader that gets promoted is scaled to handle the write load.

vpc = nil # AWSCDK::EC2::VPC

cluster = AWSCDK::RDS::DatabaseCluster.new(self, "Database", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_mysql({version: AWSCDK::RDS::AuroraMysqlEngineVersion.VER_3_01_0}),
    writer: AWSCDK::RDS::ClusterInstance.serverless_v2("writer"),
    readers: [
        AWSCDK::RDS::ClusterInstance.serverless_v2("reader1", {scale_with_writer: true}),
        AWSCDK::RDS::ClusterInstance.serverless_v2("reader2"),
    ],
    vpc: vpc,
})

When configuring your cluster it is important to take this into consideration and ensure that in the event of a failover there is an instance that is scaled up to take over.

Mixing Serverless v2 and Provisioned instances

You are able to create a cluster that has both provisioned and serverless instances. This blog post has an excellent guide on choosing between serverless and provisioned instances based on use case.

There are a couple of high level differences:

Provisioned writer

With a provisioned writer and serverless v2 readers, some of the serverless readers will need to be configured to scale with the writer so they can act as failover targets. You will need to determine the correct capacity based on the provisioned instance type and its utilization.

As an example, if the CPU utilization for a db.r6g.4xlarge (128 GB) instance stays at 10% most times, then the minimum ACUs may be set at 6.5 ACUs (10% of 128 GB) and maximum may be set at 64 ACUs (64x2GB=128GB). Keep in mind that the speed at which the serverless instance can scale up is determined by the minimum capacity so if your cluster has spiky workloads you may need to set a higher minimum capacity.

vpc = nil # AWSCDK::EC2::VPC

cluster = AWSCDK::RDS::DatabaseCluster.new(self, "Database", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_mysql({version: AWSCDK::RDS::AuroraMysqlEngineVersion.VER_3_01_0}),
    writer: AWSCDK::RDS::ClusterInstance.provisioned("writer", {
        instance_type: AWSCDK::EC2::InstanceType.of(AWSCDK::EC2::InstanceClass::R6G, AWSCDK::EC2::InstanceSize::XLARGE4),
    }),
    serverless_v2_min_capacity: 6.5,
    serverless_v2_max_capacity: 64,
    readers: [
        AWSCDK::RDS::ClusterInstance.serverless_v2("reader1", {scale_with_writer: true}),
        AWSCDK::RDS::ClusterInstance.serverless_v2("reader2"),
    ],
    vpc: vpc,
})

In the above example reader1 will scale with the writer based on the writer's utilization. So if the writer were to go to 50% utilization then reader1 would scale up to use 32 ACUs. If the read load stayed consistent then reader2 may remain at 6.5 since it is not configured to scale with the writer.

If one of your Aurora Serverless v2 DB instances consistently reaches the limit of its maximum capacity, Aurora indicates this condition by setting the DB instance to a status of incompatible-parameters. While the DB instance has the incompatible-parameters status, some operations are blocked. For example, you can't upgrade the engine version.

CA certificate

Use the ca_certificate property to specify the CA certificates to use for a cluster instances:

vpc = nil # AWSCDK::EC2::VPC

cluster = AWSCDK::RDS::DatabaseCluster.new(self, "Database", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_mysql({version: AWSCDK::RDS::AuroraMysqlEngineVersion.VER_3_01_0}),
    writer: AWSCDK::RDS::ClusterInstance.provisioned("writer", {
        ca_certificate: AWSCDK::RDS::CaCertificate.RDS_CA_RSA2048_G1,
    }),
    readers: [
        AWSCDK::RDS::ClusterInstance.serverless_v2("reader", {
            ca_certificate: AWSCDK::RDS::CaCertificate.of("custom-ca"),
        }),
    ],
    vpc: vpc,
})

Scheduling modifications

To schedule modifications to database instances in the next scheduled maintenance window, specify apply_immediately to false in the instance props:

vpc = nil # AWSCDK::EC2::VPC

AWSCDK::RDS::DatabaseCluster.new(self, "Database", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_mysql({version: AWSCDK::RDS::AuroraMysqlEngineVersion.VER_3_01_0}),
    writer: AWSCDK::RDS::ClusterInstance.provisioned("writer", {
        apply_immediately: false,
    }),
    readers: [
        AWSCDK::RDS::ClusterInstance.serverless_v2("reader", {
            apply_immediately: false,
        }),
    ],
    vpc: vpc,
})

Until RDS applies the changes, the DB instance remains in a drift state. As a result, the configuration doesn't fully reflect the requested modifications and temporarily diverges from the intended state.

Currently, CloudFormation does not support to schedule modifications of the cluster configurations. To apply changes of the cluster, such as engine version, in the next scheduled maintenance window, you should use modify-db-cluster CLI command or management console.

For details, see Modifying an Amazon Aurora DB cluster.

Retaining Automated Backups

By default, when a database cluster is deleted, automated backups are removed immediately unless an AWS Backup policy specifies a point-in-time restore rule. You can control this behavior using the delete_automated_backups property:

vpc = nil # AWSCDK::EC2::IVPC

# Retain automated backups after cluster deletion
AWSCDK::RDS::DatabaseCluster.new(self, "Database", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_mysql({version: AWSCDK::RDS::AuroraMysqlEngineVersion.VER_3_01_0}),
    writer: AWSCDK::RDS::ClusterInstance.provisioned("writer"),
    vpc: vpc,
    delete_automated_backups: false,
})

When set to false, automated backups are retained according to the configured retention period after the cluster is deleted. When set to true or not specified (default), automated backups are deleted immediately when the cluster is deleted. Detail about this feature can be found in the AWS documentation.

Migrating from instanceProps

Creating instances in a DatabaseCluster using instance_props & instances is deprecated. To migrate to the new properties you can provide the is_from_legacy_instance_props property.

For example, in order to migrate from this deprecated config:

vpc = nil # AWSCDK::EC2::VPC

cluster = AWSCDK::RDS::DatabaseCluster.new(self, "Database", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_mysql({
        version: AWSCDK::RDS::AuroraMysqlEngineVersion.VER_3_03_0,
    }),
    instances: 2,
    instance_props: {
        instance_type: AWSCDK::EC2::InstanceType.of(AWSCDK::EC2::InstanceClass::BURSTABLE3, AWSCDK::EC2::InstanceSize::SMALL),
        vpc_subnets: {subnet_type: AWSCDK::EC2::SubnetType::PUBLIC},
        vpc: vpc,
    },
})

You would need to migrate to this. The old method of providing instance_props and instances will create the number of instances that you provide. The first instance will be the writer and the rest will be the readers. It's important that the id that you provide is Instance{NUMBER}. The writer should always be Instance1 and the readers will increment from there.

Make sure to run a cdk diff before deploying to make sure that all changes are expected. Always test the migration in a non-production environment first.

vpc = nil # AWSCDK::EC2::VPC
instance_props = {
    instance_type: AWSCDK::EC2::InstanceType.of(AWSCDK::EC2::InstanceClass::BURSTABLE3, AWSCDK::EC2::InstanceSize::SMALL),
    is_from_legacy_instance_props: true,
}
cluster = AWSCDK::RDS::DatabaseCluster.new(self, "Database", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_mysql({
        version: AWSCDK::RDS::AuroraMysqlEngineVersion.VER_3_03_0,
    }),
    vpc_subnets: {subnet_type: AWSCDK::EC2::SubnetType::PUBLIC},
    vpc: vpc,
    writer: AWSCDK::RDS::ClusterInstance.provisioned("Instance1", {
        instance_type: instance_props.instance_type,
        is_from_legacy_instance_props: instance_props.is_from_legacy_instance_props,
    }),
    readers: [
        AWSCDK::RDS::ClusterInstance.provisioned("Instance2", {
            instance_type: instance_props.instance_type,
            is_from_legacy_instance_props: instance_props.is_from_legacy_instance_props,
        }),
    ],
})

Creating a read replica cluster

Use replication_source_identifier to create a read replica cluster:

vpc = nil # AWSCDK::EC2::VPC
primary_cluster = nil # AWSCDK::RDS::DatabaseCluster


AWSCDK::RDS::DatabaseCluster.new(self, "DatabaseCluster", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_mysql({
        version: AWSCDK::RDS::AuroraMysqlEngineVersion.VER_3_03_0,
    }),
    writer: AWSCDK::RDS::ClusterInstance.serverless_v2("Writer"),
    vpc: vpc,
    replication_source_identifier: primary_cluster.cluster_arn,
})

Note: Cannot create a read replica cluster with credentials as the value is inherited from the source DB cluster.

Starting an instance database

To set up an instance database, define a DatabaseInstance. You must always launch a database in a VPC. Use the vpc_subnets attribute to control whether your instances will be launched privately or publicly:

vpc = nil # AWSCDK::EC2::VPC

instance = AWSCDK::RDS::DatabaseInstance.new(self, "Instance", {
    engine: AWSCDK::RDS::DatabaseInstanceEngine.oracle_se2({version: AWSCDK::RDS::OracleEngineVersion.VER_19_0_0_0_2020_04_R1}),
    # optional, defaults to m5.large
    instance_type: AWSCDK::EC2::InstanceType.of(AWSCDK::EC2::InstanceClass::BURSTABLE3, AWSCDK::EC2::InstanceSize::SMALL),
    credentials: AWSCDK::RDS::Credentials.from_generated_secret("syscdk"),
    vpc: vpc,
    vpc_subnets: {
        subnet_type: AWSCDK::EC2::SubnetType::PRIVATE_WITH_EGRESS,
    },
})

If there isn't a constant for the exact engine version you want to use, all of the Version classes have a static of method that can be used to create an arbitrary version.

custom_engine_version = AWSCDK::RDS::OracleEngineVersion.of("19.0.0.0.ru-2020-04.rur-2020-04.r1", "19")

By default, the master password will be generated and stored in AWS Secrets Manager.

To use the storage auto scaling option of RDS you can specify the maximum allocated storage. This is the upper limit to which RDS can automatically scale the storage. More info can be found here Example for max storage configuration:

vpc = nil # AWSCDK::EC2::VPC

instance = AWSCDK::RDS::DatabaseInstance.new(self, "Instance", {
    engine: AWSCDK::RDS::DatabaseInstanceEngine.postgres({version: AWSCDK::RDS::PostgresEngineVersion.VER_16_3}),
    # optional, defaults to m5.large
    instance_type: AWSCDK::EC2::InstanceType.of(AWSCDK::EC2::InstanceClass::BURSTABLE2, AWSCDK::EC2::InstanceSize::SMALL),
    vpc: vpc,
    max_allocated_storage: 200,
})

When you create a DB instance, you can choose an Availability Zone or have Amazon RDS choose one for you randomly. For details, see Regions, Availability Zones, and Local Zones.

vpc = nil # AWSCDK::EC2::VPC

instance = AWSCDK::RDS::DatabaseInstance.new(self, "Instance", {
    engine: AWSCDK::RDS::DatabaseInstanceEngine.postgres({version: AWSCDK::RDS::PostgresEngineVersion.VER_16_3}),
    vpc: vpc,
    availability_zone: "us-east-1a",
})

To use dual-stack mode, specify NetworkType.DUAL on the network_type property:

vpc = nil # AWSCDK::EC2::VPC
# VPC and subnets must have IPv6 CIDR blocks
instance = AWSCDK::RDS::DatabaseInstance.new(self, "Instance", {
    engine: AWSCDK::RDS::DatabaseInstanceEngine.postgres({version: AWSCDK::RDS::PostgresEngineVersion.VER_16_3}),
    vpc: vpc,
    network_type: AWSCDK::RDS::NetworkType::DUAL,
    publicly_accessible: false,
})

For more information about dual-stack mode, see Working with a DB instance in a VPC.

Use DatabaseInstanceFromSnapshot and DatabaseInstanceReadReplica to create an instance from snapshot or a source database respectively:

vpc = nil # AWSCDK::EC2::VPC

source_instance = nil # AWSCDK::RDS::DatabaseInstance

AWSCDK::RDS::DatabaseInstanceFromSnapshot.new(self, "Instance", {
    snapshot_identifier: "my-snapshot",
    engine: AWSCDK::RDS::DatabaseInstanceEngine.postgres({version: AWSCDK::RDS::PostgresEngineVersion.VER_16_3}),
    # optional, defaults to m5.large
    instance_type: AWSCDK::EC2::InstanceType.of(AWSCDK::EC2::InstanceClass::BURSTABLE2, AWSCDK::EC2::InstanceSize::LARGE),
    vpc: vpc,
})
AWSCDK::RDS::DatabaseInstanceReadReplica.new(self, "ReadReplica", {
    source_database_instance: source_instance,
    instance_type: AWSCDK::EC2::InstanceType.of(AWSCDK::EC2::InstanceClass::BURSTABLE2, AWSCDK::EC2::InstanceSize::LARGE),
    vpc: vpc,
})

Or you can restore a DB instance from a Multi-AZ DB cluster snapshot

vpc = nil # AWSCDK::EC2::VPC


AWSCDK::RDS::DatabaseInstanceFromSnapshot.new(self, "Instance", {
    cluster_snapshot_identifier: "my-cluster-snapshot",
    engine: AWSCDK::RDS::DatabaseInstanceEngine.postgres({version: AWSCDK::RDS::PostgresEngineVersion.VER_16_3}),
    vpc: vpc,
})

Automatic backups of read replica instances are only supported for MySQL and MariaDB. By default, automatic backups are disabled for read replicas and can only be enabled (using backup_retention) if also enabled on the source instance.

For more information on configuring Oracle database instances, see option groups and parameter groups.

Use the storage_type property to specify the type of storage to use for the instance:

vpc = nil # AWSCDK::EC2::VPC


iops_instance = AWSCDK::RDS::DatabaseInstance.new(self, "IopsInstance", {
    engine: AWSCDK::RDS::DatabaseInstanceEngine.mysql({version: AWSCDK::RDS::MysqlEngineVersion.VER_8_0_39}),
    vpc: vpc,
    storage_type: AWSCDK::RDS::StorageType::IO1,
    iops: 5000,
})

gp3_instance = AWSCDK::RDS::DatabaseInstance.new(self, "Gp3Instance", {
    engine: AWSCDK::RDS::DatabaseInstanceEngine.mysql({version: AWSCDK::RDS::MysqlEngineVersion.VER_8_0_39}),
    vpc: vpc,
    allocated_storage: 500,
    storage_type: AWSCDK::RDS::StorageType::GP3,
    storage_throughput: 500,
})

Use the allocated_storage property to specify the amount of storage (in gigabytes) that is initially allocated for the instance to use for the instance:

vpc = nil # AWSCDK::EC2::VPC

# Setting allocatedStorage for DatabaseInstance replica
# Note: If allocatedStorage isn't set here, the replica instance will inherit the allocatedStorage of the source instance
source_instance = nil # AWSCDK::RDS::DatabaseInstance


# Setting allocatedStorage for DatabaseInstance
iops_instance = AWSCDK::RDS::DatabaseInstance.new(self, "IopsInstance", {
    engine: AWSCDK::RDS::DatabaseInstanceEngine.mysql({version: AWSCDK::RDS::MysqlEngineVersion.VER_8_0_39}),
    vpc: vpc,
    storage_type: AWSCDK::RDS::StorageType::IO1,
    iops: 5000,
    allocated_storage: 500,
})
AWSCDK::RDS::DatabaseInstanceReadReplica.new(self, "ReadReplica", {
    source_database_instance: source_instance,
    instance_type: AWSCDK::EC2::InstanceType.of(AWSCDK::EC2::InstanceClass::BURSTABLE2, AWSCDK::EC2::InstanceSize::LARGE),
    vpc: vpc,
    allocated_storage: 500,
})

Use the ca_certificate property to specify the CA certificates to use for the instance:

vpc = nil # AWSCDK::EC2::VPC


AWSCDK::RDS::DatabaseInstance.new(self, "Instance", {
    engine: AWSCDK::RDS::DatabaseInstanceEngine.mysql({version: AWSCDK::RDS::MysqlEngineVersion.VER_8_0_39}),
    vpc: vpc,
    ca_certificate: AWSCDK::RDS::CaCertificate.RDS_CA_RSA2048_G1,
})

You can specify a custom CA certificate with:

vpc = nil # AWSCDK::EC2::VPC


AWSCDK::RDS::DatabaseInstance.new(self, "Instance", {
    engine: AWSCDK::RDS::DatabaseInstanceEngine.mysql({version: AWSCDK::RDS::MysqlEngineVersion.VER_8_0_39}),
    vpc: vpc,
    ca_certificate: AWSCDK::RDS::CaCertificate.of("future-rds-ca"),
})

Scheduling modifications

To schedule modifications in the next scheduled maintenance window, specify apply_immediately to false:

vpc = nil # AWSCDK::EC2::VPC

AWSCDK::RDS::DatabaseInstance.new(self, "Instance", {
    engine: AWSCDK::RDS::DatabaseInstanceEngine.mysql({version: AWSCDK::RDS::MysqlEngineVersion.VER_8_0_39}),
    vpc: vpc,
    apply_immediately: false,
})

Until RDS applies the changes, the DB instance remains in a drift state. As a result, the configuration doesn't fully reflect the requested modifications and temporarily diverges from the intended state.

For details, see Using the schedule modifications setting.

Setting Public Accessibility

You can set public accessibility for the DatabaseInstance or the ClusterInstance using the publicly_accessible property. If you specify true, it creates an instance with a publicly resolvable DNS name, which resolves to a public IP address. If you specify false, it creates an internal instance with a DNS name that resolves to a private IP address.

The default value will be true if vpc_subnets is subnetType: SubnetType.PUBLIC, false otherwise. In the case of a cluster, the default value will be determined on the vpc placement of the DatabaseCluster otherwise it will be determined based on the vpc placement of standalone DatabaseInstance.

vpc = nil # AWSCDK::EC2::VPC

# Setting public accessibility for DB instance
AWSCDK::RDS::DatabaseInstance.new(self, "Instance", {
    engine: AWSCDK::RDS::DatabaseInstanceEngine.mysql({
        version: AWSCDK::RDS::MysqlEngineVersion.VER_8_0_19,
    }),
    vpc: vpc,
    vpc_subnets: {
        subnet_type: AWSCDK::EC2::SubnetType::PRIVATE_WITH_EGRESS,
    },
    publicly_accessible: true,
})

# Setting public accessibility for DB cluster instance
AWSCDK::RDS::DatabaseCluster.new(self, "DatabaseCluster", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_mysql({
        version: AWSCDK::RDS::AuroraMysqlEngineVersion.VER_3_03_0,
    }),
    writer: AWSCDK::RDS::ClusterInstance.serverless_v2("Writer", {
        publicly_accessible: true,
    }),
    vpc: vpc,
    vpc_subnets: {
        subnet_type: AWSCDK::EC2::SubnetType::PRIVATE_WITH_EGRESS,
    },
})

Instance events

To define Amazon CloudWatch event rules for database instances, use the on_event method:

instance = nil # AWSCDK::RDS::DatabaseInstance
fn = nil # AWSCDK::Lambda::Function

rule = instance.on_event("InstanceEvent", {target: AWSCDK::EventsTargets::LambdaFunction.new(fn)})

Login credentials

By default, database instances and clusters (with the exception of DatabaseInstanceFromSnapshot and ServerlessClusterFromSnapshot) will have admin user with an auto-generated password. An alternative username (and password) may be specified for the admin user instead of the default.

The following examples use a DatabaseInstance, but the same usage is applicable to DatabaseCluster.

vpc = nil # AWSCDK::EC2::VPC

engine = AWSCDK::RDS::DatabaseInstanceEngine.postgres({version: AWSCDK::RDS::PostgresEngineVersion.VER_16_3})
AWSCDK::RDS::DatabaseInstance.new(self, "InstanceWithUsername", {
    engine: engine,
    vpc: vpc,
    credentials: AWSCDK::RDS::Credentials.from_generated_secret("postgres"),
})

AWSCDK::RDS::DatabaseInstance.new(self, "InstanceWithUsernameAndPassword", {
    engine: engine,
    vpc: vpc,
    credentials: AWSCDK::RDS::Credentials.from_password("postgres", AWSCDK::SecretValue.ssm_secure("/dbPassword", "1")),
})

my_secret = AWSCDK::SecretsManager::Secret.from_secret_name(self, "DBSecret", "myDBLoginInfo")
AWSCDK::RDS::DatabaseInstance.new(self, "InstanceWithSecretLogin", {
    engine: engine,
    vpc: vpc,
    credentials: AWSCDK::RDS::Credentials.from_secret(my_secret),
})

Secrets generated by from_generated_secret() can be customized:

vpc = nil # AWSCDK::EC2::VPC

engine = AWSCDK::RDS::DatabaseInstanceEngine.postgres({version: AWSCDK::RDS::PostgresEngineVersion.VER_16_3})
my_key = AWSCDK::KMS::Key.new(self, "MyKey")

AWSCDK::RDS::DatabaseInstance.new(self, "InstanceWithCustomizedSecret", {
    engine: engine,
    vpc: vpc,
    credentials: AWSCDK::RDS::Credentials.from_generated_secret("postgres", {
        secret_name: "my-cool-name",
        encryption_key: my_key,
        exclude_characters: "!&*^\#@()",
        replica_regions: [{region: "eu-west-1"}, {region: "eu-west-2"}],
    }),
})

RDS-managed master password

You can enable RDS to manage the master password in AWS Secrets Manager by setting manage_master_user_password to true. When enabled, RDS creates and manages the secret automatically, and you can only specify the username and optionally an encryption_key in the credentials:

vpc = nil # AWSCDK::EC2::VPC
kms_key = nil # AWSCDK::KMS::Key


# Database cluster with RDS-managed password
AWSCDK::RDS::DatabaseCluster.new(self, "Cluster", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_mysql({version: AWSCDK::RDS::AuroraMysqlEngineVersion.VER_3_01_0}),
    writer: AWSCDK::RDS::ClusterInstance.serverless_v2("writer"),
    vpc: vpc,
    manage_master_user_password: true,
    credentials: AWSCDK::RDS::Credentials.from_username("admin", {
        encryption_key: kms_key,
    }),
})

# Database instance with RDS-managed password
AWSCDK::RDS::DatabaseInstance.new(self, "Instance", {
    engine: AWSCDK::RDS::DatabaseInstanceEngine.postgres({version: AWSCDK::RDS::PostgresEngineVersion.VER_16_3}),
    vpc: vpc,
    manage_master_user_password: true,
    credentials: AWSCDK::RDS::Credentials.from_username("postgres"),
})

Note: When manage_master_user_password is enabled, you cannot use other credential properties like password, secret, secret_name, exclude_characters, replica_regions, or username_as_string. Only username and encryption_key are allowed. The secret property exposes a read-only reference to the secret that RDS created, not a CDK-owned secret — add_to_resource_policy() is a no-op, so use secret.grantRead(grantee) to grant access.

Snapshot credentials

As noted above, Databases created with DatabaseInstanceFromSnapshot or ServerlessClusterFromSnapshot will not create user and auto-generated password by default because it's not possible to change the master username for a snapshot. Instead, they will use the existing username and password from the snapshot. You can still generate a new password - to generate a secret similarly to the other constructs, pass in credentials with from_generated_secret() or from_generated_password().

vpc = nil # AWSCDK::EC2::VPC

engine = AWSCDK::RDS::DatabaseInstanceEngine.postgres({version: AWSCDK::RDS::PostgresEngineVersion.VER_16_3})
my_key = AWSCDK::KMS::Key.new(self, "MyKey")

AWSCDK::RDS::DatabaseInstanceFromSnapshot.new(self, "InstanceFromSnapshotWithCustomizedSecret", {
    engine: engine,
    vpc: vpc,
    snapshot_identifier: "mySnapshot",
    credentials: AWSCDK::RDS::SnapshotCredentials.from_generated_secret("username", {
        encryption_key: my_key,
        exclude_characters: "!&*^\#@()",
        replica_regions: [{region: "eu-west-1"}, {region: "eu-west-2"}],
    }),
})

Connecting

To control who can access the cluster or instance, use the .connections attribute. RDS databases have a default port, so you don't need to specify the port:

cluster = nil # AWSCDK::RDS::DatabaseCluster

cluster.connections.allow_from_any_ipv4(AWSCDK::EC2::Port.all_traffic, "Open to the world")

The endpoints to access your database cluster will be available as the .clusterEndpoint and .readerEndpoint attributes:

cluster = nil # AWSCDK::RDS::DatabaseCluster

write_address = cluster.cluster_endpoint.socket_address

For an instance database:

instance = nil # AWSCDK::RDS::DatabaseInstance

address = instance.instance_endpoint.socket_address

Rotating credentials

When the master password is generated and stored in AWS Secrets Manager, it can be rotated automatically:

instance = nil # AWSCDK::RDS::DatabaseInstance
my_security_group = nil # AWSCDK::EC2::SecurityGroup


instance.add_rotation_single_user({
    automatically_after: AWSCDK::Duration.days(7),
     # defaults to 30 days
    exclude_characters: "!@\#$%^&*",
     # defaults to the set " %+~`#/// here*()|[]{}:;<>?!'/@\"\\"
    security_group: my_security_group,
})

For more information on setting up master password rotation for a cluster, see Set up automatic rotation for Amazon RDS secrets.

The multi user rotation scheme is also available:

instance = nil # AWSCDK::RDS::DatabaseInstance
my_imported_secret = nil # AWSCDK::RDS::DatabaseSecret

instance.add_rotation_multi_user("MyUser", {
    secret: my_imported_secret,
})

It's also possible to create user credentials together with the instance/cluster and add rotation:

instance = nil # AWSCDK::RDS::DatabaseInstance

my_user_secret = AWSCDK::RDS::DatabaseSecret.new(self, "MyUserSecret", {
    username: "myuser",
    secret_name: "my-user-secret",
     # optional, defaults to a CloudFormation-generated name
    dbname: "mydb",
     # optional, defaults to the main database of the RDS cluster this secret gets attached to
    master_secret: instance.secret,
    exclude_characters: "{}[]()'\"/\\",
})
my_user_secret_attached = my_user_secret.attach(instance) # Adds DB connections information in the secret

instance.add_rotation_multi_user("MyUser", {
     # Add rotation using the multi user scheme
    secret: my_user_secret_attached,
})

Note: This user must be created manually in the database using the master credentials. The rotation will start as soon as this user exists.

Access to the Secrets Manager API is required for the secret rotation. This can be achieved either with internet connectivity (through NAT) or with a VPC interface endpoint. By default, the rotation Lambda function is deployed in the same subnets as the instance/cluster. If access to the Secrets Manager API is not possible from those subnets or using the default API endpoint, use the vpc_subnets and/or endpoint options:

instance = nil # AWSCDK::RDS::DatabaseInstance
my_endpoint = nil # AWSCDK::EC2::InterfaceVPCEndpoint


instance.add_rotation_single_user({
    vpc_subnets: {subnet_type: AWSCDK::EC2::SubnetType::PRIVATE_WITH_EGRESS},
     # Place rotation Lambda in private subnets
    endpoint: my_endpoint,
})

See also aws-cdk-lib/aws-secretsmanager for credentials rotation of existing clusters/instances.

By default, any stack updates will cause AWS Secrets Manager to rotate a secret immediately. To prevent this behavior and wait until the next scheduled rotation window specified via the automatically_after property, set the rotate_immediately_on_update property to false:

instance = nil # AWSCDK::RDS::DatabaseInstance
my_security_group = nil # AWSCDK::EC2::SecurityGroup


instance.add_rotation_single_user({
    automatically_after: AWSCDK::Duration.days(7),
     # defaults to 30 days
    exclude_characters: "!@\#$%^&*",
     # defaults to the set " %+~`#/// here*()|[]{}:;<>?!'/@\"\\"
    security_group: my_security_group,
     # defaults to an auto-created security group
    rotate_immediately_on_update: false,
})

IAM Authentication

You can also authenticate to a database instance using AWS Identity and Access Management (IAM) database authentication; See https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.html for more information and a list of supported versions and limitations.

The following example shows enabling IAM authentication for a database instance and granting connection access to an IAM role.

Instance

vpc = nil # AWSCDK::EC2::VPC

instance = AWSCDK::RDS::DatabaseInstance.new(self, "Instance", {
    engine: AWSCDK::RDS::DatabaseInstanceEngine.mysql({version: AWSCDK::RDS::MysqlEngineVersion.VER_8_0_19}),
    vpc: vpc,
    iam_authentication: true,
})
role = AWSCDK::IAM::Role.new(self, "DBRole", {assumed_by: AWSCDK::IAM::AccountPrincipal.new(@account)})
instance.grant_connect(role)

Proxy

The following example shows granting connection access for RDS Proxy to an IAM role.

vpc = nil # AWSCDK::EC2::VPC

cluster = AWSCDK::RDS::DatabaseCluster.new(self, "Database", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_mysql({
        version: AWSCDK::RDS::AuroraMysqlEngineVersion.VER_3_03_0,
    }),
    writer: AWSCDK::RDS::ClusterInstance.provisioned("writer"),
    vpc: vpc,
})

proxy = AWSCDK::RDS::DatabaseProxy.new(self, "Proxy", {
    proxy_target: AWSCDK::RDS::ProxyTarget.from_cluster(cluster),
    secrets: [cluster.secret],
    vpc: vpc,
})

role = AWSCDK::IAM::Role.new(self, "DBProxyRole", {assumed_by: AWSCDK::IAM::AccountPrincipal.new(@account)})
proxy.grant_connect(role, "admin")

Note: In addition to the setup above, a database user will need to be created to support IAM auth. See https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.DBAccounts.html for setup instructions.

To specify the details of authentication used by a proxy to log in as a specific database user use the client_password_auth_type property:

vpc = nil # AWSCDK::EC2::VPC

cluster = AWSCDK::RDS::DatabaseCluster.new(self, "Database", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_mysql({
        version: AWSCDK::RDS::AuroraMysqlEngineVersion.VER_3_03_0,
    }),
    writer: AWSCDK::RDS::ClusterInstance.provisioned("writer"),
    vpc: vpc,
})

proxy = AWSCDK::RDS::DatabaseProxy.new(self, "Proxy", {
    proxy_target: AWSCDK::RDS::ProxyTarget.from_cluster(cluster),
    secrets: [cluster.secret],
    vpc: vpc,
    client_password_auth_type: AWSCDK::RDS::ClientPasswordAuthType::MYSQL_NATIVE_PASSWORD,
})

Default Authentication Scheme

RDS Proxy supports different authentication schemes to connect to your database. You can configure the default authentication scheme using the default_auth_scheme property.

When using DefaultAuthScheme.IAM_AUTH, the proxy uses end-to-end IAM authentication to connect to the database, eliminating the need for secrets stored in AWS Secrets Manager:

vpc = nil # AWSCDK::EC2::VPC

instance = AWSCDK::RDS::DatabaseInstance.new(self, "Database", {
    engine: AWSCDK::RDS::DatabaseInstanceEngine.postgres({
        version: AWSCDK::RDS::PostgresEngineVersion.VER_17_7,
    }),
    vpc: vpc,
    iam_authentication: true,
})

proxy = AWSCDK::RDS::DatabaseProxy.new(self, "Proxy", {
    proxy_target: AWSCDK::RDS::ProxyTarget.from_instance(instance),
    vpc: vpc,
    default_auth_scheme: AWSCDK::RDS::DefaultAuthScheme::IAM_AUTH,
})

# Grant IAM permissions for database connection
role = AWSCDK::IAM::Role.new(self, "DBRole", {assumed_by: AWSCDK::IAM::AccountPrincipal.new(@account)})
proxy.grant_connect(role, "database-user")

Cluster

The following example shows granting connection access for an IAM role to an Aurora Cluster.

vpc = nil # AWSCDK::EC2::VPC

cluster = AWSCDK::RDS::DatabaseCluster.new(self, "Database", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_mysql({
        version: AWSCDK::RDS::AuroraMysqlEngineVersion.VER_3_03_0,
    }),
    writer: AWSCDK::RDS::ClusterInstance.provisioned("writer"),
    vpc: vpc,
})
role = AWSCDK::IAM::Role.new(self, "AppRole", {assumed_by: AWSCDK::IAM::ServicePrincipal.new("someservice.amazonaws.com")})
cluster.grant_connect(role, "somedbuser")

Note: In addition to the setup above, a database user will need to be created to support IAM auth. See https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.DBAccounts.html for setup instructions.

Kerberos Authentication

You can also authenticate using Kerberos to a database instance using AWS Managed Microsoft AD for authentication; See https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/kerberos-authentication.html for more information and a list of supported versions and limitations.

The following example shows enabling domain support for a database instance and creating an IAM role to access Directory Services.

vpc = nil # AWSCDK::EC2::VPC

role = AWSCDK::IAM::Role.new(self, "RDSDirectoryServicesRole", {
    assumed_by: AWSCDK::IAM::CompositePrincipal.new(
    AWSCDK::IAM::ServicePrincipal.new("rds.amazonaws.com"),
    AWSCDK::IAM::ServicePrincipal.new("directoryservice.rds.amazonaws.com")),
    managed_policies: [
        AWSCDK::IAM::ManagedPolicy.from_aws_managed_policy_name("service-role/AmazonRDSDirectoryServiceAccess"),
    ],
})
instance = AWSCDK::RDS::DatabaseInstance.new(self, "Instance", {
    engine: AWSCDK::RDS::DatabaseInstanceEngine.mysql({version: AWSCDK::RDS::MysqlEngineVersion.VER_8_0_19}),
    vpc: vpc,
    domain: "d-????????",
     # The ID of the domain for the instance to join.
    domain_role: role,
})

You can also use the Kerberos authentication for an Aurora database cluster.

vpc = nil # AWSCDK::EC2::VPC

iam_role = AWSCDK::IAM::Role.new(self, "Role", {
    assumed_by: AWSCDK::IAM::CompositePrincipal.new(
    AWSCDK::IAM::ServicePrincipal.new("rds.amazonaws.com"),
    AWSCDK::IAM::ServicePrincipal.new("directoryservice.rds.amazonaws.com")),
    managed_policies: [
        AWSCDK::IAM::ManagedPolicy.from_aws_managed_policy_name("service-role/AmazonRDSDirectoryServiceAccess"),
    ],
})

AWSCDK::RDS::DatabaseCluster.new(self, "Database", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_mysql({version: AWSCDK::RDS::AuroraMysqlEngineVersion.VER_3_05_1}),
    writer: AWSCDK::RDS::ClusterInstance.provisioned("Instance", {
        instance_type: AWSCDK::EC2::InstanceType.of(AWSCDK::EC2::InstanceClass::BURSTABLE3, AWSCDK::EC2::InstanceSize::MEDIUM),
    }),
    vpc: vpc,
    domain: "d-????????",
     # The ID of the domain for the cluster to join.
    domain_role: iam_role,
})

Note: In addition to the setup above, you need to make sure that the database instance or cluster has network connectivity to the domain controllers. This includes enabling cross-VPC traffic if in a different VPC and setting up the appropriate security groups/network ACL to allow traffic between the database instance and domain controllers. Once configured, see https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/kerberos-authentication.html for details on configuring users for each available database engine.

Metrics

Database instances and clusters both expose metrics (cloudwatch.Metric):

# The number of database connections in use (average over 5 minutes)
instance = nil # AWSCDK::RDS::DatabaseInstance

# Average CPU utilization over 5 minutes
cluster = nil # AWSCDK::RDS::DatabaseCluster

db_connections = instance.metric_database_connections
cpu_utilization = cluster.metric_cpu_utilization

# The average amount of time taken per disk I/O operation (average over 1 minute)
read_latency = instance.metric("ReadLatency", {statistic: "Average", period: AWSCDK::Duration.seconds(60)})

Enabling S3 integration

Data in S3 buckets can be imported to and exported from certain database engines using SQL queries. To enable this functionality, set the s3_import_buckets and s3_export_buckets properties for import and export respectively. When configured, the CDK automatically creates and configures IAM roles as required. Additionally, the s3_import_role and s3_export_role properties can be used to set this role directly. Note: To use s3_import_role and s3_export_role with Aurora PostgreSQL, you must also enable the S3 import and export features when you create the DatabaseClusterEngine.

You can read more about loading data to (or from) S3 here:

The following snippet sets up a database cluster with different S3 buckets where the data is imported and exported -

require 'aws-cdk-lib'

vpc = nil # AWSCDK::EC2::VPC

import_bucket = AWSCDK::S3::Bucket.new(self, "importbucket")
export_bucket = AWSCDK::S3::Bucket.new(self, "exportbucket")
AWSCDK::RDS::DatabaseCluster.new(self, "dbcluster", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_mysql({
        version: AWSCDK::RDS::AuroraMysqlEngineVersion.VER_3_03_0,
    }),
    writer: AWSCDK::RDS::ClusterInstance.provisioned("writer"),
    vpc: vpc,
    s3_import_buckets: [import_bucket],
    s3_export_buckets: [export_bucket],
})

Creating a Database Proxy

Amazon RDS Proxy sits between your application and your relational database to efficiently manage connections to the database and improve scalability of the application. Learn more about at Amazon RDS Proxy.

RDS Proxy is supported for MySQL, MariaDB, Postgres, and SQL Server.

The following code configures an RDS Proxy for a DatabaseInstance.

vpc = nil # AWSCDK::EC2::VPC
security_group = nil # AWSCDK::EC2::SecurityGroup
secrets = []
db_instance = nil # AWSCDK::RDS::DatabaseInstance


proxy = db_instance.add_proxy("proxy", {
    borrow_timeout: AWSCDK::Duration.seconds(30),
    max_connections_percent: 50,
    secrets: secrets,
    vpc: vpc,
})

Proxy Endpoint

The following example add additional endpoint to RDS Proxy.

vpc = nil # AWSCDK::EC2::VPC
secrets = []
db_instance = nil # AWSCDK::RDS::DatabaseInstance


proxy = db_instance.add_proxy("Proxy", {
    secrets: secrets,
    vpc: vpc,
})

# Add a reader endpoint
proxy.add_endpoint("ProxyEndpoint", {
    vpc: vpc,
    target_role: AWSCDK::RDS::ProxyEndpointTargetRole::READ_ONLY,
})

Exporting Logs

You can publish database logs to Amazon CloudWatch Logs. With CloudWatch Logs, you can perform real-time analysis of the log data, store the data in highly durable storage, and manage the data with the CloudWatch Logs Agent. This is available for both database instances and clusters; the types of logs available depend on the database type and engine being used.

require 'aws-cdk-lib'
my_logs_publishing_role = nil # AWSCDK::IAM::Role
vpc = nil # AWSCDK::EC2::VPC


# Exporting logs from a cluster
cluster = AWSCDK::RDS::DatabaseCluster.new(self, "Database", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora({
        version: AWSCDK::RDS::AuroraEngineVersion.VER_1_17_9,
    }),
    writer: AWSCDK::RDS::ClusterInstance.provisioned("writer"),
    vpc: vpc,
    cloudwatch_logs_exports: ["error", "general", "slowquery", "audit", "instance", "iam-db-auth-error"],
     # Export all available MySQL-based logs
    cloudwatch_logs_retention: AWSCDK::Logs::RetentionDays::THREE_MONTHS,
     # Optional - default is to never expire logs
    cloudwatch_logs_retention_role: my_logs_publishing_role,
})

# When 'cloudwatchLogsExports' is set, each export value creates its own log group in DB cluster.
# Specify an export value to access its log group.
error_log_group = cluster.cloudwatch_log_groups["error"]
audit_log_group = cluster.cloudwatch_log_groups.audit

# Exporting logs from an instance
instance = AWSCDK::RDS::DatabaseInstance.new(self, "Instance", {
    engine: AWSCDK::RDS::DatabaseInstanceEngine.postgres({
        version: AWSCDK::RDS::PostgresEngineVersion.VER_16_3,
    }),
    vpc: vpc,
    cloudwatch_logs_exports: ["postgresql"],
     # Export the PostgreSQL logs
    cloudwatch_logs_retention: AWSCDK::Logs::RetentionDays::THREE_MONTHS,
})

# When 'cloudwatchLogsExports' is set, each export value creates its own log group in DB instance.
# Specify an export value to access its log group.
postgresql_log_group = instance.cloudwatch_log_groups["postgresql"]

Option Groups

Some DB engines offer additional features that make it easier to manage data and databases, and to provide additional security for your database. Amazon RDS uses option groups to enable and configure these features. An option group can specify features, called options, that are available for a particular Amazon RDS DB instance.

vpc = nil # AWSCDK::EC2::VPC
security_group = nil # AWSCDK::EC2::SecurityGroup


AWSCDK::RDS::OptionGroup.new(self, "Options", {
    engine: AWSCDK::RDS::DatabaseInstanceEngine.oracle_se2({
        version: AWSCDK::RDS::OracleEngineVersion.VER_19,
    }),
    configurations: [
        {
            name: "OEM",
            port: 5500,
            vpc: vpc,
            security_groups: [security_group],
        },
    ],
    option_group_name: "MyOptionGroup",
})

Parameter Groups

Database parameters specify how the database is configured. For example, database parameters can specify the amount of resources, such as memory, to allocate to a database. You manage your database configuration by associating your DB instances with parameter groups. Amazon RDS defines parameter groups with default settings.

You can create your own parameter group for your cluster or instance and associate it with your database:

vpc = nil # AWSCDK::EC2::VPC


parameter_group = AWSCDK::RDS::ParameterGroup.new(self, "ParameterGroup", {
    engine: AWSCDK::RDS::DatabaseInstanceEngine.sql_server_ee({
        version: AWSCDK::RDS::SqlServerEngineVersion.VER_11,
    }),
    name: "my-parameter-group",
    parameters: {
        locks: "100",
    },
})

AWSCDK::RDS::DatabaseInstance.new(self, "Database", {
    engine: AWSCDK::RDS::DatabaseInstanceEngine.SQL_SERVER_EE,
    vpc: vpc,
    parameter_group: parameter_group,
})

Another way to specify parameters is to use the inline field parameters that creates an RDS parameter group for you. You can use this if you do not want to reuse the parameter group instance for different instances:

vpc = nil # AWSCDK::EC2::VPC


AWSCDK::RDS::DatabaseInstance.new(self, "Database", {
    engine: AWSCDK::RDS::DatabaseInstanceEngine.sql_server_ee({version: AWSCDK::RDS::SqlServerEngineVersion.VER_11}),
    vpc: vpc,
    parameters: {
        locks: "100",
    },
})

You cannot specify a parameter map and a parameter group at the same time.

Creating Standalone Parameter Groups

In some scenarios, you may want to create a parameter group that exists independently of a database instance or cluster.

By default, ParameterGroup uses a lazy creation pattern and only generates the CloudFormation resource when bound to an instance or cluster. To create a standalone parameter group, use the static factory methods for_instance() or for_cluster():

For instance parameter group (AWS::RDS::DBParameterGroup):

parameter_group = AWSCDK::RDS::ParameterGroup.for_instance(self, "InstanceParameterGroup", {
    engine: AWSCDK::RDS::DatabaseInstanceEngine.mysql({
        version: AWSCDK::RDS::MysqlEngineVersion.VER_8_0_35,
    }),
    description: "Parameter group for MySQL",
    parameters: {
        max_connections: "150",
        slow_query_log: "1",
    },
})

For cluster parameter group (AWS::RDS::DBClusterParameterGroup):

cluster_parameter_group = AWSCDK::RDS::ParameterGroup.for_cluster(self, "ClusterParameterGroup", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_mysql({
        version: AWSCDK::RDS::AuroraMysqlEngineVersion.VER_3_04_0,
    }),
    description: "Parameter group for Aurora MySQL",
    parameters: {
        aurora_parallel_query: "1",
    },
})

Serverless v1

Amazon Aurora Serverless v1 is an on-demand, auto-scaling configuration for Amazon Aurora. The database will automatically start up, shut down, and scale capacity up or down based on your application's needs. It enables you to run your database in the cloud without managing any database instances.

The following example initializes an Aurora Serverless v1 PostgreSql cluster. Aurora Serverless clusters can specify scaling properties which will be used to automatically scale the database cluster seamlessly based on the workload.

vpc = nil # AWSCDK::EC2::VPC


cluster = AWSCDK::RDS::ServerlessCluster.new(self, "AnotherCluster", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.AURORA_POSTGRESQL,
    copy_tags_to_snapshot: true,
     # whether to save the cluster tags when creating the snapshot. Default is 'true'
    parameter_group: AWSCDK::RDS::ParameterGroup.from_parameter_group_name(self, "ParameterGroup", "default.aurora-postgresql11"),
    vpc: vpc,
    scaling: {
        auto_pause: AWSCDK::Duration.minutes(10),
         # default is to pause after 5 minutes of idle time
        min_capacity: AWSCDK::RDS::AuroraCapacityUnit::ACU_8,
         # default is 2 Aurora capacity units (ACUs)
        max_capacity: AWSCDK::RDS::AuroraCapacityUnit::ACU_32,
         # default is 16 Aurora capacity units (ACUs)
        timeout: AWSCDK::Duration.seconds(100),
         # default is 5 minutes
        timeout_action: AWSCDK::RDS::TimeoutAction::FORCE_APPLY_CAPACITY_CHANGE,
    },
})

Note: The rds.ServerlessCluster class is for Aurora Serverless v1. If you want to use Aurora Serverless v2, use the rds.DatabaseCluster class.

Aurora Serverless v1 Clusters do not support the following features:

Read more about the limitations of Aurora Serverless v1

Learn more about using Amazon Aurora Serverless v1 by reading the documentation

Use ServerlessClusterFromSnapshot to create a serverless cluster from a snapshot:

vpc = nil # AWSCDK::EC2::VPC

AWSCDK::RDS::ServerlessClusterFromSnapshot.new(self, "Cluster", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.AURORA_MYSQL,
    vpc: vpc,
    snapshot_identifier: "mySnapshot",
})

Data API

You can access your Aurora DB cluster using the built-in Data API. The Data API doesn't require a persistent connection to the DB cluster. Instead, it provides a secure HTTP endpoint and integration with AWS SDKs.

The following example shows granting Data API access to a Lambda function.

vpc = nil # AWSCDK::EC2::VPC
fn = nil # AWSCDK::Lambda::Function
secret = nil # AWSCDK::SecretsManager::Secret


# Create a serverless V1 cluster
serverless_v1_cluster = AWSCDK::RDS::ServerlessCluster.new(self, "AnotherCluster", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.AURORA_MYSQL,
    vpc: vpc,
     # this parameter is optional for serverless Clusters
    enable_data_api: true,
})
serverless_v1_cluster.grant_data_api_access(fn)

# Create an Aurora cluster
cluster = AWSCDK::RDS::DatabaseCluster.new(self, "Cluster", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.AURORA_MYSQL,
    vpc: vpc,
    enable_data_api: true,
})
cluster.grant_data_api_access(fn)

# Import an Aurora cluster
imported_cluster = AWSCDK::RDS::DatabaseCluster.from_database_cluster_attributes(self, "ImportedCluster", {
    cluster_identifier: "clusterIdentifier",
    secret: secret,
    data_api_enabled: true,
})
imported_cluster.grant_data_api_access(fn)

Note: To invoke the Data API, the resource will need to read the secret associated with the cluster.

To learn more about using the Data API, see the documentation.

Default VPC

The vpc parameter is optional.

If not provided, the cluster will be created in the default VPC of the account and region. As this VPC is not deployed with AWS CDK, you can't configure the vpc_subnets, subnet_group or security_groups of the Aurora Serverless Cluster. If you want to provide one of vpc_subnets, subnet_group or security_groups parameter, please provide a vpc.

Preferred Maintenance Window

When creating an RDS cluster, it is possible to (optionally) specify a preferred maintenance window for the cluster as well as the instances under the cluster. See AWS docs for more information regarding maintenance windows.

The following code snippet shows an example of setting the cluster's maintenance window to 22:15-22:45 (UTC) on Saturdays, but setting the instances' maintenance window to 23:15-23:45 on Sundays

vpc = nil # AWSCDK::EC2::VPC

AWSCDK::RDS::DatabaseCluster.new(self, "DatabaseCluster", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.AURORA,
    instance_props: {
        vpc: vpc,
        preferred_maintenance_window: "Sun:23:15-Sun:23:45",
    },
    preferred_maintenance_window: "Sat:22:15-Sat:22:45",
})

You can also set the preferred maintenance window via reader and writer props:

vpc = nil # AWSCDK::EC2::VPC

AWSCDK::RDS::DatabaseCluster.new(self, "DatabaseCluster", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.AURORA,
    vpc: vpc,
    writer: AWSCDK::RDS::ClusterInstance.provisioned("WriterInstance", {
        preferred_maintenance_window: "Sat:22:15-Sat:22:45",
    }),
    preferred_maintenance_window: "Sat:22:15-Sat:22:45",
})

Performance Insights

You can enable Performance Insights for a clustered database or an instance database.

Clustered Database

You can enable Performance Insights at cluster level or instance level.

To enable Performance Insights at the cluster level, set the enable_performance_insights property for the DatabaseCluster to true. If you want to specify the detailed settings, you can use the performance_insight_retention and performance_insight_encryption_key properties.

The settings are then applied to all instances in the cluster.

vpc = nil # AWSCDK::EC2::VPC
kms_key = nil # AWSCDK::KMS::Key

AWSCDK::RDS::DatabaseCluster.new(self, "Database", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.AURORA,
    vpc: vpc,
    enable_performance_insights: true,
    performance_insight_retention: AWSCDK::RDS::PerformanceInsightRetention::LONG_TERM,
    performance_insight_encryption_key: kms_key,
    writer: AWSCDK::RDS::ClusterInstance.provisioned("Writer", {
        instance_type: AWSCDK::EC2::InstanceType.of(AWSCDK::EC2::InstanceClass::R7G, AWSCDK::EC2::InstanceSize::LARGE),
    }),
})

To enable Performance Insights at the instance level, set the same properties for each instance of the writer and the readers.

In this way, different settings can be applied to different instances in a cluster.

Note: If Performance Insights is enabled at the cluster level, it is also automatically enabled for each instance. If specified, Performance Insights for each instance require the same retention period and encryption key as the cluster level.

vpc = nil # AWSCDK::EC2::VPC
kms_key = nil # AWSCDK::KMS::Key

AWSCDK::RDS::DatabaseCluster.new(self, "Database", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.AURORA,
    vpc: vpc,
    writer: AWSCDK::RDS::ClusterInstance.provisioned("Writer", {
        instance_type: AWSCDK::EC2::InstanceType.of(AWSCDK::EC2::InstanceClass::R7G, AWSCDK::EC2::InstanceSize::LARGE),
        enable_performance_insights: true,
        performance_insight_retention: AWSCDK::RDS::PerformanceInsightRetention::LONG_TERM,
        performance_insight_encryption_key: kms_key,
    }),
    readers: [
        AWSCDK::RDS::ClusterInstance.provisioned("Reader", {
            instance_type: AWSCDK::EC2::InstanceType.of(AWSCDK::EC2::InstanceClass::R7G, AWSCDK::EC2::InstanceSize::LARGE),
            enable_performance_insights: false,
        }),
    ],
})

Instance Database

To enable Performance Insights for an instance database, set the enable_performance_insights property for the DatabaseInstance to true. If you want to specify the detailed settings, you can use the performance_insight_retention and performance_insight_encryption_key properties.

vpc = nil # AWSCDK::EC2::VPC
kms_key = nil # AWSCDK::KMS::Key

instance = AWSCDK::RDS::DatabaseInstance.new(self, "Instance", {
    engine: AWSCDK::RDS::DatabaseInstanceEngine.mysql({version: AWSCDK::RDS::MysqlEngineVersion.VER_8_0_39}),
    instance_type: AWSCDK::EC2::InstanceType.of(AWSCDK::EC2::InstanceClass::R7G, AWSCDK::EC2::InstanceSize::LARGE),
    vpc: vpc,
    enable_performance_insights: true,
    performance_insight_retention: AWSCDK::RDS::PerformanceInsightRetention::LONG_TERM,
    performance_insight_encryption_key: kms_key,
})

Supported Engines

Performance Insights supports a limited number of engines.

To see Amazon RDS DB engines that support Performance Insights, see Amazon RDS DB engine, Region, and instance class support for Performance Insights.

To see Amazon Aurora DB engines that support Performance Insights, see Amazon Aurora DB engine, Region, and instance class support for Performance Insights.

For more information about Performance Insights, see Monitoring DB load with Performance Insights on Amazon RDS.

Database Insights

The standard mode of Database Insights is enabled by default for Aurora databases.

You can enhance the monitoring of your Aurora databases by enabling the advanced mode of Database Insights.

To control Database Insights mode, use the database_insights_mode property:

vpc = nil # AWSCDK::EC2::VPC

AWSCDK::RDS::DatabaseCluster.new(self, "Database", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.AURORA,
    vpc: vpc,
    # If you enable the advanced mode of Database Insights,
    # Performance Insights is enabled and you must set the `performanceInsightRetention` to 465(15 months).
    database_insights_mode: AWSCDK::RDS::DatabaseInsightsMode::ADVANCED,
    performance_insight_retention: AWSCDK::RDS::PerformanceInsightRetention::MONTHS_15,
    writer: AWSCDK::RDS::ClusterInstance.provisioned("Writer", {
        instance_type: AWSCDK::EC2::InstanceType.of(AWSCDK::EC2::InstanceClass::R7G, AWSCDK::EC2::InstanceSize::LARGE),
    }),
})

Database Insights is also supported for RDS instances:

vpc = nil # AWSCDK::EC2::VPC

AWSCDK::RDS::DatabaseInstance.new(self, "PostgresInstance", {
    engine: AWSCDK::RDS::DatabaseInstanceEngine.postgres({version: AWSCDK::RDS::PostgresEngineVersion.VER_17_5}),
    instance_type: AWSCDK::EC2::InstanceType.of(AWSCDK::EC2::InstanceClass::R5, AWSCDK::EC2::InstanceSize::LARGE),
    vpc: vpc,
    # If you enable the advanced mode of Database Insights,
    # Performance Insights is enabled and you must set the `performanceInsightRetention` to 465(15 months).
    database_insights_mode: AWSCDK::RDS::DatabaseInsightsMode::ADVANCED,
    performance_insight_retention: AWSCDK::RDS::PerformanceInsightRetention::MONTHS_15,
})

Visit CloudWatch Database Insights for more details.

Enhanced Monitoring

With Enhanced Monitoring, you can monitor the operating system of your DB instance in real time.

To enable Enhanced Monitoring for a clustered database, set the monitoring_interval property. This value is applied at instance level to all instances in the cluster by default.

If you want to enable enhanced monitoring at the cluster level, you can set the enable_cluster_level_enhanced_monitoring property to true. Note that you must set monitoring_interval when using enable_cluster_level_enhanced_monitoring

vpc = nil # AWSCDK::EC2::VPC

# Enable Enhanced Monitoring at instance level to all instances in the cluster
AWSCDK::RDS::DatabaseCluster.new(self, "Cluster", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_postgres({version: AWSCDK::RDS::AuroraPostgresEngineVersion.VER_16_1}),
    writer: AWSCDK::RDS::ClusterInstance.serverless_v2("writerInstance"),
    vpc: vpc,
    monitoring_interval: AWSCDK::Duration.seconds(5),
})

# Enable Enhanced Monitoring at the cluster level
AWSCDK::RDS::DatabaseCluster.new(self, "Cluster", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_postgres({version: AWSCDK::RDS::AuroraPostgresEngineVersion.VER_16_1}),
    writer: AWSCDK::RDS::ClusterInstance.serverless_v2("writerInstance"),
    vpc: vpc,
    monitoring_interval: AWSCDK::Duration.seconds(5),
    enable_cluster_level_enhanced_monitoring: true,
})

AWS CDK automatically generate the IAM role for Enhanced Monitoring. If you want to create the IAM role manually, you can use the monitoring_role property.

vpc = nil # AWSCDK::EC2::VPC
monitoring_role = nil # AWSCDK::IAM::Role


AWSCDK::RDS::DatabaseCluster.new(self, "Cluster", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_postgres({version: AWSCDK::RDS::AuroraPostgresEngineVersion.VER_16_1}),
    writer: AWSCDK::RDS::ClusterInstance.serverless_v2("writerInstance"),
    vpc: vpc,
    monitoring_interval: AWSCDK::Duration.seconds(5),
    monitoring_role: monitoring_role,
})

Extended Support

With Amazon RDS Extended Support, you can continue running your database on a major engine version past the RDS end of standard support date for an additional cost. To configure the life cycle type, use the engine_lifecycle_support property:

vpc = nil # AWSCDK::EC2::IVPC


AWSCDK::RDS::DatabaseCluster.new(self, "DatabaseCluster", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_mysql({version: AWSCDK::RDS::AuroraMysqlEngineVersion.VER_3_07_0}),
    writer: AWSCDK::RDS::ClusterInstance.serverless_v2("writerInstance"),
    vpc: vpc,
    engine_lifecycle_support: AWSCDK::RDS::EngineLifecycleSupport::OPEN_SOURCE_RDS_EXTENDED_SUPPORT,
})

AWSCDK::RDS::DatabaseInstance.new(self, "DatabaseInstance", {
    engine: AWSCDK::RDS::DatabaseInstanceEngine.mysql({version: AWSCDK::RDS::MysqlEngineVersion.VER_8_0_39}),
    instance_type: AWSCDK::EC2::InstanceType.of(AWSCDK::EC2::InstanceClass::R7G, AWSCDK::EC2::InstanceSize::LARGE),
    vpc: vpc,
    engine_lifecycle_support: AWSCDK::RDS::EngineLifecycleSupport::OPEN_SOURCE_RDS_EXTENDED_SUPPORT_DISABLED,
})

Importing existing DatabaseInstance

Lookup DatabaseInstance by instanceIdentifier

You can lookup an existing DatabaseInstance by its instanceIdentifier using DatabaseInstance.fromLookup(). This method returns an IDatabaseInstance.

Here's how DatabaseInstance.fromLookup() can be used:

my_user_role = nil # AWSCDK::IAM::Role


db_from_lookup = AWSCDK::RDS::DatabaseInstance.from_lookup(self, "dbFromLookup", {
    instance_identifier: "instanceId",
})

# Grant a connection
db_from_lookup.grant_connect(my_user_role, "my-user-id")

Importing existing DatabaseCluster

Lookup DatabaseCluster by clusterIdentifier

You can lookup an existing DatabaseCluster by its clusterIdentifier using DatabaseCluster.fromLookup(). This method returns an IDatabaseCluster.

Here's how DatabaseCluster.fromLookup() can be used:

my_user_role = nil # AWSCDK::IAM::Role


cluster_from_lookup = AWSCDK::RDS::DatabaseCluster.from_lookup(self, "ClusterFromLookup", {
    cluster_identifier: "my-cluster-id",
})

# Grant a connection
cluster_from_lookup.grant_connect(my_user_role, "my-user-id")

Limitless Database Cluster

Amazon Aurora PostgreSQL Limitless Database provides automated horizontal scaling to process millions of write transactions per second and manages petabytes of data while maintaining the simplicity of operating inside a single database.

The following example shows creating an Aurora PostgreSQL Limitless Database cluster:

vpc = nil # AWSCDK::EC2::IVPC


AWSCDK::RDS::DatabaseCluster.new(self, "LimitlessDatabaseCluster", {
    engine: AWSCDK::RDS::DatabaseClusterEngine.aurora_postgres({
        version: AWSCDK::RDS::AuroraPostgresEngineVersion.VER_16_4_LIMITLESS,
    }),
    vpc: vpc,
    cluster_scalability_type: AWSCDK::RDS::ClusterScalabilityType::LIMITLESS,
    # Requires enabling Performance Insights
    enable_performance_insights: true,
    performance_insight_retention: AWSCDK::RDS::PerformanceInsightRetention::MONTHS_1,
    # Requires enabling Enhanced Monitoring at the cluster level
    monitoring_interval: AWSCDK::Duration.minutes(1),
    enable_cluster_level_enhanced_monitoring: true,
    # Requires I/O optimized storage type
    storage_type: AWSCDK::RDS::DBClusterStorageType::AURORA_IOPT1,
    # Requires exporting the PostgreSQL log to Amazon CloudWatch Logs.
    cloudwatch_logs_exports: ["postgresql"],
})

API Reference

Classes 49

AuroraEngineVersionThe versions for the Aurora cluster engine (those returned by `DatabaseClusterEngine.auror AuroraMysqlEngineVersionThe versions for the Aurora MySQL cluster engine (those returned by `DatabaseClusterEngine AuroraPostgresEngineVersionThe versions for the Aurora PostgreSQL cluster engine (those returned by `DatabaseClusterE CaCertificateThe CA certificate used for a DB instance. CfnCustomDBEngineVersionCreates a custom DB engine version (CEV). CfnDBClusterThe `AWS::RDS::DBCluster` resource creates an Amazon Aurora DB cluster or Multi-AZ DB clus CfnDBClusterParameterGroupThe `AWS::RDS::DBClusterParameterGroup` resource creates a new Amazon RDS DB cluster param CfnDBInstanceThe `AWS::RDS::DBInstance` resource creates an Amazon DB instance. CfnDBParameterGroupThe `AWS::RDS::DBParameterGroup` resource creates a custom parameter group for an RDS data CfnDBProxyThe `AWS::RDS::DBProxy` resource creates or updates a DB proxy. CfnDBProxyEndpointThe `AWS::RDS::DBProxyEndpoint` resource creates or updates a DB proxy endpoint. CfnDBProxyTargetGroupThe `AWS::RDS::DBProxyTargetGroup` resource represents a set of RDS DB instances, Aurora D CfnDBSecurityGroupThe `AWS::RDS::DBSecurityGroup` resource creates or updates an Amazon RDS DB security grou CfnDBSecurityGroupIngressThe `AWS::RDS::DBSecurityGroupIngress` resource enables ingress to a DB security group usi CfnDBShardGroupCreates a new DB shard group for Aurora Limitless Database. CfnDBSubnetGroupThe `AWS::RDS::DBSubnetGroup` resource creates a database subnet group. CfnEventSubscriptionThe `AWS::RDS::EventSubscription` resource allows you to receive notifications for Amazon CfnGlobalClusterThe `AWS::RDS::GlobalCluster` resource creates or updates an Amazon Aurora global database CfnIntegrationA zero-ETL integration with Amazon Redshift. CfnOptionGroupThe `AWS::RDS::OptionGroup` resource creates or updates an option group, to enable and con ClusterInstanceCreate an RDS Aurora Cluster Instance. ClusterInstanceTypeThe type of Aurora Cluster Instance. CredentialsUsername and password combination. DatabaseClusterCreate a clustered database with a given number of instances. DatabaseClusterBaseA new or imported clustered database. DatabaseClusterEngineA database cluster engine. DatabaseClusterFromSnapshotA database cluster restored from a snapshot. DatabaseInstanceA database instance. DatabaseInstanceBaseA new or imported database instance. DatabaseInstanceEngineA database instance engine. DatabaseInstanceFromSnapshotA database instance restored from a snapshot. DatabaseInstanceReadReplicaA read replica database instance. DatabaseProxyRDS Database Proxy. DatabaseProxyEndpointRDS Database Proxy Endpoint. DatabaseSecretA database secret. EndpointConnection endpoint of a database cluster or instance. MariaDBEngineVersionThe versions for the MariaDB instance engines (those returned by `DatabaseInstanceEngine.m MysqlEngineVersionThe versions for the MySQL instance engines (those returned by `DatabaseInstanceEngine.mys OptionGroupAn option group. OracleEngineVersionThe versions for the Oracle instance engines. ParameterGroupA parameter group. PostgresEngineVersionThe versions for the PostgreSQL instance engines (those returned by `DatabaseInstanceEngin ProxyTargetProxy target: Instance or Cluster. ServerlessClusterCreate an Aurora Serverless v1 Cluster. ServerlessClusterFromSnapshotA Aurora Serverless v1 Cluster restored from a snapshot. SessionPinningFilterSessionPinningFilter. SnapshotCredentialsCredentials to update the password for a ``DatabaseInstanceFromSnapshot``. SqlServerEngineVersionThe versions for the SQL Server instance engines (those returned by `DatabaseInstanceEngin SubnetGroupClass for creating a RDS DB subnet group.

Interfaces 97

AuroraClusterEnginePropsCreation properties of the plain Aurora database cluster engine. AuroraMysqlClusterEnginePropsCreation properties of the Aurora MySQL database cluster engine. AuroraPostgresClusterEnginePropsCreation properties of the Aurora PostgreSQL database cluster engine. AuroraPostgresEngineFeaturesFeatures supported by this version of the Aurora Postgres cluster engine. BackupPropsBackup configuration for RDS databases. CfnCustomDBEngineVersionPropsProperties for defining a `CfnCustomDBEngineVersion`. CfnDBClusterParameterGroupPropsProperties for defining a `CfnDBClusterParameterGroup`. CfnDBClusterPropsProperties for defining a `CfnDBCluster`. CfnDBInstancePropsProperties for defining a `CfnDBInstance`. CfnDBParameterGroupPropsProperties for defining a `CfnDBParameterGroup`. CfnDBProxyEndpointPropsProperties for defining a `CfnDBProxyEndpoint`. CfnDBProxyPropsProperties for defining a `CfnDBProxy`. CfnDBProxyTargetGroupPropsProperties for defining a `CfnDBProxyTargetGroup`. CfnDBSecurityGroupIngressPropsProperties for defining a `CfnDBSecurityGroupIngress`. CfnDBSecurityGroupPropsProperties for defining a `CfnDBSecurityGroup`. CfnDBShardGroupPropsProperties for defining a `CfnDBShardGroup`. CfnDBSubnetGroupPropsProperties for defining a `CfnDBSubnetGroup`. CfnEventSubscriptionPropsProperties for defining a `CfnEventSubscription`. CfnGlobalClusterPropsProperties for defining a `CfnGlobalCluster`. CfnIntegrationPropsProperties for defining a `CfnIntegration`. CfnOptionGroupPropsProperties for defining a `CfnOptionGroup`. ClusterEngineBindOptionsThe extra options passed to the `IClusterEngine.bindToCluster` method. ClusterEngineConfigThe type returned from the `IClusterEngine.bindToCluster` method. ClusterEngineFeaturesRepresents Database Engine features. ClusterInstanceBindOptionsOptions for binding the instance to the cluster. ClusterInstanceOptionsCommon options for creating a cluster instance. ClusterInstancePropsCommon options for creating cluster instances (both serverless and provisioned). CommonRotationUserOptionsProperties common to single-user and multi-user rotation options. CredentialsBaseOptionsBase options for creating Credentials. CredentialsFromUsernameOptionsOptions for creating Credentials from a username. DatabaseClusterAttributesProperties that describe an existing cluster instance. DatabaseClusterFromSnapshotPropsProperties for ``DatabaseClusterFromSnapshot``. DatabaseClusterLookupOptionsProperties for looking up an existing DatabaseCluster. DatabaseClusterPropsProperties for a new database cluster. DatabaseInstanceAttributesProperties that describe an existing instance. DatabaseInstanceFromSnapshotPropsConstruction properties for a DatabaseInstanceFromSnapshot. DatabaseInstanceLookupOptionsProperties for looking up an existing DatabaseInstance. DatabaseInstanceNewPropsConstruction properties for a DatabaseInstanceNew. DatabaseInstancePropsConstruction properties for a DatabaseInstance. DatabaseInstanceReadReplicaPropsConstruction properties for a DatabaseInstanceReadReplica. DatabaseInstanceSourcePropsConstruction properties for a DatabaseInstanceSource. DatabaseProxyAttributesProperties that describe an existing DB Proxy. DatabaseProxyEndpointAttributesProperties that describe an existing DB Proxy Endpoint. DatabaseProxyEndpointOptionsOptions for a new DatabaseProxyEndpoint. DatabaseProxyEndpointPropsConstruction properties for a DatabaseProxyEndpoint. DatabaseProxyOptionsOptions for a new DatabaseProxy. DatabaseProxyPropsConstruction properties for a DatabaseProxy. DatabaseSecretPropsConstruction properties for a DatabaseSecret. EngineVersionA version of an engine - for either a cluster, or instance. IAuroraClusterInstanceAn Aurora Cluster Instance. IClusterEngineThe interface representing a database cluster (as opposed to instance) engine. IClusterInstanceRepresents an Aurora cluster instance This can be either a provisioned instance or a serve IDatabaseClusterCreate a clustered database with a given number of instances. IDatabaseInstanceA database instance. IDatabaseProxyDB Proxy. IDatabaseProxyEndpointA DB proxy endpoint. IEngineA common interface for database engines. IInstanceEngineInterface representing a database instance (as opposed to cluster) engine. InstanceEngineBindOptionsThe options passed to `IInstanceEngine.bind`. InstanceEngineConfigThe type returned from the `IInstanceEngine.bind` method. InstanceEngineFeaturesRepresents Database Engine features. InstancePropsInstance properties for database instances. IOptionGroupAn option group. IParameterGroupA parameter group. IServerlessClusterInterface representing a serverless database cluster. ISubnetGroupInterface for a subnet group. MariaDBInstanceEnginePropsProperties for MariaDB instance engines. MySqlInstanceEnginePropsProperties for MySQL instance engines. OptionConfigurationConfiguration properties for an option. OptionGroupPropsConstruction properties for an OptionGroup. OracleEeCdbInstanceEnginePropsProperties for Oracle Enterprise Edition (CDB) instance engines. OracleEeInstanceEnginePropsProperties for Oracle Enterprise Edition instance engines. OracleSe2CdbInstanceEnginePropsProperties for Oracle Standard Edition 2 (CDB) instance engines. OracleSe2InstanceEnginePropsProperties for Oracle Standard Edition 2 instance engines. ParameterGroupClusterBindOptionsOptions for `IParameterGroup.bindToCluster`. Empty for now, but can be extended later. ParameterGroupClusterConfigThe type returned from `IParameterGroup.bindToCluster`. ParameterGroupInstanceBindOptionsOptions for `IParameterGroup.bindToInstance`. Empty for now, but can be extended later. ParameterGroupInstanceConfigThe type returned from `IParameterGroup.bindToInstance`. ParameterGroupPropsProperties for a parameter group. PostgresEngineFeaturesFeatures supported by the Postgres database engine. PostgresInstanceEnginePropsProperties for PostgreSQL instance engines. ProcessorFeaturesThe processor features. ProvisionedClusterInstancePropsOptions for creating a provisioned instance. ProxyTargetConfigThe result of binding a `ProxyTarget` to a `DatabaseProxy`. RotationMultiUserOptionsOptions to add the multi user rotation. RotationSingleUserOptionsOptions to add the multi user rotation. ServerlessClusterAttributesProperties that describe an existing cluster instance. ServerlessClusterFromSnapshotPropsProperties for ``ServerlessClusterFromSnapshot``. ServerlessClusterPropsProperties for a new Aurora Serverless v1 Cluster. ServerlessScalingOptionsOptions for configuring scaling on an Aurora Serverless v1 Cluster. ServerlessV2ClusterInstancePropsOptions for creating a serverless v2 instance. SnapshotCredentialsFromGeneratedPasswordOptionsOptions used in the `SnapshotCredentials.fromGeneratedPassword` method. SqlServerEeInstanceEnginePropsProperties for SQL Server Enterprise Edition instance engines. SqlServerExInstanceEnginePropsProperties for SQL Server Express Edition instance engines. SqlServerSeInstanceEnginePropsProperties for SQL Server Standard Edition instance engines. SqlServerWebInstanceEnginePropsProperties for SQL Server Web Edition instance engines. SubnetGroupPropsProperties for creating a SubnetGroup.

Enums 16

AuroraCapacityUnitAurora capacity units (ACUs). ClientPasswordAuthTypeClient password authentication type used by a proxy to log in as a specific database user. ClusterScailabilityTypeThe scalability mode of the Aurora DB cluster. ClusterScalabilityTypeThe scalability mode of the Aurora DB cluster. DatabaseInsightsModeThe database insights mode. DBClusterStorageTypeThe storage type to be associated with the DB cluster. DefaultAuthSchemeThe default authentication scheme that the proxy uses for client connections to the proxy EngineLifecycleSupportEngine lifecycle support for Amazon RDS and Amazon Aurora. InstanceType InstanceUpdateBehaviourThe orchestration of updates of multiple instances. LicenseModelThe license model. NetworkTypeThe network type of the DB instance. PerformanceInsightRetentionThe retention period for Performance Insight data, in days. ProxyEndpointTargetRoleA value that indicates whether the DB proxy endpoint can be used for read/write or read-on StorageTypeThe type of storage. TimeoutActionTimeoutAction defines the action to take when a timeout occurs if a scaling point is not f