Skip to content

Commit

Permalink
feat(aws-applicationautoscaling): enabling autoscaling for ElastiCach…
Browse files Browse the repository at this point in the history
…e 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*
  • Loading branch information
astrohome authored Dec 10, 2021
1 parent 203c42b commit 7f54ed6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/@aws-cdk/aws-applicationautoscaling/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,20 @@ target.scaleToTrackMetric('PceTracking', {
predefinedMetric: appscaling.PredefinedMetric.LAMBDA_PROVISIONED_CONCURRENCY_UTILIZATION,
})
```

### ElastiCache Redis shards scaling with target value

```ts
const shardsScalableTarget = new appscaling.ScalableTarget(this, 'ElastiCacheRedisShardsScalableTarget', {
serviceNamespace: appscaling.ServiceNamespace.ELASTICACHE,
scalableDimension: 'elasticache:replication-group:NodeGroups',
minCapacity: 2,
maxCapacity: 10,
resourceId: 'replication-group/main-cluster',
});

shardsScalableTarget.scaleToTrackMetric('ElastiCacheRedisShardsCPUUtilization', {
targetValue: 20,
predefinedMetric: appscaling.PredefinedMetric.ELASTICACHE_PRIMARY_ENGINE_CPU_UTILIZATION,
});
```
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,9 @@ export enum ServiceNamespace {
* Kafka
*/
KAFKA = 'kafka',

/**
* ElastiCache
*/
ELASTICACHE = 'elasticache',
}
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,19 @@ export enum PredefinedMetric {
* @see https://docs.aws.amazon.com/autoscaling/application/APIReference/API_PredefinedMetricSpecification.html
*/
KAFKA_BROKER_STORAGE_UTILIZATION = 'KafkaBrokerStorageUtilization',
/**
* ELASTIC_CACHE_PRIMARY_ENGINE_CPU_UTILIZATION
* @see https://docs.aws.amazon.com/autoscaling/application/APIReference/API_PredefinedMetricSpecification.html
*/
ELASTICACHE_PRIMARY_ENGINE_CPU_UTILIZATION = 'ElastiCachePrimaryEngineCPUUtilization',
/**
* ELASTIC_CACHE_REPLICA_ENGINE_CPU_UTILIZATION
* @see https://docs.aws.amazon.com/autoscaling/application/APIReference/API_PredefinedMetricSpecification.html
*/
ELASTICACHE_REPLICA_ENGINE_CPU_UTILIZATION = 'ElastiCacheReplicaEngineCPUUtilization',
/**
* ELASTIC_CACHE_REPLICA_ENGINE_CPU_UTILIZATION
* @see https://docs.aws.amazon.com/autoscaling/application/APIReference/API_PredefinedMetricSpecification.html
*/
ELASTICACHE_DATABASE_MEMORY_USAGE_COUNTED_FOR_EVICT_PERCENTAGE = 'ElastiCacheDatabaseMemoryUsageCountedForEvictPercentage',
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ describe('scalable target', () => {
expect(appscaling.ServiceNamespace.LAMBDA).toEqual('lambda');
expect(appscaling.ServiceNamespace.RDS).toEqual('rds');
expect(appscaling.ServiceNamespace.SAGEMAKER).toEqual('sagemaker');
expect(appscaling.ServiceNamespace.ELASTICACHE).toEqual('elasticache');
});

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

0 comments on commit 7f54ed6

Please sign in to comment.