mysterious-family-43099
04/13/2023, 4:56 PMconst instance = new aws.rds.Instance(instanceName, {
allocatedStorage,
// This is the availability zone of the subnet.
// For db.t3.micro instances, you can only use us-west-2a or us-west-2b.
availabilityZone: 'us-west-2a',
dbSubnetGroupName: subnetGroup.name,
engine: 'postgres',
// 15.2 is the newest version supported on RDS as of now.
// <https://docs.aws.amazon.com/AmazonRDS/latest/PostgreSQLReleaseNotes/postgresql-versions.html#postgresql-versions-version14>
engineVersion: '15.2',
allowMajorVersionUpgrade: true,
instanceClass: instanceType,
// <https://aws.amazon.com/about-aws/whats-new/2018/09/amazon-rds-now-provides-database-deletion-protection/>
deletionProtection,
applyImmediately: true,
skipFinalSnapshot,
backupRetentionPeriod,
backupWindow: '00:00-01:00',
maintenanceWindow: 'sun:03:00-sun:04:00',
finalSnapshotIdentifier: `${instanceName}-final-snapshot-${Date.now()}`,
password: dbPassword,
username: dbUsername,
vpcSecurityGroupIds: [securityGroup.id],
tags: {
Name: instanceName,
Stack: stackName,
},
});
const sharedCoreStackRef = new pulumi.StackReference("yoz/shared-core/shared-core");
const alarmTopicArn = sharedCoreStackRef.requireOutput('alarmTopicArn');
// TODO: Consider adding alarms for IOPS & throughput
new aws.cloudwatch.MetricAlarm(`${stackName}-cpu-alarm`, {
comparisonOperator: "GreaterThanOrEqualToThreshold",
evaluationPeriods: 2,
metricName: "CPUUtilization",
namespace: "AWS/RDS",
period: 120,
statistic: "Average",
threshold: 75,
alarmDescription: "Monitors CPU utilization",
dimensions: {
DBInstanceIdentifier: instance.dbName,
},
alarmActions: [alarmTopicArn]
});
new aws.cloudwatch.MetricAlarm(`${stackName}-connections-alarm`, {
comparisonOperator: "GreaterThanOrEqualToThreshold",
evaluationPeriods: 2,
metricName: "DatabaseConnections",
namespace: "AWS/RDS",
period: 120,
statistic: "Average",
threshold: Math.round(maxDatabaseConnections * 0.75),
alarmDescription: "Monitors database connections",
dimensions: {
DBInstanceIdentifier: instance.dbName,
},
alarmActions: [alarmTopicArn]
});
new aws.cloudwatch.MetricAlarm(`${stackName}-disk-alarm`, {
comparisonOperator: "LessThanOrEqualToThreshold",
evaluationPeriods: 2,
metricName: "FreeStorageSpace",
namespace: "AWS/RDS",
period: 120,
statistic: "Average",
threshold: Math.round((allocatedStorage ** 9) * 0.25),
alarmDescription: "Monitors free storage space left",
dimensions: {
DBInstanceIdentifier: instance.dbName,
},
alarmActions: [alarmTopicArn]
});
new aws.cloudwatch.MetricAlarm(`${stackName}-memory-alarm`, {
comparisonOperator: "LessThanOrEqualToThreshold",
evaluationPeriods: 2,
metricName: "FreeableMemory",
namespace: "AWS/RDS",
period: 120,
statistic: "Average",
threshold: Math.round((allocatedMemory ** 9) * 0.15),
alarmDescription: "Monitors free memory left",
dimensions: {
DBInstanceIdentifier: instance.dbName,
},
alarmActions: [alarmTopicArn]
});