ebook img

Amazon EC2 Auto Scaling - User Guide PDF

156 Pages·2017·1.6 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Amazon EC2 Auto Scaling - User Guide

Amazon EC2 Auto Scaling User Guide Amazon EC2 Auto Scaling User Guide Amazon EC2 Auto Scaling: User Guide Copyright © 2022 Amazon Web Services, Inc. and/or its affiliates. All rights reserved. Amazon's trademarks and trade dress may not be used in connection with any product or service that is not Amazon's, in any manner that is likely to cause confusion among customers, or in any manner that disparages or discredits Amazon. All other trademarks not owned by Amazon are the property of their respective owners, who may or may not be affiliated with, connected to, or sponsored by Amazon. Amazon EC2 Auto Scaling User Guide Table of Contents What is Amazon EC2 Auto Scaling? ...................................................................................................... 1 Auto Scaling components ............................................................................................................ 1 Pricing for Amazon EC2 Auto Scaling ........................................................................................... 2 Get started ................................................................................................................................ 2 Related services......................................................................................................................... 2 Work with Auto Scaling groups .................................................................................................... 2 Auto scaling benefits.................................................................................................................. 3 Example: Cover variable demand.......................................................................................... 3 Example: Web app architecture............................................................................................ 4 Example: Distribute instances across Availability Zones ........................................................... 5 Instance lifecycle........................................................................................................................ 7 Scale out........................................................................................................................... 8 Instances in service............................................................................................................ 8 Scale in............................................................................................................................. 9 Attach an instance ............................................................................................................. 9 Detach an instance ........................................................................................................... 10 Lifecycle hooks................................................................................................................ 10 Enter and exit standby ...................................................................................................... 10 Quotas.................................................................................................................................... 10 Set up............................................................................................................................................. 13 Prepare to use Amazon EC2...................................................................................................... 13 Install the AWS CLI................................................................................................................... 13 Get started...................................................................................................................................... 14 Walkthrough summary.............................................................................................................. 14 Prepare for the walkthrough ..................................................................................................... 15 Step 1: Create a launch template ............................................................................................... 15 Step 2: Create a single-instance Auto Scaling group ...................................................................... 17 Step 3: Verify your Auto Scaling group ....................................................................................... 17 Step 4: Terminate an instance in your Auto Scaling group ............................................................. 18 Step 5: Next steps .................................................................................................................... 18 Step 6: Clean up...................................................................................................................... 19 Launch templates............................................................................................................................. 20 Permissions............................................................................................................................. 21 Create a launch template for an Auto Scaling group ..................................................................... 21 Create your launch template (console) ................................................................................ 22 Create a launch template from an existing instance (console) ................................................. 28 Additional information...................................................................................................... 28 Limitations...................................................................................................................... 29 Copy launch configurations to launch templates .......................................................................... 29 Replace a launch configuration with a launch template ................................................................. 30 Request Spot Instances ............................................................................................................. 31 AWS CLI examples for working with launch templates .................................................................. 32 Example usage................................................................................................................. 32 Create a basic launch template .......................................................................................... 33 Specify tags that tag instances at launch ............................................................................ 34 Specify an IAM role to pass to instances ............................................................................. 34 Assign public IP addresses ................................................................................................. 34 Specify a user data script that configures instances at launch ................................................. 34 Specify a block device mapping ......................................................................................... 35 Specify Dedicated Hosts to bring software licenses from external vendors ................................ 35 Specify an existing network interface ................................................................................. 35 Create multiple network interfaces ..................................................................................... 35 Manage your launch templates .......................................................................................... 36 Update an Auto Scaling group to use a launch template ....................................................... 38 iii Amazon EC2 Auto Scaling User Guide Launch configurations....................................................................................................................... 39 Create a launch configuration .................................................................................................... 39 Create a launch configuration (console) ............................................................................... 40 Create a launch configuration (AWS CLI) ............................................................................. 41 Configure IMDS ................................................................................................................ 41 Create a launch configuration using an EC2 instance ..................................................................... 43 Create a launch configuration using an EC2 instance ............................................................. 43 Create a launch configuration from an instance and override the block devices (AWS CLI) ........... 44 Create a launch configuration and override the instance type (AWS CLI) ................................... 45 Change a launch configuration ................................................................................................... 46 Configure instance tenancy ........................................................................................................ 47 Auto Scaling groups ......................................................................................................................... 50 Use multiple instance types and purchase options ........................................................................ 51 Allocation strategies......................................................................................................... 52 Best practices for Spot Instances ........................................................................................ 53 Control the proportion of On-Demand Instances .................................................................. 54 Prerequisites.................................................................................................................... 56 Create an Auto Scaling group with Spot and On-Demand Instances (console) ........................... 56 Create an Auto Scaling group with Spot and On-Demand Instances (AWS CLI) .......................... 58 Verify your Auto Scaling group configuration and launched instances (AWS CLI) ........................ 65 Configure overrides.......................................................................................................... 66 Create a group using attribute-based instance type selection ......................................................... 76 Considerations................................................................................................................. 77 Prerequisites.................................................................................................................... 78 Use attribute-based instance type selection ......................................................................... 78 Limitations...................................................................................................................... 82 Create a group using a launch template ...................................................................................... 82 Create a group using a launch configuration ................................................................................ 84 Create a group using an EC2 instance ......................................................................................... 86 Prerequisites.................................................................................................................... 87 Create an Auto Scaling group from an EC2 instance (console) ................................................. 87 Create an Auto Scaling group from an EC2 instance (AWS CLI) ............................................... 88 Create a group using the EC2 launch wizard ................................................................................ 90 Create a launch template .................................................................................................. 91 Create an Auto Scaling group ............................................................................................ 91 Next steps....................................................................................................................... 92 Tag groups and instances.......................................................................................................... 92 Tag naming and usage restrictions ..................................................................................... 93 EC2 instance tagging lifecycle ............................................................................................ 93 Tag your Auto Scaling groups ............................................................................................ 94 Delete tags...................................................................................................................... 96 Tags for security .............................................................................................................. 96 Control access to tags ....................................................................................................... 97 Use tags to filter Auto Scaling groups ................................................................................. 97 Replace instances................................................................................................................... 100 Replace instances based on an instance refresh .................................................................. 100 Check instance refresh status ........................................................................................... 107 AWS CLI examples that enable skip matching .................................................................... 108 Add checkpoints to an instance refresh ............................................................................. 112 Replace instances based on maximum instance lifetime ....................................................... 115 Delete your Auto Scaling infrastructure ..................................................................................... 118 Delete your Auto Scaling group ........................................................................................ 118 (Optional) Delete the launch configuration ........................................................................ 119 (Optional) Delete the launch template .............................................................................. 119 (Optional) Delete the load balancer and target groups ....................................................... 120 (Optional) Delete CloudWatch alarms ................................................................................ 120 Scale your group............................................................................................................................ 122 iv Amazon EC2 Auto Scaling User Guide Scaling options...................................................................................................................... 122 Set capacity limits .................................................................................................................. 123 Maintain a fixed number of instances ........................................................................................ 124 Manual scaling....................................................................................................................... 125 Change the size of your Auto Scaling group (console) .......................................................... 125 Change the size of your Auto Scaling group (AWS CLI) ........................................................ 126 Attach EC2 instances to your Auto Scaling group ................................................................ 127 Detach EC2 instances from your Auto Scaling group ........................................................... 131 Dynamic scaling..................................................................................................................... 134 How dynamic scaling policies work ................................................................................... 134 Multiple dynamic scaling policies...................................................................................... 135 Target tracking scaling policies ......................................................................................... 136 Step and simple scaling policies....................................................................................... 144 Set default warm-up or cooldown values ........................................................................... 154 Scaling based on Amazon SQS ......................................................................................... 161 Verify a scaling activity ................................................................................................... 165 Disable a scaling policy ................................................................................................... 167 Delete a scaling policy .................................................................................................... 168 AWS CLI examples for scaling policies ............................................................................... 170 Predictive scaling.................................................................................................................... 172 How predictive scaling works ........................................................................................... 173 Best practices................................................................................................................. 173 Create a predictive scaling policy (console) ........................................................................ 174 Create a predictive scaling policy (AWS CLI) ....................................................................... 176 Limitations..................................................................................................................... 178 Supported Regions......................................................................................................... 179 Explore your data and forecast ......................................................................................... 179 Override the forecast ...................................................................................................... 183 Use custom metrics........................................................................................................ 187 Scheduled scaling................................................................................................................... 194 Considerations................................................................................................................ 194 Recurring schedules........................................................................................................ 195 Create and manage scheduled actions (console) ................................................................. 195 Create and manage scheduled actions (AWS CLI) ................................................................ 197 Limitations..................................................................................................................... 199 Lifecycle hooks....................................................................................................................... 199 Considerations and limitations for lifecycle hooks ............................................................... 200 Lifecycle hook availability ................................................................................................ 201 Examples....................................................................................................................... 201 How lifecycle hooks work ................................................................................................ 201 Prepare to add a lifecycle hook ........................................................................................ 203 Add lifecycle hooks ......................................................................................................... 209 Complete a lifecycle action .............................................................................................. 211 Tutorial: Configure user data to retrieve the target lifecycle state through instance metadata .... 212 Tutorial: Configure a lifecycle hook that invokes a Lambda function ...................................... 217 Warm pools........................................................................................................................... 223 Core concepts................................................................................................................ 224 Prerequisites.................................................................................................................. 225 Create a warm pool ........................................................................................................ 226 Update a warm pool....................................................................................................... 226 Delete a warm pool........................................................................................................ 227 Limitations..................................................................................................................... 227 Use lifecycle hooks ......................................................................................................... 227 View health check status................................................................................................. 230 AWS CLI examples for working with warm pools ................................................................ 232 Control instance termination .................................................................................................... 234 Termination policy scenarios ............................................................................................ 235 v Amazon EC2 Auto Scaling User Guide Work with termination policies ......................................................................................... 237 Create a custom termination policy with Lambda ............................................................... 240 Use instance scale-in protection ....................................................................................... 244 Temporarily remove instances .................................................................................................. 246 How the standby state works ........................................................................................... 247 Health status of an instance in a standby state .................................................................. 248 Temporarily remove an instance (console) .......................................................................... 248 Temporarily remove an instance (AWS CLI) ........................................................................ 248 Suspend-resume processes...................................................................................................... 251 Types of processes .......................................................................................................... 251 Considerations................................................................................................................ 252 Suspend and resume processes (console) ........................................................................... 254 Suspend and resume processes (AWS CLI) .......................................................................... 254 Monitor......................................................................................................................................... 256 Check instance health ............................................................................................................. 257 Health check types ......................................................................................................... 257 Amazon EC2 health checks .............................................................................................. 257 Elastic Load Balancing health checks................................................................................. 258 Custom health detection tasks ......................................................................................... 259 Unhealthy instance replacement ....................................................................................... 260 How Amazon EC2 Auto Scaling minimizes downtime ........................................................... 260 Health check considerations ............................................................................................. 261 Additional information.................................................................................................... 261 Health check grace period ............................................................................................... 262 Monitor with AWS Health Dashboard ........................................................................................ 263 Monitor with CloudWatch ........................................................................................................ 264 Available metrics and dimensions ..................................................................................... 265 Enable Auto Scaling group metrics (console) ...................................................................... 268 Enable Auto Scaling group metrics (AWS CLI) ..................................................................... 269 Configure monitoring for Auto Scaling instances ................................................................ 269 View monitoring graphs in the Amazon EC2 Auto Scaling console ......................................... 271 Log API calls with AWS CloudTrail ............................................................................................ 273 Amazon EC2 Auto Scaling information in CloudTrail ............................................................ 273 Understand Amazon EC2 Auto Scaling log file entries ......................................................... 274 Monitor with Amazon SNS notifications .................................................................................... 275 SNS notifications............................................................................................................ 275 Configure Amazon SNS notifications for Amazon EC2 Auto Scaling ....................................... 276 Work with other services ................................................................................................................. 279 Capacity Rebalancing .............................................................................................................. 279 How it works ................................................................................................................. 279 Considerations................................................................................................................ 280 Enable Capacity Rebalancing ............................................................................................ 281 Add a termination lifecycle hook ...................................................................................... 285 Limitations..................................................................................................................... 286 AWS CloudFormation.............................................................................................................. 287 Amazon EC2 Auto Scaling and AWS CloudFormation templates ............................................ 287 Learn more about AWS CloudFormation ............................................................................ 287 AWS CloudShell...................................................................................................................... 287 Compute Optimizer................................................................................................................ 288 Limitations..................................................................................................................... 288 Findings........................................................................................................................ 289 View recommendations................................................................................................... 289 Considerations for evaluating the recommendations ........................................................... 289 Elastic Load Balancing............................................................................................................. 290 Elastic Load Balancing types ............................................................................................ 291 Prerequisites.................................................................................................................. 292 Attach a load balancer .................................................................................................... 293 vi Amazon EC2 Auto Scaling User Guide Understand the attachment status .................................................................................... 294 Configure a load balancer from the Amazon EC2 Auto Scaling console ................................... 295 Add Elastic Load Balancing health checks .......................................................................... 295 Add Availability Zones ..................................................................................................... 296 AWS CLI examples for working with Elastic Load Balancing .................................................. 299 Tutorial: Set up a scaled and load-balanced application ....................................................... 302 EventBridge........................................................................................................................... 308 Amazon EC2 Auto Scaling event reference ......................................................................... 308 Warm pool event types and patterns ................................................................................ 314 Create EventBridge rules ................................................................................................. 318 Amazon VPC.......................................................................................................................... 321 EC2-Classic.................................................................................................................... 322 Default VPC................................................................................................................... 322 Nondefault VPC.............................................................................................................. 323 Considerations when choosing VPC subnets....................................................................... 323 IP addressing in a VPC .................................................................................................... 323 Network interfaces in a VPC ............................................................................................ 324 Instance placement tenancy ............................................................................................. 324 AWS Outposts................................................................................................................ 324 More resources for learning about VPCs ............................................................................ 324 Security......................................................................................................................................... 326 Data protection...................................................................................................................... 326 Use AWS KMS keys to encrypt Amazon EBS volumes ........................................................... 327 Identity and Access Management .............................................................................................. 327 Access control................................................................................................................ 327 How Amazon EC2 Auto Scaling works with IAM .................................................................. 328 Managed policies............................................................................................................ 334 Service-linked roles......................................................................................................... 336 Identity-based policy examples ........................................................................................ 342 Cross-service confused deputy prevention ......................................................................... 351 Launch template support ................................................................................................ 352 IAM role for applications that run on Amazon EC2 instances ................................................ 356 AWS KMS key policy for use with encrypted volumes .......................................................... 358 Compliance validation............................................................................................................. 362 PCI DSS compliance ........................................................................................................ 363 Resilience.............................................................................................................................. 363 Infrastructure security............................................................................................................. 364 Use VPC endpoints for private connectivity ................................................................................ 364 Create an interface VPC endpoint ..................................................................................... 364 Create a VPC endpoint policy ........................................................................................... 365 Troubleshoot.................................................................................................................................. 366 Retrieve an error message ....................................................................................................... 366 Additional troubleshooting resources ........................................................................................ 367 Instance launch failure ............................................................................................................ 368 The requested configuration is currently not supported. ...................................................... 369 The security group <name of the security group> does not exist. Launching EC2 instance failed. 369 The key pair <key pair associated with your EC2 instance> does not exist. Launching EC2 instance failed................................................................................................................ 370 The requested Availability Zone is no longer supported. Please retry your request... ................. 370 Your requested instance type (<instance type>) is not supported in your requested Availability Zone (<instance Availability Zone>)... ................................................................................ 370 Your Spot request price of 0.015 is lower than the minimum required Spot request fulfillment price of 0.0735... ............................................................................................................ 370 Invalid device name <device name> / Invalid device name upload. Launching EC2 instance failed............................................................................................................................. 371 Value (<name associated with the instance storage device>) for parameter virtualName is invalid............................................................................................................................ 371 vii Amazon EC2 Auto Scaling User Guide EBS block device mappings not supported for instance-store AMIs. ....................................... 371 Placement groups may not be used with instances of type 'm1.large'. Launching EC2 instance failed............................................................................................................................. 372 Client.InternalError: Client error on launch. ........................................................................ 372 We currently do not have sufficient <instance type> capacity in the Availability Zone you requested... Launching EC2 instance failed. ........................................................................ 373 There is no Spot capacity available that matches your request. Launching EC2 instance failed. ... 373 <number of instances> instance(s) are already running. Launching EC2 instance failed. ............. 373 AMI issues............................................................................................................................. 374 The AMI ID <ID of your AMI> does not exist. Launching EC2 instance failed. ............................ 374 AMI <AMI ID> is pending, and cannot be run. Launching EC2 instance failed. .......................... 374 Value (<ami ID>) for parameter virtualName is invalid. ........................................................ 374 The requested instance type's architecture (i386) does not match the architecture in the manifest for ami-6622f00f (x86_64). Launching EC2 instance failed. ..................................... 375 Load balancer issues ............................................................................................................... 375 One or more target groups not found. Validating load balancer configuration failed. ................ 376 Cannot find Load Balancer <your load balancer>. Validating load balancer configuration failed.. 376 There is no ACTIVE Load Balancer named <load balancer name>. Updating load balancer configuration failed......................................................................................................... 376 EC2 instance <instance ID> is not in VPC. Updating load balancer configuration failed. ............. 376 EC2 instance <instance ID> is in VPC. Updating load balancer configuration failed. ................... 377 Launch template issues........................................................................................................... 377 You must use a valid fully-formed launch template (invalid value) ........................................ 377 You are not authorized to use launch template (insufficient IAM permissions) ......................... 378 Health checks........................................................................................................................ 378 An instance was taken out of service in response to an EC2 instance status check failure ........... 379 An instance was taken out of service in response to an EC2 scheduled reboot ......................... 379 An instance was taken out of service in response to an EC2 health check that indicated it had been terminated or stopped............................................................................................ 380 An instance was taken out of service in response to an ELB system health check failure ............ 380 Resources...................................................................................................................................... 382 Document history........................................................................................................................... 383 viii Amazon EC2 Auto Scaling User Guide Auto Scaling components What is Amazon EC2 Auto Scaling? Amazon EC2 Auto Scaling helps you ensure that you have the correct number of Amazon EC2 instances available to handle the load for your application. You create collections of EC2 instances, called Auto Scaling groups. You can specify the minimum number of instances in each Auto Scaling group, and Amazon EC2 Auto Scaling ensures that your group never goes below this size. You can specify the maximum number of instances in each Auto Scaling group, and Amazon EC2 Auto Scaling ensures that your group never goes above this size. If you specify the desired capacity, either when you create the group or at any time thereafter, Amazon EC2 Auto Scaling ensures that your group has this many instances. If you specify scaling policies, then Amazon EC2 Auto Scaling can launch or terminate instances as demand on your application increases or decreases. For example, the following Auto Scaling group has a minimum size of one instance, a desired capacity of two instances, and a maximum size of four instances. The scaling policies that you define adjust the number of instances, within your minimum and maximum number of instances, based on the criteria that you specify. For more information about the benefits of Amazon EC2 Auto Scaling, see Amazon EC2 Auto Scaling benefits (p. 3). Auto Scaling components The following table describes the key components of Amazon EC2 Auto Scaling. Groups Your EC2 instances are organized into groups so that they can be treated as a logical unit for the purposes of scaling and management. When you create a group, you can specify its minimum, maximum, and, desired number of EC2 instances. For more information, see Auto Scaling groups (p. 50). Configuration templates Your group uses a launch template, or a launch configuration (not recommended, offers fewer features), as a configuration template for its EC2 instances. You can specify information such as the AMI ID, instance type, key pair, security groups, and block device mapping for your instances. For more information, see Launch templates (p. 20) and Launch configurations (p. 39). Scaling options Amazon EC2 Auto Scaling provides several ways for you to scale your Auto Scaling groups. For example, you can configure a group 1 Amazon EC2 Auto Scaling User Guide Pricing for Amazon EC2 Auto Scaling to scale based on the occurrence of specified conditions (dynamic scaling) or on a schedule. For more information, see Scaling options (p. 122). Pricing for Amazon EC2 Auto Scaling There are no additional fees with Amazon EC2 Auto Scaling, so it's easy to try it out and see how it can benefit your AWS architecture. You only pay for the AWS resources (for example, EC2 instances, EBS volumes, and CloudWatch alarms) that you use. Get started To begin, complete the Get started with Amazon EC2 Auto Scaling (p. 14) tutorial to create an Auto Scaling group and see how it responds when an instance in that group terminates. Related services To automatically distribute incoming application traffic across multiple instances in your Auto Scaling group, use Elastic Load Balancing. For more information, see Use Elastic Load Balancing to distribute traffic across the instances in your Auto Scaling group (p. 290). To monitor your Auto Scaling groups and instance utilization data, use Amazon CloudWatch. For more information, see Monitor CloudWatch metrics for your Auto Scaling groups and instances (p. 264). To configure auto scaling for scalable resources for Amazon Web Services beyond Amazon EC2, see the Application Auto Scaling User Guide. Work with Auto Scaling groups You can create, access, and manage your Auto Scaling groups using any of the following interfaces: • AWS Management Console – Provides a web interface that you can use to access your Auto Scaling groups. If you've signed up for an AWS account, you can access your Auto Scaling groups by signing into the AWS Management Console, using the search box on the navigation bar to search for Auto Scaling groups, and then choosing Auto Scaling groups. • AWS Command Line Interface (AWS CLI) – Provides commands for a broad set of AWS services, and is supported on Windows, macOS, and Linux. To get started, see AWS Command Line Interface User Guide. For more information, see autoscaling in the AWS CLI Command Reference. • AWS Tools for Windows PowerShell – Provides commands for a broad set of AWS products for those who script in the PowerShell environment. To get started, see the AWS Tools for Windows PowerShell User Guide. For more information, see the AWS Tools for PowerShell Cmdlet Reference. • AWS SDKs – Provides language-specific API operations and takes care of many of the connection details, such as calculating signatures, handling request retries, and handling errors. For more information, see AWS SDKs. • Query API – Provides low-level API actions that you call using HTTPS requests. Using the Query API is the most direct way to access AWS services. However, it requires your application to handle low-level details such as generating the hash to sign the request, and handling errors. For more information, see the Amazon EC2 Auto Scaling API Reference. • AWS CloudFormation – Supports creating Auto Scaling groups using CloudFormation templates. For more information, see Create Auto Scaling groups with AWS CloudFormation (p. 287). 2

Description:
All other trademarks not owned by Amazon are the property of their respective owners, who may or may not be affiliated with, connected to, or sponsored by .. Tutorial: Set Up a Scaled and Load-Balanced Application . Configure Scaling and Load Balancing Using the AWS Management Console .
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.