Launching EC2 Instance From Launch Template

What Is Launch Template?

Launch template is a feature which allows to us create a template (by storing all launch parameters) by reducing the number of steps and manual configurations each time while we create a EC2 Instance.

Launch Template includes AMI ID, network settings such as VPC , AZ and subnets , instance type, key pairs , Security group.

So You can create a launch template with all the details and you can launch an EC2 instance using this template.

Versioning Of Launch Template:

Launch template supports versions.

For each launch template you can create one or more versions and each versions can have different launch parameters.

How Can I Use Version With Launch Template?

When you launch an EC2 instance you can choose the launch template and the version of the launch template. And If you don’t have any versions for a launch template It will use default version for that launch template.

Limitations Of Launch Template:

  • 5000 launch template per region.
  • 10,000 versions per launch template.
  • All the required parameters should be provided in the launch template.
  • Only launch templates can be tagged, not the versions.
  • Launch template versions are numbered in order , No manual versioning.

Ways Of Creating Launch Templates:

  • Create Launch Template from existing ec2 Instance
  • Create Launch template from existing launch template
  • Create Launch template from the scratch

In this article , We will go through the process of creating launch template from the scratch.

Creating Launch Template:

To create a launch template , Login to EC2 CONSOLE

In the Navigation pane , Choose Launch Templates.

You should see the following page,

Click Create launch template , Provide the name for the launch template.

And If you want to setup launch template for auto-scaling , You can check Auto Scaling guidance. For this tutorial , We are not setting up template for autoscaling.

Add a tag for launch template ,

Under Launch template contents ,

Choose an AWS Managed AMI or If you have an AMI for the existing Instance you can use the same.

To use custom AMI , Click Specify a custom value , Provide the AMI ID and click save.

Or You can use the AWS managed AMI’s.

For this tutorial , I am using Ubuntu 18.04 AMI.

you can choose the Instance type as per the requirement.

For SSH into EC2 Instance We need a key pair , You shoudl specify the key pair value here.

Enter the key pair name and click save.

Under Networking Settings,

Choose the VPC where you want to launch the template and select the security group , You can also use the specify id of the security group.

Under Storage (volumes),

We need to configure Volume for the EC2 instance which will be launched using launch template.

You can change the size of the volume , volume type , IOPS value .

Also You can attach an additional volume If required.

Clicking Add volume,

You can mention the device name for the new volume to be attached with the instance , specify the size of the volume, IOPS etc.

You can add a tag to the EC2 instance which will be launched using launch template.

Under Network interfaces ,

We need to specify the subnet , Security group ID , Auto-assign public ip (If public IP is required for EC2 Instance),

Under Advanced settings,

Here you can set the shutdown behaviour , termination protection , detailed Cloudwatch monitoring , IAM role attachment and other parameters.

Once everything is in place , Click create template.

You should get an acknowledgement like this.

You can see the versions of the launch template and all the details.

If you want to launch an EC2 Instance from the launch template , Under Actions ,

Click launch Instance from Template. By clicking this , You can see all the parameters we have passed already while creating launch template.

You can create new versions for the launch template by using different instance paramaters.

By default , Each launch template will have only 1 version.

If you want to delete the version of a launch template , Click delete template version ,

It will ask for the template version , Select the version and click Delete.

As we have only 1 version for this launch template , We can delete the version of the template.

If you want to delete the launch template itself , Click delete template

Type Delete and click Delete.

Now that we have learnt how to create and configure launch template from the scratch , launch ec2 instance from the template.

Also we know how to delete the version of the launch template and the launch template itself.

Hope this article helps you. Thanks for reading this article.

Please do check out my other publications.