Create an Auto Scaling Group using the AWS Command Line Interface

Create IAM User

Create User Groups

Install AWS CLI

curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"sudo installer -pkg AWSCLIV2.pkg -target /
which awsaws --version
aws configure

Create Security Group

aws ec2 create-security-group --group-name SG-WebServer --description "WebServer Secuirty Group"
aws ec2 authorize-security-group-ingress --group-id sg-0150ceaa8eac75827 --protocol tcp --port 80 --cidr  0.0.0.0/0

Create EC2 Instance

#!/bin/bash
yum update -y
yum install -y httpd
echo '<h1>This is our test web server</h1>' >
/var/www/html/index.html
systemctl start httpd
systemctl enable httpd
aws ec2 run-instances --image-id ami-0d5eff06f840b45e9 --count 1 --instance-type t2.micro --tag-specifications 'ResourceType=instance, Tags=[{ Key=Name,Value=MyInstance}]' --security-group-ids sg-0150ceaa8eac75827 --user-data file://UserData.txtNote: You will need to go into console as if you were creating a new instance to get AMI information and for the security group provide the information for GroupId you created.
aws ec2 describe-instances --filters "Name=tag:Name,Values=MyInstance" --query "Reservations[].Instances[].InstanceId"

Create Auto Scaling Group

aws autoscaling create-auto-scaling-group --auto-scaling-group-name WebServerASG-from-instance \
--instance-id i-0703f458446de3150 --min-size 2 --max-size 5 --desired-capacity 2
aws ec2 describe-instances --filters "Name=tag:aws:autoscaling:groupName,Values=WebServerASG-from-instance" --query "Reservations[].Instances[].InstanceId"

Clean Up

aws ec2 terminate-instances --instance-ids i-0703f458446de3150
aws autoscaling delete-auto-scaling-group --auto-scaling-group-name WebServerASG-from-instance --force-delete
aws ec2 describe-instances --filters "Name=instance-state-name,Values=running" --query "Reservations[].Instances[].InstanceId"
aws ec2 delete-security-group --group-name SG-WebServer

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Stay logged during a test session in Cypress

Android fundamentals 03.3: Support libraries

How do you introduce a scratch to a child?

Part 2— Data Structures and Algorithms in Plain English

Polarity Service Changes (Active as of 17/02/2022 9pm CST)

Application Strategy and Digital Transformation Series — Part 4

Importance of Coding in the 21st Century

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Betty Barrera

Betty Barrera

More from Medium

Top 5 Plugins for Revit

How to Install Magento 2 Using Composer in Ubuntu/Localhost

How to Install Magento 2 Using Composer in Ubuntu/Localhost

Sitecore DEF + SXA — Part 2: Resolving SXA local data source item

Cost Optimization | AWS | Is it Secure enough?