Day 40 - 90daysofdevops : AWS EC2 Automation ?
Prakash Bohara
Immediate Joiner | #Engineer Devops ?? | MySQL | LINUX ??| Git/GitHub?? | AWS ? | DOCKER ??| KUBERNETES ?? | TERRAFORM ??? | JENKINS | ANSIBLE??| EKS/GKE
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
Step 1: Create a Launch Template
Configure Template Details:
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
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.
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.
Autoscaling group is created.
Happy Learning :) #90daysofdevops #devops #autoscaling