应用扩缩策略 - Amazon ElastiCache

应用扩缩策略

在为集群注册 ElastiCache for Valkey and Redis OSS 自动扩缩并定义扩缩策略后,您可以将扩缩策略应用于已注册的集群。要将扩缩策略应用于 ElastiCache for Redis OSS 集群,您可以使用 AWS CLI 或 Application Auto Scaling API。

使用 AWS CLI 应用扩展策略

要将扩缩策略应用于 ElastiCache for Valkey and Redis OSS 集群,请使用具有以下参数的 put-scaling-policy 命令:

  • --policy-name – 扩展策略的名称。

  • --policy-type – 将此值设置为 TargetTrackingScaling

  • --resource-id – 资源标识符。对于该参数,资源类型为 ReplicationGroup,唯一标识符为集群的名称,例如 replication-group/myscalablecluster

  • --service-namespace – 将此值设置为 elasticache

  • --scalable-dimension – 将此值设置为 elasticache:replication-group:NodeGroups

  • --target-tracking-scaling-policy-configuration – 用于集群的目标跟踪扩缩策略配置。

在以下示例中,您使用 ElastiCache 自动扩缩对名为 myscalablecluster 的 ElastiCache for Valkey and Redis OSS 集群应用名为 myscalablepolicy 的目标跟踪扩缩策略。为此,请使用在名为 config.json 的文件中保存的策略配置。

对于 Linux、macOS 或 Unix:

aws application-autoscaling put-scaling-policy \ --policy-name myscalablepolicy \ --policy-type TargetTrackingScaling \ --resource-id replication-group/myscalablecluster \ --service-namespace elasticache \ --scalable-dimension elasticache:replication-group:NodeGroups \ --target-tracking-scaling-policy-configuration file://config.json

对于 Windows:

aws application-autoscaling put-scaling-policy ^ --policy-name myscalablepolicy ^ --policy-type TargetTrackingScaling ^ --resource-id replication-group/myscalablecluster ^ --service-namespace elasticache ^ --scalable-dimension elasticache:replication-group:NodeGroups ^ --target-tracking-scaling-policy-configuration file://config.json

使用 API 应用扩展策略

要将扩缩策略应用于 ElastiCache for Valkey and Redis OSS 集群,请使用具有以下参数的 PutScalingPolicy AWS CLI 命令:

  • --policy-name – 扩展策略的名称。

  • --resource-id – 资源标识符。对于该参数,资源类型为 ReplicationGroup,唯一标识符为集群的名称,例如 replication-group/myscalablecluster

  • --service-namespace – 将此值设置为 elasticache

  • --scalable-dimension – 将此值设置为 elasticache:replication-group:NodeGroups

  • --target-tracking-scaling-policy-configuration – 用于集群的目标跟踪扩缩策略配置。

在以下示例中,您使用 ElastiCache 自动扩缩对名为 myscalablecluster 的 ElastiCache 集群应用名为 myscalablepolicy 的目标跟踪扩缩策略。您使用的策略配置基于 ElastiCachePrimaryEngineCPUUtilization 预定义指标。

POST / HTTP/1.1 Host: autoscaling.us-east-2.amazonaws.com Accept-Encoding: identity Content-Length: 219 X-Amz-Target: AnyScaleFrontendService.PutScalingPolicy X-Amz-Date: 20160506T182145Z User-Agent: aws-cli/1.10.23 Python/2.7.11 Darwin/15.4.0 botocore/1.4.8 Content-Type: application/x-amz-json-1.1 Authorization: AUTHPARAMS { "PolicyName": "myscalablepolicy", "ServiceNamespace": "elasticache", "ResourceId": "replication-group/myscalablecluster", "ScalableDimension": "elasticache:replication-group:NodeGroups", "PolicyType": "TargetTrackingScaling", "TargetTrackingScalingPolicyConfiguration": { "TargetValue": 40.0, "PredefinedMetricSpecification": { "PredefinedMetricType": "ElastiCachePrimaryEngineCPUUtilization" } } }