AWS - Create a Launch Template for EC2 Instances
A launch template function is that it specifies the instance's configuration information, such as:
- Amazon Machine Image (AMI)
- Instance type
- Key pair
- Security groups
- Other parameters used to launch EC2 instances.
Ways to create a Template and launching it
Step 1: Create an EC2 instance.
OS: Ubuntu 18.05
Instance type: t2.micro
Security Group: WebServer(port 22,80 are opened)
userdata:
#!/bin/bash
sudo su
sudo apt update
sudo apt install apache2 -y
sudo echo "<h1>Testing the Launch Template app </h1>" > /var/www/html/index.html
Step 2: Verify Instance get created with Apache installed and in the running state.
sudo su
systemctl status apache2
Take Public IP address of EC2 instance and check on browser.
Step 3: Create an AMI from EC2 instance.
Step 3: Create an AMI from EC2 instance.
Select EC2 instance
Action --> Image and Tempates ---> Image
Image: irfan/apacheimg
Action --> Image and Tempates ---> Image
Image: irfan/apacheimg
Step 4: Verify Image get created
Images ---> AMIs
Images ---> AMIs
Step 5: Create a Template from this image
Instances ---> Launch Template
Click on Create Template
Launch Template Name: ApacheTemplate
Template Version: Prod
Application and OS Images AMIs: irfan/apacheimg
Instance type: t2.micro
key pair: Irfan-RSA
Security Group: Webserver
Click on Create launch Tempate
Step 6: Create Ec2 instance from Template
Select the template ApacheTemplate
Action --> Launch Instance from template
Review the template settings
Launch Instance
Instances ---> Launch Template
Click on Create Template
Launch Template Name: ApacheTemplate
Template Version: Prod
Application and OS Images AMIs: irfan/apacheimg
Instance type: t2.micro
key pair: Irfan-RSA
Security Group: Webserver
Click on Create launch Tempate
Step 6: Create Ec2 instance from Template
Select the template ApacheTemplate
Action --> Launch Instance from template
Review the template settings
Launch Instance
Step 7: Verify the Instance is created and apache is installed with a modified index.html file