Day 40 - 90daysofdevops : AWS EC2 Automation ?

Day 40 - 90daysofdevops : AWS EC2 Automation ?

Automation in EC2

Amazon EC2 allows you to automate many routine tasks to improve efficiency and reduce manual operations and maintenance costs. Some tasks you can automate in EC2 are:

? Instance launching - You can write scripts or use AWS services like CloudFormation to automatically launch new EC2 instances based on templates. This ensures consistency and repeatability.

? Instance termination - You can set up auto scaling policies or write scripts to automatically terminate idle or unused instances to save costs.

? Backup and snapshotting - You can automate the creation of EBS volume snapshots on a schedule to ensure your data is regularly backed up.

? Security updates - You can automate the installation of OS and software security updates on your EC2 instances to keep them patched and secure.

? Scaling - You can set up auto-scaling groups that automatically scale your EC2 fleet up or down based on metrics or schedules. This helps handle fluctuations in demand.

? Configuration management - You can use tools like Chef, Puppet or Ansible to automate and standardize the configuration of your EC2 instances.

? Monitoring - You can configure CloudWatch alarms to trigger automated actions when certain thresholds are met, like terminating unhealthy instances.

Automating routine tasks in EC2 helps improve reliability, security and cost efficiency.


Task 1: Creating a Launch Template, Launching Instances, and Setting Up an Auto Scaling Group in AWS EC2

  • 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.

Step 1: Create a Launch Template

  1. Navigate to the EC2 Dashboard: Go to your AWS Management Console, then under the "Compute" section, click on "EC2".
  2. Create a Launch Template: In the EC2 Dashboard, click on "Launch Templates" in the left navigation pane, and then click the "Create launch template" button.

Configure Template Details:

  • Provide a name and description for the launch template.
  • For "AMI ID," select the Ubuntu AMI.
  • For "Instance type," select t2.micro.
  • Under "Advanced Details," provide your user data script that installs Jenkins and Docker (you mentioned using Day 39 User data script).

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

#!/bin/bash
 sudo apt update
 sudo apt install openjdk-11-jre -y

 curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \
   /usr/share/keyrings/jenkins-keyring.asc > /dev/null
 echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
   https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
   /etc/apt/sources.list.d/jenkins.list > /dev/null
 sudo apt-get update
 sudo apt-get install jenkins -y

 sudo systemctl enable jenkins
 sudo systemctl start jenkins

 sudo apt-get update
 sudo apt-get install docker.io -y
 sudo systemctl start docker
        

Choose “Create launch template”. below you can see template is created.

Create 3 Instances using Launch Template, there must be an option that shows number of instances to be launched.

Step 2: Launch Instances using the Launch Template

  1. Navigate to Launch Instances: In the EC2 Dashboard, click on "Instances" in the left navigation pane, and then click the "Launch Instances" button.
  2. Select Launch Template: Choose the "My launch template" tab and select the launch template you created in the previous step.
  3. Configure Instance Details: Configure settings like instance count, network settings, IAM role, etc.
  4. Add Storage: Configure the storage settings as needed.
  5. Configure Security Group: Configure security group settings as needed.
  6. Review and Launch: Review your settings and click the "Launch" button.

You can see three instances created from template.


Task 2: Create an Auto Scaling Group

Creating an Auto Scaling Group will automatically manage the number of instances running based on certain conditions like CPU utilization, network traffic, etc.

  1. Navigate to Auto Scaling Groups: In the EC2 Dashboard, click on "Auto Scaling Groups" in the left navigation pane, and then click the "Create Auto Scaling group" button.
  2. Configure Group Details:Choose the launch template you created earlier.Configure the group size settings, such as desired, minimum, and maximum instances.
  3. Configure Scaling Policies: Set up scaling policies based on conditions like CPU utilization.
  4. Configure Notifications and Tags (Optional): Configure notifications and add tags if needed.
  5. Review and Create: Review your settings and click the "Create Auto Scaling group" button.

For “Network”, choose the VPC and subnet you want the instances to launch in.

For “Load balancing”, choose any option as per your requirement.

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

  • Review the details and click on "Create Auto Scaling group" to create the group.

Autoscaling group is created.


Happy Learning :) #90daysofdevops #devops #autoscaling

要查看或添加评论,请登录

Prakash Bohara的更多文章

社区洞察

其他会员也浏览了