Skip to content

Commit 7f54ed6

Browse files
authoredDec 10, 2021
feat(aws-applicationautoscaling): enabling autoscaling for ElastiCache Redis cluster (#17919)
Following the recently released support for autoscaling in ElastiCache Redis cluster, I'd like to use CDK in order to manage the infrastructure. The only required change is to introduce a new enum value for 'elasticache' key ([cloudformation doc](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-applicationautoscaling-scalabletarget.html#cfn-applicationautoscaling-scalabletarget-servicenamespace)), however to improve dev experience I've introduced three new `PredefinedMetricType` following [cloudformation docs](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-applicationautoscaling-scalingpolicy-predefinedmetricspecification.html#cfn-applicationautoscaling-scalingpolicy-predefinedmetricspecification-predefinedmetrictype) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 203c42b commit 7f54ed6

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed
 

‎packages/@aws-cdk/aws-applicationautoscaling/README.md

+17
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,20 @@ target.scaleToTrackMetric('PceTracking', {
206206
predefinedMetric: appscaling.PredefinedMetric.LAMBDA_PROVISIONED_CONCURRENCY_UTILIZATION,
207207
})
208208
```
209+
210+
### ElastiCache Redis shards scaling with target value
211+
212+
```ts
213+
const shardsScalableTarget = new appscaling.ScalableTarget(this, 'ElastiCacheRedisShardsScalableTarget', {
214+
serviceNamespace: appscaling.ServiceNamespace.ELASTICACHE,
215+
scalableDimension: 'elasticache:replication-group:NodeGroups',
216+
minCapacity: 2,
217+
maxCapacity: 10,
218+
resourceId: 'replication-group/main-cluster',
219+
});
220+
221+
shardsScalableTarget.scaleToTrackMetric('ElastiCacheRedisShardsCPUUtilization', {
222+
targetValue: 20,
223+
predefinedMetric: appscaling.PredefinedMetric.ELASTICACHE_PRIMARY_ENGINE_CPU_UTILIZATION,
224+
});
225+
```

‎packages/@aws-cdk/aws-applicationautoscaling/lib/scalable-target.ts

+5
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,9 @@ export enum ServiceNamespace {
281281
* Kafka
282282
*/
283283
KAFKA = 'kafka',
284+
285+
/**
286+
* ElastiCache
287+
*/
288+
ELASTICACHE = 'elasticache',
284289
}

‎packages/@aws-cdk/aws-applicationautoscaling/lib/target-tracking-scaling-policy.ts

+15
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,19 @@ export enum PredefinedMetric {
243243
* @see https://docs.aws.amazon.com/autoscaling/application/APIReference/API_PredefinedMetricSpecification.html
244244
*/
245245
KAFKA_BROKER_STORAGE_UTILIZATION = 'KafkaBrokerStorageUtilization',
246+
/**
247+
* ELASTIC_CACHE_PRIMARY_ENGINE_CPU_UTILIZATION
248+
* @see https://docs.aws.amazon.com/autoscaling/application/APIReference/API_PredefinedMetricSpecification.html
249+
*/
250+
ELASTICACHE_PRIMARY_ENGINE_CPU_UTILIZATION = 'ElastiCachePrimaryEngineCPUUtilization',
251+
/**
252+
* ELASTIC_CACHE_REPLICA_ENGINE_CPU_UTILIZATION
253+
* @see https://docs.aws.amazon.com/autoscaling/application/APIReference/API_PredefinedMetricSpecification.html
254+
*/
255+
ELASTICACHE_REPLICA_ENGINE_CPU_UTILIZATION = 'ElastiCacheReplicaEngineCPUUtilization',
256+
/**
257+
* ELASTIC_CACHE_REPLICA_ENGINE_CPU_UTILIZATION
258+
* @see https://docs.aws.amazon.com/autoscaling/application/APIReference/API_PredefinedMetricSpecification.html
259+
*/
260+
ELASTICACHE_DATABASE_MEMORY_USAGE_COUNTED_FOR_EVICT_PERCENTAGE = 'ElastiCacheDatabaseMemoryUsageCountedForEvictPercentage',
246261
}

‎packages/@aws-cdk/aws-applicationautoscaling/test/scalable-target.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ describe('scalable target', () => {
144144
expect(appscaling.ServiceNamespace.LAMBDA).toEqual('lambda');
145145
expect(appscaling.ServiceNamespace.RDS).toEqual('rds');
146146
expect(appscaling.ServiceNamespace.SAGEMAKER).toEqual('sagemaker');
147+
expect(appscaling.ServiceNamespace.ELASTICACHE).toEqual('elasticache');
147148
});
148149

149150
test('create scalable target with negative minCapacity throws error', () => {

0 commit comments

Comments
 (0)
Please sign in to comment.