Use Amazon CloudFormation for Auto Scaling policies
This snippet shows how to create a target tracking policy and apply it to an
AWS::ElastiCache::ReplicationGroup resource using the AWS::ApplicationAutoScaling::ScalableTarget resource. It uses the
Fn::Join and Ref intrinsic functions to construct the ResourceId
property with the logical name of the
AWS::ElastiCache::ReplicationGroup
resource that is specified in
the same template.
ScalingTarget: Type: 'AWS::ApplicationAutoScaling::ScalableTarget' Properties: MaxCapacity: 3 MinCapacity: 1 ResourceId: !Sub replication-group/${logicalName} ScalableDimension: 'elasticache:replication-group:NodeGroups' ServiceNamespace: elasticache RoleARN: !Sub "arn:aws:iam::${AWS::AccountId}:role/aws-service-role/elasticache.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_ElastiCacheRG" ScalingPolicy: Type: "AWS::ApplicationAutoScaling::ScalingPolicy" Properties: ScalingTargetId: !Ref ScalingTarget ServiceNamespace: elasticache PolicyName: testpolicy PolicyType: TargetTrackingScaling ScalableDimension: 'elasticache:replication-group:NodeGroups' TargetTrackingScalingPolicyConfiguration: PredefinedMetricSpecification: PredefinedMetricType: ElastiCachePrimaryEngineCPUUtilization TargetValue: 40