AWS EC2 Automation ☁

Dhwarika JhaDhwarika Jha
3 min read

Automation in EC2

Amazon EC2 or Amazon Elastic Compute Cloud can give you secure, reliable, high-performance, and cost-effective computing infrastructure to meet demanding business needs. Also, if you know a few things, you can automate many things.

Launch template in AWS EC2

  • You can make a launch template with the configuration information you need to start an instance. You can save launch parameters in launch templates so you don't have to type them in every time you start a new instance.

  • For example, a launch template can have the AMI ID, instance type, and network settings that you usually use to launch instances.

  • You can tell the Amazon EC2 console to use a certain launch template when you start an instance.

Instance Types

Amazon EC2 has a large number of instance types that are optimised for different uses. The different combinations of CPU, memory, storage and networking capacity in instance types give you the freedom to choose the right mix of resources for your apps. Each instance type comes with one or more instance sizes, so you can adjust your resources to meet the needs of the workload you want to run.

AMI

An Amazon Machine Image (AMI) is an image that AWS supports and keeps up to date. It contains the information needed to start an instance. When you launch an instance, you must choose an AMI. When you need multiple instances with the same configuration, you can launch them from a single AMI.

Task1

  • Create a launch template with Amazon Linux 2 AMI and t2.micro instance type with Jenkins and Docker setup (You can use the Day 39 User data script for installing the required tools.

    1. Open the Amazon EC2 console.

    2. In the left navigation pane, choose "Launch Templates".

    3. Choose "Create launch template".

    4. In the "Create a launch template" page, enter a name for the launch template

    5. For "Ubuntu Machine (AMI)", choose "Ubuntu"

    6. For "Instance type", choose "t2.micro"

    7. create or choose a security group.

    8. In the "Advanced Details" section, paste the user data script for installing Jenkins and Docker in the "User data" field.

    9. Choose "Create launch template". below you can see the template has been created

    10. Also, we can create a template using EC2 Instance, Select the EC2 instance, click action, click Image and Templates, and click create a template from the instance.

  • Create 3 Instances using Launch Template

  • To launch three instances using the launch template

    1. In the Amazon EC2 console, choose "Launch an instance from templates" in the left navigation pane.

    2. Select the launch template that you just created.

    3. Choose "Launch instances" to launch the instances.

      You can see three instances created from a template.

  • You can go one step ahead and create an auto-scaling group

    1. In the left navigation pane, choose "Auto Scaling Groups".

    2. Choose "Create Auto Scaling Group".

    3. In the "Create Auto Scaling Group" page, enter a name for the auto-scaling group.

    4. For "Launch Template", choose the launch template we created earlier.

    5. For "Load balancing", choose any option as per your requirement.

    6. In the "Group Size" page, enter the desired capacity for the auto-scaling group, such as 2.

      For "Scaling policies", you can choose to set up scaling policies based on various metrics such as CPU utilization, network in/out, and others. Choose the policy target tracking policy.

1
Subscribe to my newsletter

Read articles from Dhwarika Jha directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Dhwarika Jha
Dhwarika Jha