Understanding AWS EC2 Launch Templates

If you find yourself launching a lot of identical or similar AWS EC2 instances then you should consider using EC2 Launch Templates. In this post I will explain what an EC2 launch template is and how to get started using EC2 launch templates.

What is an EC2 Launch Template

Simply put a launch template is a method of storing the configuration of an EC2 instance which can then be used over and over for launching new instances with identical configurations. An EC2 launch template is designed to reduce the repetitive tasks which are usually performed when launching a new EC2 instance.

When to Use an EC2 Launch Template

When you use the EC2 Launch Wizard you can launch multiple versions of that instance at that time. However once you have completed the wizard and the instances have been launched, if you want to launch more you’ll need to go through the entire process again. EC2 launch templates are designed to eliminate this problem.

If you find yourself creating the same instance configuration multiple times then creating an EC2 Launch Template is going to help you.

How Launch Templates Work

Before we create our first template I’ll explain a little about how launch templates are setup to allow for maximum flexibility and reuse.

Each option you can set in a launch template can be given a specific value or it can be set to “don’t include in launch template”. This means when you launch an EC2 using the template those values will not be set automatically and will need to be set at launch time.

This is great if you are launching instances which are 90% identical so you’ll only need to update the different settings each launch. Of course even if you did set all the values within a launch template, you can still change them when you launch a new instance. This is what makes launch templates so flexible and powerful.

Creating an EC2 Launch Template

I’m assuming if you’re reading this you are already familiar with AWS and EC2 and have an AWS account setup. Log into your AWS account and open the EC2 dashboard. Under the Instances menu click on Launch Templates.

You’ll be greeted with it an empty screen for now but this is where all your launch templates will be listed. Click the Create launch template button.

The launch template page is basically all the questions you get asked when using the EC2 launch wizard but shown on a single page. The main difference being the top section where you will give your launch template a name and description (optional).

Naming EC2 Launch Template

You can now proceed to enter your required EC2 configuration settings in the rest of the fields. As mentioned you should be familiar with fields you are seeing as they are from the EC2 launch wizard.

Note that when you are entering your desired settings you may need to reference some AWS IDs for different resources. For example if you want to add a Security Group to your launch template then you will need to know the Security Group ID. The fields when creating a launch template don’t autocomplete like other elements of the AWS console (at the time of writing this)

Also take note of the “Advanced details” section at the bottom of the template. Click it to expand to enter more

Launch Template Advanced Details

Once you have completed your desired configuration click “Create launch template” button to save your new template.

Editing a Launch Template & Launch Templates Versions

When you want to edit a launch template you will either need to create a  new template or create a new version of it. You cannot directly edit an existing template. To perform a template edit, start by clicking the “Create launch template” button like when creating a new template.

If you want to create a brand new edit of a template select “Create a new template” radio button, give the template a name and choose the template you want to use for the source of your new template.

Launch Templete Source Template

Once you have selected the source template all the settings from that template will be automatically populated into the launch template fields. You can now go an make the necessary changes to the template as needed.

Another way to edit a launch template is to create a version of the template. To do this select “Create a new template version” and select what template you want to make a version of.

Select Launch Template Version

Once you have done that you can select a source template and an existing template version if you already have any created. Your new template will be incremented automatically.

When a template has multiple versions you are able to set one of them as the default version. This version will be automatically selected when you launch a new EC2 instance from the template.

Launch Template Versions

Launching an EC2 from a Launch Template

Now you have your launch template created you are ready to launch an instance based of its configuration.

Open the Instances page and click the small down arrow in the Launch Instance button at the top. A drop down will appear and you can select “Launch instance from template”.

On the following screen you will be able to select what launch template you want to use and select a specific version of the template if there are any. You can also specify how many instances you want to create from this instance. You can go through this page and alter any settings you may need to.

Once you have selected the template and version you will see a single screen which looks similar to the launch template screen with all your predefined configuration already set. Once you’re done click the “Launch instance from template” button and your instance will start initializing.

As you can see using EC2 Launch Templates can really save you a lot of time if you find your self launching lots of identical or similar instances.

I hope you found this article interesting and useful, if you did please do leave your feedback in the comments below – Mathew

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Site Footer