After diving into using CDK, I am a newcomer to programming.
I have successfully set up a basic environment including an EC2 instance, a VPC with 2 subnets, and an RDS instance. Additionally, I've configured CloudWatch Alarms to monitor the CPU usage of the RDS DB:
const CPUUsage = new cw.Alarm(this, 'CPUUsage', {
metric: cpuUsage,
threshold: 4,
evaluationPeriods: 2,
alarmName: 'DB CPU Usage',
});
My goal is to create alarms that can automatically restart instances (one for EC2 and one for RDS) if their CPU usage exceeds a certain percentage (e.g., 4).
However, I have yet to find a solution to automatically restarting the RDS instance. For the EC2 instance, I came across the InitCommand class, but it doesn't fully meet my requirements as I prefer to avoid using shell commands in the code unless absolutely necessary.
Your assistance on this matter would be greatly appreciated. Thank you!