Create an Auto Scaling Group using the AWS Command Line Interface

The following will provide directions on creating an Auto Scaling Group using the AWS Command Line Interface instead of using the Graphical User Interface (GUI).
Create IAM User
User will require programmatic and console access.
1. Navigate IAM in AWS Console
2. Click on Users
3. Click on Add User
- User name — Create user name
- Access type — Select both Programmatic access and AWS Management Console access
- Console password — Select custom password
- Require password reset — Uncheck User must create a new password at next sign-in

4. Click Next for Permissions, we will skip for now
5. Click Next for Tags, no tags required
6. Click Next for Review
7. Click Create User
8. Click on Download .csv, we will need this information.
Create User Groups
1. Navigate to User Groups, we will create a group to grant our new user permissions.
2. Click Create Group
- User Group Name — Create group name
- Add User to the Group — Select User Name created to grant permissions
- Attach Permission Policies — Select AmazonEC2FullAccess
3. Click Create Group
Install AWS CLI
The following steps are what you will use if installing on MacOS Terminal, but you could find direction here if you wish to use other options or platforms.
1. Open Terminal
2. Install AWS CLI using the following commands:
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"sudo installer -pkg AWSCLIV2.pkg -target /
3. Verify the installation:
which awsaws --version
4. AWS Configurations
aws configure
5. The following question will be prompted, reference .csv file dowloaded:
- AWS Access Key ID: Enter Access key ID
- AWS Secret Access Key [None]: Enter Secret access key
- Default region name [None]: us-east-1
- Default output format [None]: Leave blank
Create Security Group
Security Group will be created for our instance that will allow HTTP from 0.0.0.0/0 in order to access our site:
1. Create Security Group SG-WebServer using following command:
aws ec2 create-security-group --group-name SG-WebServer --description "WebServer Secuirty Group"
2. If command runs successfully the GroupId for the Security Group will be displayed. You will need this information so make a note of it.

3. Run the following command to update the inbound rules for the Security Group. For the group-id make sure you use your GroupID created.
aws ec2 authorize-security-group-ingress --group-id sg-0150ceaa8eac75827 --protocol tcp --port 80 --cidr 0.0.0.0/0
Create EC2 Instance
1. Create a file titled UserData.txt containing the following:
#!/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
2. Create EC2 instance using the following command:
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.
3. After successfully running the command it will output a json template withe the instance information.
4. To confirm your EC2 instance was created run the following command filtering by Tag to only view new instance created.
aws ec2 describe-instances --filters "Name=tag:Name,Values=MyInstance" --query "Reservations[].Instances[].InstanceId"
5. You will see your instance id:

Create Auto Scaling Group
Now that we have created EC2 instance and verified it we will create Auto Scaling Group using the same instance. You will need the Instance ID from the instance created.
1. Create Auto Scaling Group running the following command, the min size was set to 2, the max to 5 and desired capacity to 2.
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
2. Run the following command to list all instances with name of WebServerASG-from-instance.
aws ec2 describe-instances --filters "Name=tag:aws:autoscaling:groupName,Values=WebServerASG-from-instance" --query "Reservations[].Instances[].InstanceId"
5. You will see your instance created with Auto Scaling Group.

Clean Up
We may now delete everything we created since we completed our task and no longer needed. This could be done from the Console or Terminal.
1. Delete original instance created.
aws ec2 terminate-instances --instance-ids i-0703f458446de3150
2. Delete our Auto Scaling Group created with force delete since they are still running.
aws autoscaling delete-auto-scaling-group --auto-scaling-group-name WebServerASG-from-instance --force-delete
3. Now run command to list our running instances, you should only get empty brackets [] back since everything has been terminated.
aws ec2 describe-instances --filters "Name=instance-state-name,Values=running" --query "Reservations[].Instances[].InstanceId"
4. Delete Security Group created.
aws ec2 delete-security-group --group-name SG-WebServer
5. Delete test user created from AWS Console.