Amazon EC2 Auto Scaling
User Guide

The AWS Documentation website is getting a new look!
Try it now and let us know what you think. Switch to the new look >>

You can return to the original look by selecting English in the language selector above.

Creating a Launch Template for an Auto Scaling Group

Before you can create an Auto Scaling group using a launch template, you must create a launch template that includes the parameters required to launch an EC2 instance, such as the ID of the Amazon Machine Image (AMI) and an instance type.

The following procedure works for creating a new launch template. The new template uses parameters that you define (starting from scratch) or an existing launch template. After you create your launch template, you can create the Auto Scaling group by following the instructions in Creating an Auto Scaling Group Using a Launch Template.

Prerequisites

For information about the required IAM permissions, see Controlling the Use of Launch Templates in the Amazon EC2 User Guide for Linux Instances.

Considerations

Keep the following considerations in mind when creating a launch template for use with an Auto Scaling group:

  • Launch templates give you the flexibility of launching one type of instance, or a combination of instance types and On-Demand and Spot purchase options. For more information, see Auto Scaling Groups with Multiple Instance Types and Purchase Options. Launching instances with such a combination is not supported:

    • If you specify a Spot Instance request in Additional Details

    • In EC2-Classic

  • If you configure a network type (VPC or EC2-Classic), subnet, and Availability Zone for your template, these settings are ignored in favor of what is specified in the Auto Scaling group.

  • If you specify a network interface, you must configure the security group as part of the network interface, and not in the Security Groups section of the template.

  • You cannot specify multiple network interfaces.

  • You cannot assign specific private IP addresses. When an instance launches, a private address is allocated from the CIDR range of the subnet in which the instance is launched. For more information on specifying CIDR ranges for your VPC or subnet, see the Amazon VPC User Guide.

  • To specify an existing network interface to use, its device index must be 0 (eth0). For this scenario, you must use the CLI or API to create the Auto Scaling group. When you create the group using the CLI create-auto-scaling-group command or API CreateAutoScalingGroup action, you must specify the Availability Zones parameter instead of the subnet (VPC zone identifier) parameter.

  • You cannot use host placement affinity.

To create a new launch template for an Auto Scaling group using the console

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. In the navigation pane, choose Launch Templates.

  3. Choose Create a new template. Enter a name and provide a description for the initial version of the launch template.

  4. If you choose to create the new template based on another template:

    1. For Source template, choose an existing launch template.

    2. Choose the launch template version on which to base the new launch template from Source template version.

  5. Under Launch template contents, provide the following information.

    1. AMI ID: Choose the ID of the Amazon Machine Image (AMI) from which to launch the instances. You can search through all available AMIs using the Search for AMI dialog. From the Quick Start list, select from one of the commonly used AMIs in the list. If you don't see the AMI that you need, select the AWS Marketplace or Community AMIs list to find a suitable AMI.

    2. Instance type: Choose the instance type. Ensure that the instance type is compatible with the AMI you've specified.

    3. Key pair name: Specify the key pair to use when connecting to your instances.

    4. Network type: You can choose to specify whether to launch instances into a VPC or EC2-Classic, if applicable. However, the network type and Availability Zone settings of the launch template are ignored for Amazon EC2 Auto Scaling in favor of the settings of the Auto Scaling group.

    5. Security Groups: Choose one or more security groups, or leave blank to configure the security group as part of the network interface. You cannot specify security groups in both places. If you're using EC2-Classic, you must use security groups created specifically for EC2-Classic.

  6. Under Network interfaces, choose Add network interface and provide the following optional information. You can only specify one network interface. Pay attention to the following fields:

    1. Device: Specify eth0 as the device name (the device for which the device index is 0).

    2. Network interface: Leave blank to let AWS create a new network interface when an instance is launched, or enter the ID of an existing network interface. If you specify an ID, this limits your Auto Scaling group to one instance.

    3. Description: Enter a descriptive name.

    4. Subnet: While you may choose to specify a subnet, it is ignored for Amazon EC2 Auto Scaling in favor of the settings of the Auto Scaling group.

    5. Auto-assign public IP: Specify whether to automatically assign a public IP address to the network interface with the device index of eth0. This setting can only be enabled for a single, new network interface.

    6. Security group ID: Enter the IDs of one or more security groups with which to associate the primary network interface (eth0). Each security group must be configured for the VPC that your Auto Scaling group will launch instances into. Separate the entries with commas.

    7. Delete on termination: Choose whether the network interface is deleted when the Auto Scaling group scales in and terminates the instance to which the network interface is attached.

  7. If you choose to specify volumes to attach to the instances not including the volumes specified by the AMI, under Storage (Volumes), provide the following information:

    1. Volume type: Choose instance store or Amazon EBS volumes. The type of volume depends on the instance type that you've chosen. For more information, see Amazon EC2 Instance Store and Amazon EBS Volumes in the Amazon EC2 User Guide for Linux Instances.

    2. Device name: Specify a device name for the volume.

    3. Snapshot: Enter the ID of the snapshot from which to create the volume.

    4. Size: For Amazon EBS-backed volumes, specify a storage size. If you're creating the volume from a snapshot and don't specify a volume size, the default is the snapshot size.

    5. Volume type: For Amazon EBS volumes, choose the volume type.

    6. IOPS: With a Provisioned IOPS SSD volume, enter the maximum number of input/output operations per second (IOPS) that the volume should support.

    7. Delete on termination: For Amazon EBS volumes, choose whether to delete the volume when the associated instance is terminated.

    8. Encrypted: Choose Yes to change the encryption state of an Amazon EBS volume. The default effect of setting this parameter varies with the choice of volume source, as described in the table below. You must in all cases have permission to use the specified CMK. For more information about specifying encrypted volumes, see Amazon EBS Encryption in the Amazon EC2 User Guide for Linux Instances.

      Encryption Outcomes

      If Encrypted parameter is set to... And if source of volume is... Then the default encryption state is... Notes
      No New (empty) volume Unencrypted* N/A
      Unencrypted snapshot that you own Unencrypted*
      Encrypted snapshot that you own Encrypted by same key
      Unencrypted snapshot that is shared with you Unencrypted*
      Encrypted snapshot that is shared with you Encrypted by default CMK
      Yes New volume Encrypted by default CMK To use a non-default CMK, specify a value for the Key parameter.
      Unencrypted snapshot that you own Encrypted by default CMK
      Encrypted snapshot that you own Encrypted by same key
      Unencrypted snapshot that is shared with you Encrypted by default CMK
      Encrypted snapshot that is shared with you Encrypted by default CMK

      * If encryption by default is enabled, all newly created volumes (whether or not the Encrypted parameter is set to Yes) are encrypted using the default CMK. Setting both the Encrypted and Key parameters allows you to specify a non-default CMK.

    9. [Optional] Key: If you chose Yes in the previous step, enter the customer master key (CMK) you want to use when encrypting the volumes. Enter any CMK that you previously created using the AWS Key Management Service. You can paste the full ARN of any key that you have access to. For more information, see the AWS Key Management Service Developer Guide and the Required CMK Key Policy for Use with Encrypted Volumes topic in this guide.

      Note

      Providing a CMK without also setting the Encrypted parameter results in an error.

  8. For Instance tags, specify tags by providing key and value combinations. You can tag the instances, the volumes, or both.

  9. For Advanced Details, expand the section to view the fields and specify any additional parameters for the instances. For more information about this section and how each parameter can be used, see Creating a Launch Template in the Amazon EC2 User Guide for Linux Instances.

    • Purchasing option: You have the option to request Spot Instances and specify the maximum price you are willing to pay per instance hour. For this to work with an Auto Scaling group, you must specify a one-time request with no end date. For more information, see Launching Spot Instances in Your Auto Scaling Group.

      Important

      If you plan to specify multiple instance types and purchase options when you configure your Auto Scaling group, leave these fields empty. For more information, see Auto Scaling Groups with Multiple Instance Types and Purchase Options.

    • IAM instance profile: Specify an AWS Identity and Access Management (IAM) instance profile to associate with the instances. For more information, see IAM Role for Applications That Run on Amazon EC2 Instances.

    • Shutdown behavior: You can leave this field blank because it is ignored for Amazon EC2 Auto Scaling. The default behavior of Amazon EC2 Auto Scaling is to terminate the instance.

    • Termination protection: Provides additional termination protection but is ignored for Amazon EC2 Auto Scaling when scaling in your Auto Scaling group. To control whether an Auto Scaling group can terminate a particular instance when scaling in, use Instance Protection.

    • Monitoring: Choose whether to enable detailed monitoring of the instances using Amazon CloudWatch. Additional charges apply. For more information, see Monitoring Your Auto Scaling Groups and Instances Using Amazon CloudWatch.

    • T2/T3 Unlimited: (Only valid for T2 and T3 instances) Choose whether to enable applications to burst beyond the baseline for as long as needed. Additional charges may apply. For more information, see Using an Auto Scaling Group to Launch a Burstable Performance Instance as Unlimited in the Amazon EC2 User Guide for Linux Instances.

    • Placement group name: Specify a placement group in which to launch the instances. Not all instance types can be launched in a placement group. If you configure an Auto Scaling group using a CLI command that specifies a different placement group, the setting is ignored in favor of the one specified for the Auto Scaling group.

    • EBS-optimized instance: Provides additional, dedicated capacity for Amazon EBS I/O. Not all instance types support this feature, and additional charges apply.

    • Tenancy: You can choose to run your instances either on shared hardware (Shared), or on isolated, dedicated hardware (Dedicated). Additional charges may apply. You cannot choose Dedicated host.

    • RAM disk ID: The ID of the RAM disk associated with the AMI. Only valid for paravirtual (PV) AMIs.

    • Kernel ID: The ID of the kernel associated with the AMI. Only valid for paravirtual (PV) AMIs.

    • User data: You can specify user data to configure an instance during launch, or to run a configuration script.

  10. Choose Create launch template.

To create a launch template from an existing instance

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. In the navigation pane, choose Instances.

  3. Select the instance and choose Actions, Create template from instance.

  4. Provide a name and description. Adjust any other launch parameters as required, and choose Create Launch Template.

To create a launch template using the command line

You can use one of the following commands:

Create a launch template using the create-launch-template command as follows. Specify a value for Groups that corresponds to security groups for the VPC that your Auto Scaling group will launch instances into. Specify the VPC and subnets as properties of the Auto Scaling group.

aws ec2 create-launch-template --launch-template-name my-template-for-auto-scaling --version-description version1 \ --launch-template-data '{"NetworkInterfaces":[{"DeviceIndex":0,"AssociatePublicIpAddress":true,"Groups":["sg-7c227019"],"DeleteOnTermination":true}],"ImageId":"ami-01e24be29428c15b2","InstanceType":"t2.micro","TagSpecifications": [{"ResourceType":"instance","Tags":[{"Key":"purpose","Value":"webserver"}]}]}'

Use the following describe-launch-templates command to describe the launch template my-template-for-auto-scaling.

aws ec2 describe-launch-templates --launch-template-names my-template-for-auto-scaling

Use the following describe-launch-template-versions command to describe the versions of the specified launch template my-template-for-auto-scaling.

aws ec2 describe-launch-template-versions --launch-template-id lt-068f72b72934aff71

The following is an example response:

{ "LaunchTemplateVersions": [ { "VersionDescription": "version1", "LaunchTemplateId": "lt-068f72b72934aff71", "LaunchTemplateName": "my-template-for-auto-scaling", "VersionNumber": 1, "CreatedBy": "arn:aws:iam::123456789012:user/Bob", "LaunchTemplateData": { "TagSpecifications": [ { "ResourceType": "instance", "Tags": [ { "Key": "purpose", "Value": "webserver" } ] } ], "ImageId": "ami-01e24be29428c15b2", "InstanceType": "t2.micro", "NetworkInterfaces": [ { "DeviceIndex": 0, "DeleteOnTermination": true, "Groups": [ "sg-7c227019" ], "AssociatePublicIpAddress": true } ] }, "DefaultVersion": true, "CreateTime": "2019-02-28T19:52:27.000Z" } ] }