Description • Pre-requisites • Solution Architecture • How it works • Tech Stack • Author • License
This project consists of creating a structure in AWS for a auto scaling application. It is made up of the following components:
- VPC
- Internet Gateway
- Subnets
- Route Tables
- Security Groups
- Load Balancer
- Auto Scaling Group
- CloudWatch
- RDS
Before you begin, you will need to have the following tools installed on your machine: [Terraform] (https://www.terraform.io/) and [Git] (https://git-scm.com). You will need to have a [AWS Account] (https://aws.amazon.com/). In addition, it is good to have an editor to work with the code like [VSCode] (https://code.visualstudio.com/).
1 - Clone this repository.
git clone git@github.com:diogofiaminghi/terraform-application-auto-scaling.git
2 - Open console AWS.
IMPORTANT: Make sure you are in "us-east-1" region
- Go to EC2
- Network & Security >> Key Pairs
- Create Key Pair
- Name = terraform-application-auto-scaling
- Key pair type = RSA
- Privete key format = .pem
- Click on "Create key pair"
- The key is downloaded automatically
IMPORTANT: Copy the key to the same project directory (keep your key in a safe place and don't share it. You will use it to access the instances).
- Change permission.
chmod 400 terraform-application-auto-scaling.pem
3 - Add the key-name in your .gitignore file.
4 - You must now configure your AWS Access Keys using the bash terminal.
export AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXX
export AWS_SECRET_ACCESS_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5 - Terraform Commands in Project Folder
terraform init
terraform fmt
terraform validate
terraform plan -out=plan.out
terraform apply plan.out
6 - Now, to prove that everything worked, we will test the Auto Scaling.
-
AWS console >> EC2 >> Instances >> click on WEB instance >> monitoring >> CPU Utilization >> View in metrics >> periodo 10s >> auto-refresching 10s. Repit this for the second WEB instance in another browser tab.
-
In another browser tab, open Auto Scaling Grou >> Activity >> Activity history
-
In Load Balancer, copy the DNS name >> paste in another browser tab >> the html page must be loaded
-
connect via ssh to both web instances
ssh -i "terraform-application-auto-scaling.pem" ubuntu@the-public-ip-here
sudo stress-ng --cpu 32 --timeout 600 --metrics-brief
- observe the number of instances being increased and decreased as stress rises and falls. The test will end in 10 minutes.
7 - Do not forget to destroy the provisioned structure otherwise you will be able to receive invoices.
terraform destroy
The following tools were used in the construction of the project:
This project is under the license MIT.
Made with love by Diogo Fiaminghi 👋🏽 Get in Touch!