AWS Autoscaling allows us to automatically add or remove instances when certain thresholds are reached. There are two components that needs to be created in order to setup an autoscaling group in AWS,
An AWS launch configuration: This is the component that defines AMIs and regions like configurations.
An autoscaling group: This specifies the properties used to scale resources. For example the CPU threshold to be considered.
In this section I will be reusing the set up we used in the previous sections. In addtion to the previous content, I will be craeting a couple of additional resources as follows.
In here, I first define the launch configuration. There I specify a name prefix and an ami with some other properties. Next it is the autoscaling group. In there I specify which subnets of the VPC to be used when launching the EC2 instances. Associate it with a launch configuration and specify the minimum and maximum number of instances it could have, and so on.
Then let's create a file with the name autoscalingpolicy.tf,