# NOT RUN {
# The following example applies a target tracking scaling policy with a
# predefined metric specification to an Amazon ECS service called web-app
# in the default cluster. The policy keeps the average CPU utilization of
# the service at 75 percent, with scale-out and scale-in cooldown periods
# of 60 seconds.
# }
# NOT RUN {
svc$put_scaling_policy(
PolicyName = "cpu75-target-tracking-scaling-policy",
PolicyType = "TargetTrackingScaling",
ResourceId = "service/default/web-app",
ScalableDimension = "ecs:service:DesiredCount",
ServiceNamespace = "ecs",
TargetTrackingScalingPolicyConfiguration = list(
PredefinedMetricSpecification = list(
PredefinedMetricType = "ECSServiceAverageCPUUtilization"
),
ScaleInCooldown = 60L,
ScaleOutCooldown = 60L,
TargetValue = 75L
)
)
# }
# NOT RUN {
# The following example applies a target tracking scaling policy with a
# customized metric specification to an Amazon ECS service called web-app
# in the default cluster. The policy keeps the average utilization of the
# service at 75 percent, with scale-out and scale-in cooldown periods of
# 60 seconds.
# }
# NOT RUN {
svc$put_scaling_policy(
PolicyName = "cms75-target-tracking-scaling-policy",
PolicyType = "TargetTrackingScaling",
ResourceId = "service/default/web-app",
ScalableDimension = "ecs:service:DesiredCount",
ServiceNamespace = "ecs",
TargetTrackingScalingPolicyConfiguration = list(
CustomizedMetricSpecification = list(
Dimensions = list(
list(
Name = "MyOptionalMetricDimensionName",
Value = "MyOptionalMetricDimensionValue"
)
),
MetricName = "MyUtilizationMetric",
Namespace = "MyNamespace",
Statistic = "Average",
Unit = "Percent"
),
ScaleInCooldown = 60L,
ScaleOutCooldown = 60L,
TargetValue = 75L
)
)
# }
# NOT RUN {
# The following example applies a target tracking scaling policy to an
# Amazon ECS service called web-app in the default cluster. The policy is
# used to scale out the ECS service when the RequestCountPerTarget metric
# from the Application Load Balancer exceeds the threshold.
# }
# NOT RUN {
svc$put_scaling_policy(
PolicyName = "alb-scale-out-target-tracking-scaling-policy",
PolicyType = "TargetTrackingScaling",
ResourceId = "service/default/web-app",
ScalableDimension = "ecs:service:DesiredCount",
ServiceNamespace = "ecs",
TargetTrackingScalingPolicyConfiguration = list(
DisableScaleIn = TRUE,
PredefinedMetricSpecification = list(
PredefinedMetricType = "ALBRequestCountPerTarget",
ResourceLabel = "app/EC2Co-EcsEl-1TKLTMITMM0EO/f37c06a68c1748aa/targetgroup/EC2Co-Defa..."
),
ScaleInCooldown = 60L,
ScaleOutCooldown = 60L,
TargetValue = 1000L
)
)
# }
# NOT RUN {
# This example applies a step scaling policy to an Amazon ECS service
# called web-app in the default cluster. The policy increases the desired
# count of the service by 200%, with a cool down period of 60 seconds.
# }
# NOT RUN {
svc$put_scaling_policy(
PolicyName = "web-app-cpu-gt-75",
PolicyType = "StepScaling",
ResourceId = "service/default/web-app",
ScalableDimension = "ecs:service:DesiredCount",
ServiceNamespace = "ecs",
StepScalingPolicyConfiguration = list(
AdjustmentType = "PercentChangeInCapacity",
Cooldown = 60L,
StepAdjustments = list(
list(
MetricIntervalLowerBound = 0L,
ScalingAdjustment = 200L
)
)
)
)
# }
# NOT RUN {
# This example applies a step scaling policy to an Amazon EC2 Spot fleet.
# The policy increases the target capacity of the spot fleet by 200%, with
# a cool down period of 180 seconds.",
#
# }
# NOT RUN {
svc$put_scaling_policy(
PolicyName = "fleet-cpu-gt-75",
PolicyType = "StepScaling",
ResourceId = "spot-fleet-request/sfr-45e69d8a-be48-4539-bbf3-3464e99c50c3",
ScalableDimension = "ec2:spot-fleet-request:TargetCapacity",
ServiceNamespace = "ec2",
StepScalingPolicyConfiguration = list(
AdjustmentType = "PercentChangeInCapacity",
Cooldown = 180L,
StepAdjustments = list(
list(
MetricIntervalLowerBound = 0L,
ScalingAdjustment = 200L
)
)
)
)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab