How to get memory capacity of an instance from RDS cluster?


Hi Team,

I have my rds cluster and a cloudwatch alarm as in the below code. What I'm trying to do is to apply the threshold in the alarm to match 75% value from MAXIMUM DB CONNECTION level of database cluster instance.

Since there is a co-relation in between the instance type and maximum number of database connections, I've tried several methods to access the database instance type but none of them worked. Any clue?

const TestCluster = new rds.DatabaseCluster(this, 'TestDbCluster', { engine: rds.DatabaseClusterEngine.auroraMysql({version: rds.AuroraMysqlEngineVersion.VER_2_09_2}), instances: 1, instanceProps: { instanceType: ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.MEDIUM), vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE_ISOLATED }, vpc: vpc, }, clusterIdentifier: 'TestDbCluster', })

const ConnectionsMetric = TestCluster.metricDatabaseConnections() const dbConnectionsAlarm = ConnectionsMetric.createAlarm(this, 'TestAlarm', { alarmName: DB-DbConnections-Alarm, threshold: ???, evaluationPeriods: 1 })

1 Answer

Hey Dilshan,

If you look at, you going to see that:

The maximum number of simultaneous database connections varies by the DB engine type and the memory allocation for the DB instance class. The maximum number of connections is generally set in the parameter group associated with the DB instance. The exception is Microsoft SQL Server, where it is set in the server properties for the DB instance in SQL Server Management Studio (SSMS).

Having said that, In AWS CDK, you can't directly access the maximum number of database connections specific to an instance type at runtime because the CDK constructs are resolved during synthesis time (when you run cdk deploy), which is before the resource is actually created in AWS. This max connections value is also not exposed directly via the CloudFormation resources that CDK encapsulates.

However, you could create a mapping structure in your CDK code that hardcodes the instance type and the max connections. You can then look up the threshold based on the used instance type during CDK synthesis.

const maxConnectionsByInstanceType = {
    't3.medium': 1000,
    // other instance types...

const instanceType = 't3.medium'; // this would come from your actual instance declaration

const maxConnections = maxConnectionsByInstanceType[instanceType];
const thresholdValue = maxConnections * 0.75;

const dbConnectionsAlarm = ConnectionsMetric.createAlarm(this, 'TestAlarm', {
    alarmName: 'DB-DbConnections-Alarm',
    threshold: thresholdValue,
    evaluationPeriods: 1

Any approach you use will need to account for both and should be cross-checked against the official AWS documentation for RDS limits. Please note that none of these strategies will automatically adjust the threshold if AWS changes the connection limits for an RDS instance type. This aspect would still need to be manually managed.

profile picture
answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions