creating auto scaling policies for Replication Groups in ElastiCacheTypeScript
Sure, in order to create auto scaling policies for replication groups in ElastiCache, you should focus on two of AWS services: ElastiCache to manage the replication group and CloudWatch to create the scaling policies.
In your Pulumi program, you are going to use
aws.elasticache.ReplicationGroupto create replication group and
aws.cloudwatch.MetricAlarmto create auto-scaling policies. After creating the
aws.elasticache.ReplicationGroup, you will use its
arnto attach alarms for it.
Let's take a look at the TypeScript program which accomplishes the goal:
In this code, first, an ElastiCache replication group is created with the provided configuration options. The Group includes two node groups, and each group has two replicas. They're using the "cache.t2.small" instance type and running the Redis engine.
aws.cloudwatch.MetricAlarmis used to create two alarms for the replication group, one for high CPU usage and one for low CPU usage. The
cpuMetricAlarmHighalarms when CPU utilization exceeds 70% for 2 periods of 120 seconds and
cpuMetricAlarmLowalarms when CPU utilization falls below 30% for the same period.
The replication group identifier is exported as a stack output for use in other programs or for querying with the Pulumi CLI.
The metric alarms could be triggered to execute the respective actions when the CPU usage goes above or below the specified thresholds. However, the action pointers in these cases are just referencing the replication group which is not a meaningful operation. Likely you will want to adjust these to point to the appropriate Auto Scaling Policy. Unfortunately, ElastiCache doesn't natively support auto-scaling in AWS. But an AWS Lambda function can be used as a workaround to resize the ElastiCache cluster upon certain CloudWatch alarm triggers.