Create Predictive Scaling Policy

Following up with your scenario, one of the requirements is to reduce the impact of time the application takes to become ready.

Predictive scaling has a SchedulingBufferTime parameter that allows instances to launch in advance. For example, the forecast says to add capacity at 10:00 AM, and you choose to pre-launch instances by 5 minutes. In that case, the instances will be launched at 9:55 AM. The intention is to give the instances time to be initialized..

Create the predictive scaling policy

  1. In Cloud9 IDE terminal, check you’re at this directory ec2-spot-workshops/workshops/efficient-and-resilient-ec2-auto-scaling

  2. Review the policy configuration file and note how the custom metrics have been used in it.

cat ./policy-config.json

Note this section in the outcome, what effect do you think the parameter MaxCapacityBreachBehavior could have on the Auto Scaling group capacity?

Show answer

    "Mode": "ForecastAndScale",
    "SchedulingBufferTime": 300,
    "MaxCapacityBreachBehavior": "HonorMaxCapacity"
  1. Run this command to create the policy with the custom metrics and attach it to the auto scaling group.
aws autoscaling put-scaling-policy --policy-name workshop-predictive-scaling-policy \
  --auto-scaling-group-name "ec2-workshop-asg" --policy-type PredictiveScaling \
  --predictive-scaling-configuration file://policy-config.json

If successful, the command should return the created policy ARN.

{
    "PolicyARN": "arn:aws:autoscaling:ap-southeast-2:115751184547:scalingPolicy:df0e550e-b0d6-4924-8663-d394de77b0e3:autoScalingGroupName/ec2-workshop-asg:policyName/workshop-predictive-scaling-policy",
    "Alarms": []
}

To edit a predictive scaling policy that uses customized metrics, you must use the AWS CLI or an SDK. Console support for customized metrics will be available soon.