Setting Up an Auto Scaling Group with AWS CLI

Similar to my last project, we are setting up an Auto Scaling group, but this time though our terminal. An AWS account is needed for this project, along with the AWS CLI downloaded to your terminal. This was performed on a macOS so the download process may slightly differ on other operating systems.

For all other OS environments, follow this link to download AWS CLI correctly to your environment: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html

Download AWS CLI to your terminal

Run the below code to verify that the AWS CLI can be found and run.

Taking these above steps will allow you to locate where the AWS CLI is on your computer and which version you have downloaded.

Create a user and give them programmatic and console access

You will be returned code in JSON format indicating your user name, user ID, ARN (Amazon Resource Name), and the creation date of this user. Note: you will see your AWS account ID in the ARN output information.

I already have an Admin group created in my AWS account, therefore giving programmatic and console access to my new user is simply writing code and adding them to my Admin group.

Using the below code will verify that your new user was successfully placed in your group.

Download the Access Key and Secret Access Key in a safe place

Your information is returned in JSON format. The information consists of your user name, access key ID, status, secret access key, and the creation date. Saving your access and secret access key is highly important.

The above code opens a file for you to input the new user’s access key and secret access key. From the returned information in the JSON format above, copy and paste the two keys into this vim file. You will see that the default user is also there. Knowing how to do this is important when handling multiple credentials in further projects you may be given.

Create an EC2 Instance (t3.nano, Amazon 2 AMI)

In this step, the default settings are used for the security group and subnet ID that may have previously been set up in our AWS account. We are asked to use Amazon 2 AMI in this project, so it is pasted below in the code, along with our instance type.

List the Instance to ensure creation

The output above in our terminal proves that our Instance has been successfully created, and we can go into the AWS Console to double check that success.

Create Auto Scaling group with a minimum of 2 and maximum of 5

The code above will create instances that you can check in your console, seen below. In sticking with using the CLI, the code below will provide you with your Auto Scaling group with the given name.

Double-checking the Auto Scaling group on the Console.

Clean up environment

Now that we have successfully completed our task, it is time to undo everything by following these two steps:

  1. Delete launch template

2. Delete group while terminating any unwanted EC2 Instances

Again, double checking that your environment has been cleaned up never hurts, and may help you avoid unnecessary costs garnered while attempting this project.