Bootstrap FreeKB - Amazon Web Services (AWS) - Create an EC2 instance using a Launch Template
Amazon Web Services (AWS) - Create an EC2 instance using a Launch Template

Updated:   |  Amazon Web Services (AWS) articles

This assumes you have already configured the aws command line tool. If not, check out my article on Getting Started with the AWS CLI.

At a high level, there are 3 types of EC2 instances

An EC2 Launch Template is a way to set certain defaults for launching a new EC2 instance, such as the SSH Key Pairs, Network Subnets, Security Groups, Amazon Machine Image, et cetera that the EC2 Instance will have. An EC2 Launch Template is often used with an EC2 Auto Scaling Group, to auto scale a collection of EC2 instances based on needs, such as when load is high or low is low.

The aws ec2 create-launch-template command can be used to create the Launch Template. This a super simple example to create an t2.micro EC2 instance using Amazon Machine Image (AMI) ami-0277155c3f0ab2930 and the EC2 instance will not have a public IP address. Realistically, you would have a many more configurations. This is just to get the idea across. 

aws ec2 create-launch-template \
--launch-template-name my-launch-template \
--version-description v1 \
--launch-template-data 
  '{"NetworkInterfaces":
     [
       {
         "AssociatePublicIpAddress":false,
         "DeviceIndex":0
       }
     ],
    "ImageId":"ami-0277155c3f0ab2930",
    "InstanceType":"t2.micro"
   }'

 

Then the aws ec2 run-instances command can be used to create and start a new EC2 instance using the Launch Template.

aws ec2 run-instances --launch-template LaunchTemplateId=lt-0d9de63ffd4a17813

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 76fdee in the box below so that we can be sure you are a human.