01 Run get-auto-scaling-group-recommendations command (OSX/Linux/UNIX) to retrieve the Amazon Resource Name (ARN) of each under-provisioned or over-provisioned EC2 instance identified in the selected AWS region (i.e. Asia Pacific - Sydney region):
aws compute-optimizer get-auto-scaling-group-recommendations
--region ap-southeast-2
--filters name=Finding,values=NotOptimized
--query 'autoScalingGroupRecommendations[*].autoScalingGroupArn'
02 The command output should return the requested Amazon Resource Name(s):
[
"arn:aws:autoscaling:us-east-1:123456789012:autoScalingGroup:abcd1234-abcd-1234-abcd-1234abcd1234:autoScalingGroupName/cc-project5-web-asg",
"arn:aws:autoscaling:us-east-1:123456789012:autoScalingGroup:1234abcd-1234-abcd-1234-abcd1234abcd:autoScalingGroupName/cc-frontend-app-asg"
]
03 Run get-auto-scaling-group-recommendations command (OSX/Linux/UNIX) using the ARN of the under-optimized Auto Scaling group that you want to optimize as identifier parameter, to describe the optimization recommendations available for the selected Amazon EC2 Auto Scaling group:
aws compute-optimizer get-auto-scaling-group-recommendations
--region ap-southeast-2
--auto-scaling-group-arns arn:aws:autoscaling:us-east-1:123456789012:autoScalingGroup:abcd1234-abcd-1234-abcd-1234abcd1234:autoScalingGroupName/cc-project5-web-asg
--query 'autoScalingGroupRecommendations[*]'
04 The command output should return the Compute Optimizer recommendations for the selected resource:
[
{
"accountId": "123456789012",
"autoScalingGroupArn": "arn:aws:autoscaling:us-east-1:123456789012:autoScalingGroup:abcd1234-abcd-1234-abcd-1234abcd1234:autoScalingGroupName/cc-project5-web-asg",
"autoScalingGroupName": "cc-project5-web-asg",
"currentConfiguration": {
"desiredCapacity": 1,
"instanceType": "c5.2xlarge",
"maxSize": 1,
"minSize": 1
},
"finding": "NOT_OPTIMIZED",
"lastRefreshTimestamp": 1605863334.320,
"lookBackPeriodInDays": 14.0,
"recommendationOptions": [
{
"configuration": {
"desiredCapacity": 1,
"instanceType": "c5.xlarge",
"maxSize": 1,
"minSize": 1
},
"performanceRisk": 1.0,
"projectedUtilizationMetrics": [
{
"name": "CPU",
"statistic": "MAXIMUM",
"value": 44.83870967741935
}
],
"rank": 1
}
],
"utilizationMetrics": [
{
"name": "cpi",
"statistic": "MAXIMUM",
"value": 50
}
]
}
]
05 Based on the information returned at the previous step by the get-auto-scaling-group-recommendations command output, review the optimization recommendations by analyzing the finding properties listed below. Review each option to identify the optimization recommendation that works best for you. When comparing Auto Scaling group instance configurations and determining which one best suits your workload needs, weigh the possible validation efforts against the benefits. Decide whether to optimize for performance improvement, for cost reduction, or for a combination of these two:
- "finding" - the finding classification returned for the selected Auto Scaling group (ASG).
- "autoScalingGroupName" - the name of the selected ASG.
- "currentConfiguration.instanceType" – the instance type used by the current group configuration.
- "lookBackPeriodInDays" - the number of days for which utilization metrics were analyzed for the selected ASG.
- "recommendationOptions[].instanceType" - the instance type recommended for the Auto Scaling group optimization.
- "recommendationOptions[].rank" - the rank of the instance recommendation option. The top recommendation option is ranked as 1.
- "recommendationOptions[].projectedUtilizationMetrics" - information that describes the projected utilization metrics of the instance recommendation option.
- "recommendationOptions[].performanceRisk" - the performance risk of the ASG recommendation option. The performance risk represents the likelihood of the recommended configuration not meeting the performance requirement of your workload. The lowest performance risk is categorized as 0, and the highest as 5.
06 Run describe-auto-scaling-groups command (OSX/Linux/UNIX) to describe the launch template associated with the Auto Scaling group (ASG) that you want to optimize:
aws autoscaling describe-auto-scaling-groups
--region us-east-1
--auto-scaling-group-name cc-project5-web-asg
--query 'AutoScalingGroups[*].LaunchTemplate'
07 The command output should return the requested ASG information:
[
{
"LaunchTemplateName": "cc-web-asg-launch-template",
"Version": "2",
"LaunchTemplateId": "lt-0abcd1234abcd1234"
}
]
08 Run create-launch-template-version command (OSX/Linux/UNIX) using the ID of the ASG launch template described at the previous step as identifier parameter, to create a new version for the selected launch template. The --source-version parameter value represents the version number of the launch template on which to base the new version. The new version inherits the same launch parameters as the source version, except for parameters that you specify for --launch-template-data. Configure the appropriate instance type for the "InstanceType" command parameter, based on the optimization recommendation provided by AWS Compute Optimizer:
aws ec2 create-launch-template-version
--region us-east-1
--launch-template-id lt-0abcd1234abcd1234
--source-version 2
--launch-template-data '{"InstanceType":"c5.xlarge"}'
09 The command output should return the metadata available for the new launch template version:
{
"LaunchTemplateVersion": {
"LaunchTemplateId": "lt-0abcd1234abcd1234",
"LaunchTemplateName": "cc-web-asg-launch-template",
"VersionNumber": 3,
"LaunchTemplateData": {
"SecurityGroupIds": [
"sg-0abcd1234abcd1234"
],
"ImageId": "ami-01234abcd1234abcd",
"InstanceType": "c5.xlarge"
},
"CreateTime": "2020-11-22T10:00:00.000Z"
}
}
10 Run update-auto-scaling-group command (OSX/Linux/UNIX) to apply the new ASG launch template configuration to the Amazon EC2 Auto Scaling group that you want to optimize (the command does not produce an output): IMPORTANT: The following reconfiguration process assumes that the Auto Scaling group selected for optimization is NOT currently used in production or for critical operations.
aws autoscaling update-auto-scaling-group
--region us-east-1
--auto-scaling-group-name cc-project5-web-asg
--launch-template LaunchTemplateId=lt-0abcd1234abcd1234,Version=3
11 Run start-instance-refresh command (OSX/Linux/UNIX) to start the instance refresh process for the optimized Auto Scaling group (ASG). An instance refresh allows you to trigger a rolling replacement of all previously launched instances within the Auto Scaling group with a new group of EC2 instances:
aws autoscaling start-instance-refresh
--region us-east-1
--auto-scaling-group-name cc-project5-web-asg
12 The command output should return the ID of the instance refresh process:
{
"InstanceRefreshId": "abcd1234-abcd-1234-abcd-1234abcd1234"
}
13 Repeat steps no. 3 – 12 for each under-optimized Amazon EC2 Auto Scaling group (finding) identified in the selected AWS region.
14 Change the AWS region by updating the --region command parameter value and repeat the entire remediation process for other regions.