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

0

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개 답변
0

Hey Dilshan,

If you look at https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Limits.html, 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
답변함 3달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠