16
votes

I'm getting confused when using Terraform to provision an auto-scaling group. Should I use launch configuration or launch template for EC2 properties, such as which AMI, instance types, ...?

I don't know what the difference is between them, which we should use and why they exist?

3

3 Answers

31
votes

Launch templates (LTs) are newer than launch configurations (LCs) and provide more options to work with. Thus, the AWS documentation recommends use of launch templates (LTs) over launch configuration (LCs):

We recommend that you create Auto Scaling groups from launch templates to ensure that you're getting the latest features from Amazon EC2.

One of the practical key differences between LT and LC is the fact that LC is immutable. Once you define it, you can't edit it. Only a replacement is an option. However, a single LT can have multiple versions:

defining a launch template instead of a launch configuration allows you to have multiple versions of a template. With versioning, you can create a subset of the full set of parameters and then reuse it to create other templates or template versions.

Also LTs provide more EC2 options for you to configure, for example, dedicated hosting can be set only using a LT. Similarly, ability to use T2 unlimited burst credit option is only available in a LT.

Thus if you can, its better to follow AWS recommendation and use LT.

6
votes

Both are used in instance creation in ASG.


Launch Configuration(Legacy): Must be recreated every time because modification is not allowed.

Launch Template (Recommended By AWS) :

  1. Allows to edit and update.
  2. Maintains versions.
  3. Can use T2 unlimited burst feature.
  4. Allow provisioning using both On-demand and Spot Instances.
  5. Creation of parameter subsets.(Partial configuration for reuse and inheritance)
  6. Can also be used to launch a standalone instance using AWS Console, SDK and CLI.

I hope the above answer clarifies the doubt.

0
votes

Launch template is similar to launch configuration which usually Auto Scaling group uses to launch EC2 instances. However, defining a launch template instead of a launch configuration allows you to have multiple versions of a template.

AWS recommend that we should use launch templates instead of launch configurations to ensure that we can leverage the latest features of Amazon EC2, such as T2 Unlimited instances.

launch configurations are used with Auto Scaling Groups. While launch templates are used when you launch an instance using the aws EC2 console, an AWS SDK, or a command line tool.

Launch templates enable you to store the parameters (AMI, instance type, security groups, and key pairs etc.) so that you do not need to define these parameters every time you launch a new instance.