Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Create a Launch Template for an Auto Scaling group
3.
Copy Launch Configurations to Launch Templates
3.1.
Copy a Release Configuration to a Launch Template (Console)
3.2.
To Replica all Launch Configurations to Release Templates (Console)
4.
Replace a Launch Configuration with a Launch Template
5.
Request Spot Instances for Fault-Tolerant and Flexible Packages
6.
Examples for developing and coping with release templates
6.1.
To create a primary release template
6.1.1.
Specify tags that tag instances at launch
6.1.2.
Specify an IAM role to pass to instances
6.1.3.
Assign public IP addresses
6.1.4.
Specify a user data script that configures instances at launch
6.1.5.
Specify a block device mapping
6.1.6.
Specify Dedicated Hosts to bring software licenses from external vendors
6.1.7.
Specify an existing network interface
6.1.8.
Create multiple network interfaces
6.2.
Manage your launch templates
6.2.1.
List and describe your launch templates.
6.2.2.
Create a launch template version
6.2.3.
Delete a launch template version
6.2.4.
Delete a launch template
7.
Frequently Asked Questions
7.1.
What is the distinction between release template and release configuration in AWS?
7.2.
What gain does a release template have over a launch configuration?
7.3.
Can you regulate a release template?
7.4.
What are AWS launch templates?
8.
Conclusion
Last Updated: Mar 27, 2024
Easy

Launching Templates in AWS EC2 Auto Scaling

Author Amit Kumar
0 upvote
Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

Introduction

In this blog, we will create a launch template that defines a base configuration without an AMI or consumer records script. After you create your release template, you can create a new edition and add the AMI and consumer statistics that have the modern model of your application for checking out. This results in variations of the launch template. 

Storing a base configuration lets you hold the required trendy configuration parameters. You can create a new edition of your launch template from the bottom structure on every occasion you want. You can also delete the varieties used for trying out your application when you do not want them. We have a lot to learn, so let's get started.

Create a Launch Template for an Auto Scaling group

Before you could create an Auto Scaling institution using a launch template, you should create a launch template that includes the specifications required to release an EC2 instance, consisting of the Amazon Machine Image (AMI) ID and an example kind.

A launch template presents complete functionality for Amazon EC2 Auto Scaling and new features of Amazon EC2 together with the contemporary technology of EBS Provisioned IOPS volumes (io2), EBS quantity tagging, T2 Unlimited instances, Elastic Inference, and Dedicated Hosts.

The following procedure works for developing a new release template. After you create your launch template, you may begin the Auto Scaling organisation with the aid of following the commands in these subjects:

  • Create an Auto Scaling institution with the usage of a launch template
     
  • Auto Scaling groups with a couple of example types and buy options
     
  • Create an Auto Scaling institution with the use of attribute-based total example kind choice
Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Copy Launch Configurations to Launch Templates

To migrate from launch configurations to launch templates, you must reproduce or recreate your release configurations as launch templates. We suggest that you migrate to launch templates to take benefit of the modern features of Amazon EC2 and Amazon EC2 Auto Scaling.

If you reproduce your launch configurations, you can migrate them unexpectedly, or you could carry out an incremental migration over the years by choosing which release designs to copy. The copying feature is to be had best from the console.

Copy a Release Configuration to a Launch Template (Console)

  1. Select the Amazon EC2 console at AWS.
     
  2. On the navigation pane, beneath Auto Scaling, choose Launch Configurations.
     
  3. Select the release configuration you want to replicate and choose Copy to release template; copy selected. These units up a brand new release template with the same name and options because of your selected launch configuration.
     
  4. For the New release template call, you could use the name of the launch configuration (the default) or enter a brand new ring. Launch template names ought to be particular.
     
  5. (Optional) To create an Auto Scaling group using the new release template, pick Create an Auto Scaling organisation the usage of the brand new template.
     
  6. Choose Copy.
     

Use the subsequent technique to recognise that you need to replicate all release configurations to launch templates.

To Replica all Launch Configurations to Release Templates (Console)

  1. Select the Amazon EC2 console at Amazon EC2.
     
  2. On the navigation pane, under Auto Scaling, pick Launch Configurations.
     
  3. Choose Copy to release template, Copy all. This copies every release configuration in the contemporary Region to a brand new release template with equal calls and alternatives.
     
  4. Choose Copy.

Replace a Launch Configuration with a Launch Template

When you correct an Auto Scaling institution with an existing release configuration, you've chosen to replace the release configuration with a launch template.

After you update the release configuration for an Auto Scaling group, any new instances are launched using the brand new release template. Existing examples are not affected. To update the prevailing times, terminate them so that they are changed by using your Auto Scaling institution, or allow automatic scaling and replace earlier times with more modern times based on your termination rules.

To put back the launch configuration for an Auto Scaling institution (console)

  1. Unfolded the Amazon EC2 Auto Scaling console at Amazon AutoScaling.
     
  2. Choose the test field next in your Auto Scaling group.
     
  3. A split-pane opens up within the bottom a part of the page, showing information about the organisation it indeed is selected.
     
  4. On the Details tab, pick Launch configuration, Edit.
     
  5. Choose Switch to release the template.
     
  6. For the Launch template, choose your release template.
     
  7. For Version, pick out the launch template version as wanted. After creating variations of a launch template, you can select whether the Auto Scaling institution uses the default or the modern-day version of the release template whilst scaling out.
     
  8. When you have completed it, select Update.
     

To update a release configuration use the command line. You can use one of the following commands:

  • replace-auto-scaling-organization (AWS CLI)
     
  • Update-ASAutoScalingGroup (AWS Tools for Windows PowerShell)

Request Spot Instances for Fault-Tolerant and Flexible Packages

When you create a release template to release only Spot Instances, preserve the subsequent concerns in mind:

  • Spot charge. You pay the current Spot price most effectively for the Spot Instances that you launch. This pricing changes slowly over the years based on lengthy-time period tendencies in supply and demand.
     
  • You were setting your best fee. You can optionally include a maximum fee in line with the hour for Spot Instances on your launch template. If your total cost exceeds the current Spot rate, the Amazon EC2 Spot service fulfils your request if capacity is to be had. If the rate for Spot Instances rises above your maximum charge for a walking example to your Auto Scaling institution, it terminates your instance.
     
  • They are balanced throughout Availability Zones. If you specify more than one Availability Zones, Amazon EC2 Auto Scaling distributes the Spot requests across the required zones. If your maximum fee is just too low in a single Availability Zone for any requests, Amazon EC2 Auto Scaling checks whether recommendations have been fulfilled in the different zones. If so, Amazon EC2 Auto Scaling cancels the failed requests and redistributes them throughout the Availability Zones that have requests fulfilled. If the rate in an Availability Zone without a fulfilled request drops enough that destiny requests are triumphant, Amazon EC2 Auto Scaling rebalances across all Availability Zones.
     
  • Spot Instance termination. Launching templates can terminate spot Instances at any time. The Amazon EC2 Spot carrier can remove Spot Instances to your Auto Scaling group because the accessibility of, or price for, Spot Instances changes. When scaling or appearing in health exams, Amazon EC2 Auto Scaling can similarly terminate Spot Instances that may end On-Demand Instances. When an instance is terminated, any storage is deleted.
     
  • It is maintaining your favoured capability. When a Spot Instance is closed, Amazon EC2 Auto Scaling attempts to release every other Spot Instance to preserve the favoured potential for the organisation. If the cutting-edge Spot rate is less than your price, it gets a Spot Instance. If the request for a Spot Instance is useless, it keeps attempting.
     
  • You are changing your maximum fee. To exchange your full payment, create a news release template, replace a current launch template with the brand new most charge, and partner it with your Auto Scaling institution. The present Spot Instances hold to run as long as the most rate precise inside the release template used for those instances is better than the modern-day Spot rate. If you probably did now not set a maximum charge, the default maximum charge is the On-Demand charge.

Examples for developing and coping with release templates

You can make and control launch templates via the AWS Management Console, AWS CLI, or SDKs. This segment shows you examples of making and managing launch templates for Amazon EC2 Auto Scaling from the AWS CLI.

{
    "LaunchTemplateName": "my-template-for-auto-scaling",
    "VersionDescription": "test description",
    "LaunchTemplateData": {
        "ImageId": "ami-04d5cc9b88example",
        "InstanceType": "t2.micro",
        "SecurityGroupIds": [
            "sg-903004f88example"
        ], 
        "KeyName": "MyKeyPair",
        "Monitoring": {
            "Enabled": true
        },
        "Placement": {
            "Tenancy": "dedicated"
        },
        "CreditSpecification": {
            "CpuCredits": "unlimited"
        },
        "MetadataOptions": {
            "HttpTokens": "required",
            "HttpPutResponseHopLimit": 1,
            "HttpEndpoint": "enabled"
        }
    }
}

To create a primary release template

  • Put back the ami-04d5cc9b88 example with the ID of the AMI from which to release the times.
     
  • Replace t2. Micro with an example type is compatible with the AMI that you are precise.
     

This instance creates a release template with the call my-template-for-auto-scaling. If the samples created by this release template are released in a default VPC, they receive a public IP address by default. If the times are launched in a non default VPC, they no longer receive a public IP address by default.

Aws ec2 create-release-template --release-template-xyz my-template-for-vehicle-scaling --version-description version1 
  --release-template-data '"ImageId":"ami-04d5cc9b88example","InstanceType":"t2.Micro"'


Specify tags that tag instances at launch

aws ec2 create-launch-template --launch-template-xyz my-template-for-auto-scaling --version-description version1 \
  --launch-template-data '{"TagSpecifications":[{"ResourceType":"instance","Tags":[{"Key":"purpose","Value":"webserver"}]}],"ImageId":"ami-04d5cc9b88example","InstanceType":"t2.micro"}'


Specify an IAM role to pass to instances

aws ec2 create-launch-template --launch-template-xyz my-template-for-auto-scaling --version-description version1 \
--launch-template-data '{"IamInstanceProfile":{"Xyz":"my-instance-profile"},"ImageId":"ami-04d5cc9b88example","InstanceType":"t2.micro"}'


Assign public IP addresses

aws ec2 create-launch-template --launch-template-xyz my-template-for-auto-scaling --version-description version1 \
  --launch-template-data '{"NetworkInterfaces":[{"DeviceIndex":0,"AssociatePublicIpAddress":true,"Groups":["sg-903004f88example"],"DeleteOnTermination":true}],"ImageId":"ami-04d5cc9b88example","InstanceType":"t2.micro"}'


Specify a user data script that configures instances at launch

aws ec2 create-launch-template --launch-template-xyz my-template-for-auto-scaling --version-description version1 \
--launch-template-data '{"UserData":"IyEvYmluL2Jhc...","ImageId":"ami-04d5cc9b88example","InstanceType":"t2.micro"}'


Specify a block device mapping

aws ec2 create-launch-template --launch-template-xyz my-template-for-auto-scaling --version-description version1 \
--launch-template-data '{"BlockDeviceMappings":[{"DeviceXYZ":"/dev/xvdcz","Ebs":{"VolumeSize":22,"VolumeType":"gp2","DeleteOnTermination":true}}],"ImageId":"ami-04d5cc9b88example","InstanceType":"t2.micro"}'     


Specify Dedicated Hosts to bring software licenses from external vendors

aws ec2 create-launch-template --launch-template-xyz my-template-for-auto-scaling --version-description version1 \
  --launch-template-data '{"Placement":{"Tenancy":"host","HostResourceGroupArn":"arn"},"LicenseSpecifications":[{"LicenseConfigurationArn":"arn"}],"ImageId":"ami-04d5cc9b88example","InstanceType":"t2.micro"}'


Specify an existing network interface

aws ec2 create-launch-template --launch-template-xyz my-template-for-auto-scaling --version-description version1 \
  --launch-template-data '{"NetworkInterfaces":[{"DeviceIndex":0,"NetworkInterfaceId":"eni-b9a5ac93","DeleteOnTermination":false}],"ImageId":"ami-04d5cc9b88example","InstanceType":"t2.micro"}'


Create multiple network interfaces

aws ec2 create-launch-template --launch-template-xyz my-template-for-auto-scaling --version-description version1 \
  --launch-template-data '{"NetworkInterfaces":[{"DeviceIndex":0,"Groups":["sg-903004f88example"],"DeleteOnTermination":true},{"DeviceIndex":1,"Groups":["sg-903004f88example"],"DeleteOnTermination":true}],"ImageId":"ami-04d5cc9b88example","InstanceType":"t2.micro"}'

Manage your launch templates

The AWS CLI consists of numerous other commands that assist you in manipulating your launch templates.

List and describe your launch templates.

You can use two AWS CLI instructions to get your release templates statistics: describe-release-templates and describe-release-template-variations.

The following example provides a precis of the specified release template.

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


The following describe-release-template-versions command presents data describing the variations of the required launch template my-template-for-auto-scaling.

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


Create a launch template version

aws ec2 create-launch-template-version --launch-template-id lt-068f72b729example --version-description version2 \
  --source-version 1 --launch-template-data "ImageId=ami-c998b6b2example"


Delete a launch template version

aws ec2 delete-launch-template-versions --launch-template-id lt-068f72b729example --versions 1


Delete a launch template

aws ec2 delete-launch-template --launch-template-id lt-068f72b729example

Frequently Asked Questions

What is the distinction between release template and release configuration in AWS?

Release configurations are used with Auto Scaling Groups. While release templates are used whilst you release an example the use of the AWS EC2 console, an AWS SDK, or a command-line device. Launch templates allow you to save the parameters (AMI, instance type, security corporations, key pairs and so forth.)
 

What gain does a release template have over a launch configuration?

However, defining a launch template rather than a launch configuration lets you have a couple of variations of a launch template. With versioning of release templates, you could create a subset of the entire set of parameters. Then, you may reuse it to create different variations of the equal release template.
 

Can you regulate a release template?

Modifies a release template. You can specify which version of the release template to set as the default version. When launching an example, the default model applies while a release template model is not specified.
 

What are AWS launch templates?

A release template is an Amazon Elastic Compute Cloud (EC2) feature that reduces the number of steps which might be required to create an AWS example via capturing all launch parameters inside one useful resource.

Conclusion

This blog extensively discussed the concept of Launching Templates in AWS EC2 Auto Scaling and one of the Launching Templates in AWS EC2 Auto Scaling offered by AWS EC2. We mentioned the significance of making and converting the configuration in AWS  in detail with the assistance of an instance application. 

Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and Algorithms, Competitive Programming, JavaScript, System Design, and many more! If you want to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio! But if you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc; you must look at the problems, interview experiences, and interview bundle for placement preparations.

Nevertheless, you may consider our paid courses to give your career an edge over others!

Do upvote our blogs if you find them helpful and engaging!

Happy Learning!

Previous article
AWS Well-Architected Tool
Next article
Launching Configurations in AWS EC2 Auto Scaling
Live masterclass