DEV Community

Hammad Khan for AWS Community Builders

Posted on

Creating Launch Template & Auto-scale group for Ec2 Creation and Automation

Our goal is to create an auto-scale group which can automatically launch a new EC2 instance from the launch template based on the EC2 health check monitoring.
It will kill/terminate the old EC2 instance automatically and create new one with same configuration and basic software application installations which were part of its user data script.
Auto-scale Group Creation

Name your auto-scale group and create launch template for it

Create New Launch template in same AWS region where you will create your auto-scale group, and your Launch template will help you to
• Choose OS of your choice AMI (Amazon machine image).
• Apply Essential tags to categorize your EC2 instances accordingly.
• Select Instance type to select best compatible type for your EC2 instance.
• Attach Key pairs to access your machines remotely.
• Select subnet and security group for your EC2 instance for connectivity and security
• Attach EBS volumes for your instance
• Add User data script to install basic software’s and application during instance launch.

In auto-scale group select your created launch template and it will show the configuration of the template

The Auto Scaling group must be created in the same VPC and choose the same security group which you specified in your launch template. For the Availability Zones and subnets, choose one or more subnets in the specified VPC so you can use subnets in multiple Availability Zones for high availability

You can register your Amazon EC2 instances with a load balancer or choose no load balancer option if you do not want LB configurations. In case of using ELB set the amount of time until Amazon EC2 Auto Scaling checks the Elastic Load Balancing health status of an instance after it enter in the InService state.
Cloud watch metrics provide the measurements that can be useful to identify potential issue, like number of terminating instances or number of pending instances.
Enable default instance warmup, so you can choose the warm-up time for your application on EC2 instance

For Desired capacity, enter the initial number of instances to launch from auto-scale group and set the minimum and maximum capacity of instance you want to launch from auto-scale group.
To automatically scale the size of the Auto Scaling group, choose the Target tracking scaling policy.
You can control whether an Auto Scaling group can terminate a particular instance when scaling in by enabling instance scale-in protection.

Add notifications and tags for your convenience to get notifications and categorize applications accordingly.

After review an Auto-scale group has been created

Create new instance from launch template

After EC2 instance creation it will be taken care by its auto-scale group which is integrated with the launch template and on every potential issue the instance will be spin up and will start working as per the user data script.

Top comments (0)