Innovate anywhere, anytime withruncode.io Your cloud-based dev studio.
Amazon Web Services

Autoscaling Application with AutoScaling Groups and AWS LoadBalancer

2022-07-19

Creating AMI:

  • Launch an instance, Setup your application on it and shut it down.
  • Go to your AWS EC2 Console. Select your instance and create AMI, by right-click on the selection and choose Image > Create Image.
  • Wait for it to AMI creation to complete, you can check its status in Image > AMI on the Left Side Menu.
  • Wait for Status to be Available and then terminate the original instance, if needed.

Create Load Balancer:

  • Navigate to Load Balancer Section on Left Side Menu and select Create Load Balancer
  • Choose your Load Balancer Type Appropriately  between Application, Network and Classic Load Balancer.
  • Configure your Security group and other setting Appropriately and Create  a Target Group (dont choose any instances) and wait for the Load Balancer to Launch.
  • After Launch, when you visit Load Balancer URL, It should throw an 503 Service not available exception (which is already expected, since we didnt host our website yet)

Now that all is set, Lets setup Auto Scaling and Load Balancing for your Application.

Creating Auto Scaling Group:

Before we can create a Auto Scaling Group, we need to create a Launch Configuration (you can either use a single AMI to create a Launch Configuration or use Launch Templates.). You can do this by choosing Launch Configuration in AUTO SCALING section on your left-side menu, Click on Create Launch Configuration and choose your previously created AMI, Instance Type and Instance Settings like Security Groups and Storage Settings etc., and complete creation of Launch Configuration.

  • Choose Auto Scaling Groups in “AUTO SCALING” section in left-side menu.
  • Click on “Create Auto Scaling Group”, Choose use existing Launch Configuration and select the configuration you selected earlier.
  • Create Auto Scaling Group with your preferred Settings. Making Sure you select “Receive traffic from one or more load balancers” in Advanced Details.
  • Launch your Auto Scaling Group and wait for instances to Launch
  • Refresh the Load Balancer URL to see your Application.

Testing Auto Scaling Group:

Based on whether you selected CPU Average or Average Network In/Out or Load Balancer Request Count per target. Create a suitable load and check your AWS EC2 instance count increasing and they being Auto Added to your Load Balance Target Group.

Note: If you create a classic Load Balancer, then you will be asked to select the Load Balancer, If you created a Network/Application Load Balancer, you will be asked to choose a Target Group During Creation of Auto Scaling Group.