01 Run get-ec2-instance-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-ec2-instance-recommendations
--region ap-southeast-2
--filters name=Finding,values=Underprovisioned,Overprovisioned
--query 'instanceRecommendations[*].instanceArn'
02 The command output should return the requested instance ARNs:
[
"arn:aws:ec2:ap-southeast-2:123456789012:instance/i-0abcd1234abcd1234",
"arn:aws:ec2:ap-southeast-2:123456789012:instance/i-01234abcd1234abcd"
]
03 Run get-ec2-instance-recommendations command (OSX/Linux/UNIX) using the ARN of the under-provisioned/over-provisioned instance that you want to optimize as identifier parameter, to describe the optimization recommendations provided by AWS Compute Optimizer for the selected Amazon EC2 instance:
aws compute-optimizer get-ec2-instance-recommendations
--region ap-southeast-2
--instance-arns arn:aws:ec2:ap-southeast-2:123456789012:instance/i-0abcd1234abcd1234
--query 'instanceRecommendations[*]'
04 The command output should return the optimization recommendations for the selected instance:
[
{
"instanceArn": "arn:aws:ec2:ap-southeast-2:123456789012:instance/i-0abcd1234abcd1234",
"utilizationMetrics": [
{
"name": "CPU",
"value": 50.0,
"statistic": "MAXIMUM"
},
{
"name": "EBS_READ_OPS_PER_SECOND",
"value": 662.1,
"statistic": "MAXIMUM"
},
{
"name": "EBS_WRITE_OPS_PER_SECOND",
"value": 144.93666666666667,
"statistic": "MAXIMUM"
},
{
"name": "EBS_READ_BYTES_PER_SECOND",
"value": 41739361.979166664,
"statistic": "MAXIMUM"
},
{
"name": "EBS_WRITE_BYTES_PER_SECOND",
"value": 27068385.416666668,
"statistic": "MAXIMUM"
}
],
"recommendationSources": [
{
"recommendationSourceType": "Ec2Instance",
"recommendationSourceArn": "arn:aws:ec2:ap-southeast-2:123456789012:instance/i-0abcd1234abcd1234"
}
],
"lastRefreshTimestamp": 1605863228.566,
"recommendationOptions": [
{
"performanceRisk": 1.0,
"projectedUtilizationMetrics": [
{
"name": "CPU",
"value": 89.47368421052632,
"statistic": "MAXIMUM"
}
],
"instanceType": "r5.xlarge",
"rank": 1
},
{
"performanceRisk": 3.0,
"projectedUtilizationMetrics": [
{
"name": "CPU",
"value": 54.83870967741935,
"statistic": "MAXIMUM"
}
],
"instanceType": "t3.2xlarge",
"rank": 2
},
{
"performanceRisk": 1.0,
"projectedUtilizationMetrics": [
{
"name": "CPU",
"value": 50.0,
"statistic": "MAXIMUM"
}
],
"instanceType": "c5.2xlarge",
"rank": 3
}
],
"currentInstanceType": "c5.2xlarge",
"finding": "OVER_PROVISIONED",
"lookBackPeriodInDays": 14.0,
"instanceName": "cc-staging-web-instance",
"accountId": "123456789012"
}
]
05 Based on the information returned at the previous step by the get-ec2-instance-recommendations command output, review the optimization recommendations by analyzing the finding properties listed below. Review each recommendation option to identify the instance type configuration that works best for you. When comparing EC2 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 EC2 instance (UNDER_PROVISIONED or OVER_PROVISIONED).
- "instanceName" - the name of the selected instance.
- "currentInstanceType" - the current instance type of the selected Amazon EC2 instance.
- "lookBackPeriodInDays" - the number of days for which utilization metrics were analyzed for the selected instance.
- "recommendationOptions[].instanceType" - the instance type recommended for the EC2 instance optimization option.
- "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 instance recommendation option. The performance risk represents the likelihood of the recommended instance type not meeting the performance requirement of your workload. The lowest performance risk is categorized as 0, and the highest as 5.
06 Once you have chosen the best instance type configuration for the selected Amazon EC2 instance, run stop-instances command (OSX/Linux/UNIX) to stop the selected under-provisioned/over-provisioned instance: IMPORTANT: The following reconfiguration process assumes that the Amazon EC2 instance selected for optimization is NOT currently used in production or for critical operations.
aws ec2 stop-instances
--region ap-southeast-2
--instance-ids i-0abcd1234abcd1234
07 The output should return the stop-instances command request metadata:
{
"StoppingInstances": [
{
"InstanceId": "i-0abcd1234abcd1234",
"CurrentState": {
"Code": 64,
"Name": "stopping"
},
"PreviousState": {
"Code": 16,
"Name": "running"
}
}
]
}
08 Run modify-instance-attribute command (OSX/Linux/UNIX) to resize the selected Amazon EC2 instance to the recommended instance type. The following command example updates the instance type for an over-provisioned EC2 instance, identified by the ID "i-0abcd1234abcd1234", from c5.2xlarge to r5.xlarge (the command does not produce an output):
aws ec2 modify-instance-attribute
--region ap-southeast-2
--instance-id i-0abcd1234abcd1234
--instance-type "{\"Value\": \"r5.xlarge\"}"
09 Run start-instances command (OSX/Linux/UNIX) to restart the optimized Amazon EC2 instance (it may take few minutes until the instance enters the running state):
aws ec2 start-instances
--region ap-southeast-2
--instance-ids i-0abcd1234abcd1234
10 The output should return the start-instances command request metadata:
{
"StartingInstances": [
{
"InstanceId": "i-0abcd1234abcd1234",
"CurrentState": {
"Code": 0,
"Name": "pending"
},
"PreviousState": {
"Code": 80,
"Name": "stopped"
}
}
]
}
11 Repeat steps no. 3 – 10 for each under-provisioned/over-provisioned EC2 instance (finding) identified in the selected AWS region.
12 Change the AWS region by updating the --region command parameter value and repeat the entire remediation process for other regions.