AWSSupportRemediator-ResizeInstanceByOneLevel
Description
Downsizes or upsizes an Amazon Elastic Compute Cloud (Amazon EC2) instance by one level within the same instance type family.
This automation remediates findings identified by Amazon Well-Architected Agent. It remediates findings from Amazon Trusted Advisor checks Low utilization Amazon EC2 instances and High CPU Utilization Amazon EC2 Instances.
If the instance does not exist, is in terminated or shutting-down state, or the instance type changed within the specified number of days, the automation completes successfully without making changes. If the instance is in stopped state and ResizeIfStopped is set to false, the automation also completes successfully without making changes.
If the instance is in running state, the automation stops and restarts it during the resize operation. If CreateAMIBeforeResize is set to true, the automation creates an Amazon Machine Image (AMI) as a backup before changing the instance type.
The AMI and its associated Amazon Elastic Block Store (Amazon EBS) snapshot remain in the account after the automation completes and incur ongoing storage costs until you delete them. For more information about pricing, see Amazon EBS pricing
The automation fails without making changes in the following cases:
The instance is part of an Amazon EC2 Auto Scaling group or has stop protection enabled.
The instance has an Amazon EBS volume encrypted with an Amazon KMS key that is not in enabled state.
The instance is already the smallest or largest instance type in its family.
You are responsible for reviewing automation actions before they run.
This automation might cause stack drift if the resource is part of an Amazon CloudFormation stack.
Access to
AWSSupportRemediator-*runbooks requires an active Business Support+, Enterprise Support, or Unified Operations Support plan. For more information, see Compare Amazon Web Services Support Planson the Amazon website.
Document type
Automation
Owner
Amazon
Platforms
Linux, macOS, Windows
Parameters
-
AutomationAssumeRole
Type: String
Description: (Optional) The Amazon Resource Name (ARN) of the Amazon Identity and Access Management (IAM) role that allows Systems Manager Automation to perform the actions on your behalf. If no role is specified, Systems Manager Automation uses the permissions of the user that starts this runbook.
-
Direction
Type: String
Description: (Required) The direction to resize the instance. Use
downto downsize orupto upsize by one level within the same instance type family. -
InstanceId
Type:
AWS::EC2::Instance::IdDescription: (Required) The ID of the Amazon EC2 instance.
-
CreateAMIBeforeResize
Type: Boolean
Description: (Optional) Whether to create an AMI as a backup before resizing the instance.
Default: True
-
MinimumDaysSinceLastChange
Type: String
Description: (Optional) The minimum number of days since the last instance type change. If the instance type changed within the specified number of days, the automation completes successfully without making changes. Use
0to skip this validation.Default: 7
-
ResizeIfStopped
Type: Boolean
Description: (Optional) Whether to proceed with the resize if the instance is in stopped state.
Default: False
Required IAM permissions
The AutomationAssumeRole parameter requires the following actions to
use the runbook successfully.
-
cloudtrail:LookupEvents -
ec2:CreateImage -
ec2:CreateTags -
ec2:DescribeImages -
ec2:DescribeInstanceAttribute -
ec2:DescribeInstanceStatus -
ec2:DescribeInstanceTypes -
ec2:DescribeInstances -
ec2:DescribeVolumes -
ec2:ModifyInstanceAttribute -
ec2:StartInstances -
ec2:StopInstances -
kms:CreateGrant -
kms:Decrypt -
kms:DescribeKey
Document Steps
-
validateInput - Validates the Amazon EC2 instance and calculates the new instance type one level up or down within the same family.
-
branchOnChangeRequired - Branches on whether the instance type change is required.
-
waitForInstanceRunningOrStopped - Waits for the instance to reach running or stopped state before proceeding.
-
branchOnInstanceStatus - Branches on whether the instance needs to be stopped before resizing.
-
stopInstance - Stops the instance before changing the instance type.
-
branchOnAmiCreationRequired - Branches on whether an AMI backup is required before resizing.
-
createAmi - Creates an AMI as a backup before changing the instance type.
-
waitForAmiToBeAvailable - Waits for the AMI to reach available state before proceeding.
-
changeInstanceType - Changes the instance type to the calculated target instance type.
-
branchOnInitialInstanceStatus - Branches on whether the instance needs to be restarted after resizing.
-
startInstance - Starts the instance after changing the instance type.
Outputs
-
validateInput.InitialInstanceState: The state of the instance before the automation runs.
-
validateInput.InitialInstanceType: The instance type before the automation runs.
-
validateInput.NewInstanceType: The target instance type after the automation runs.
-
validateInput.ChangeRequired: Whether the instance type change is required.
-
validateInput.ValidationMessage: A message describing the validation result.
-
createAmi.AmiId: The ID of the AMI created as a backup before the instance type is changed.