DEV Community

Cover image for Elastic Beanstalk Demo: Auto Scaling with a shared load balancer
Sri for AWS Community Builders

Posted on

Elastic Beanstalk Demo: Auto Scaling with a shared load balancer

Table of Contents

  1. Introduction
  2. Create a Security Group
  3. Create an Application Load Balancer
  4. Create Elastic Beanstalk Admin App
  5. Create Elastic Beanstalk Forum App
  6. Auto Scaling Verification
  7. Clean Up
  8. Summary
  9. Referrals

Introduction

One of the users of the AWS Certified Global Community had this query which caught my attention and made me want to check it out and see If I could help solve their problem. While doing this, I actually learned about shared load balancer with Elastic Beanstalk application and found it quite interesting, so I would like to share my learning with you.

With Elastic Beanstalk, you can quickly deploy and manage applications in the AWS Cloud without having to learn about the infrastructure that runs those applications. Elastic Beanstalk reduces management complexity without restricting choice or control. You simply upload your application, and Elastic Beanstalk automatically handles the details of capacity provisioning, load balancing, scaling, and application health monitoring. However, it becomes a bit difficult when we need to customise configurations such as Application Load Balancer, Listeners...etc

The user wanted to deploy two Elastic Beanstalk applications, let's say one for an Admin application and another one for Forum application. The problem the user was facing was particularly during auto-scaling - there seemed to be two instances created instead of one when she terminated one instance.

I'd like to share the demo below to show how to configure two different elastic Beanstalk applications using a shared load balancer and verify auto-scaling.

Note: We can only have a maximum of 5 Target Groups per Action per Application Load Balancer.

Demo

Let's get started with the demo.

Step 1. Create a Security Group

  1. We are going to create a Security Group for Elastic Beanstalk

  2. Navigate to EC2 > Security Groups > Create a new security group for your ALB, and set the following values:

    • Name: EBSSG
    • Add two Inbound rules to allow HTTP traffic from 0.0.0.0/0 (IPV4) and ::/0 (IPV6)

    EBS Security Group
    EBS-ALB-SG


Step 2. Create an Application Load Balancer

  1. Navigate to EC2 > Load Balancers.
  2. Click Create Load Balancer.
  3. Click the Create button under the Application Load Balancer and set the following values:
    • Name: SharedALB
    • Scheme: internet-facing
    • IP address type: ipv4
    • Load Balancer Protocol: HTTP
    • Port: 80
    • Leave the default VPC.
    • Select us-east-1a and us-east-1b AZs.
  4. Click Next: Configure Security Settings.
    • Note: Ignore the warning as we are not using HTTPS.
  5. Select EBSALB and Click Next
  6. Configure Routing, enter the following values and then Click Next:
    • Name: EBS-TG
    • Target type: Instance
    • Protocol: HTTP
    • Port: 80
    • Path: /index.html
  7. Click Next: Register Targets.
  8. Click Next: Review.
  9. Click Create
  10. Wait until the Application Load Balancer SharedALB is Active.

    Shared Application Load Balancer
    Shared_ALB

    Configure Security Options
    EBS-Admin2

    Configure Security Groups
    EBS-Admin3

    Configure Routing
    EBS-Admin4

    Register Targets
    Image description

    Review
    EBS-Admin6

    Application Load Balancer is Active
    ALB_Active

    Initial Listener Rules
    Initial_Listener_Rules


Step 3. Create Elastic Beanstalk Admin App

  1. Navigate to Elastic Beanstalk > Environments.
  2. Click Create a new environment.
  3. Select Web server environment
  4. Enter the following values:
    • Name: Admin
    • Platform: Node.js
    • Select Upload your code and upload nodejs_admin.zip
  5. Click Configure more options
    • Note: Step 6, 7 and 8 should be done in the same order.
  6. Select High availability under Presets.
  7. Click Edit next to Network and select same two Availability Zones for Load Balancer, Instance settings and Database settings.
  8. Click Edit next to Load Balancer
    • Load balancer type: Application Load Balancer
    • Type: Shared
    • Load balancer ARN: Select the ARN of SharedALB
    • Select default under Processes and click Actions > Edit > enter Path as /admin.html and click Save
    • Click Add Rule under Rules, Enter Name as admin, PathPattern as /*, Process as default and click Add
  9. Click Save.
  10. Click Create Environment.
  11. Wait for the environment to be create and then click on the application URL.

Note: If you need to make any changes to the code and create a zip on a Mac OS

cd /nodejs_admin
zip ../nodejs_admin -r * .[^.]*
Enter fullscreen mode Exit fullscreen mode

EBS Admin 1
EBS_Admin1

EBS Admin 2.1
EBS_Admin2.1

EBS Admin 2.2
EBS_Admin2.2

EBS Admin 3.1
EBS_Admin3.1

EBS_Admin 3.2
EBS_Admin3.2

EBS_Admin 3.3
EBS_Admin3.3

EBS Admin 4.1
EBS_Admin4.1

EBS Admin 4.2
EBS_Admin4.2

you might notice this error if you do not select the shared load balancer
Caution_Error


Step 4. Create Elastic Beanstalk Forum App

  1. Navigate to Elastic Beanstalk > Environments.
  2. Click Create a new environment.
  3. Select Web server environment
  4. Enter the following values:
    • Name: Forum
    • Platform: Node.js
    • Select Upload your code and upload nodejs_forum.zip
  5. Click Configure more options
    • Note: Step 6, 7 and 8 should be done in the same order.
  6. Select High availability under Presets.
  7. Click Edit next to Network and select same two Availability Zones for Load Balancer, Instance settings and Database settings.
  8. Click Edit next to Load Balancer
    • Load balancer type: Application Load Balancer
    • Type: Shared
    • Load balancer ARN: Select the ARN of SharedALB
    • Select default under Processes and click Actions > Edit > enter Path as /forum.html and click Save
    • Click Add Rule under Rules, Enter Name as admin, PathPattern as /*, Process as default and click Add
  9. Click Save.
  10. Click Create Environment.
  11. Wait for the environment to be create and then click on the application URL.

Note: If you need to make any changes to the code and create a zip on a Mac OS

cd /nodejs_forum
zip ../nodejs_forum -r * .[^.]*
Enter fullscreen mode Exit fullscreen mode

EBS Forum 4.3
EBS_Forum4.3


Step 5. Auto Scaling Verification

  1. Navigate to EC2 > Instances
  2. Select Admin-env instance
  3. Click Actions > Instance State and Terminate
  4. Wait for a few minutes, the auto scaling group will launch a new instance for Admin application, which can be checked under Auto Scaling Groups > Activity Note: There should only be one instance launched but not two.
  5. Similarly Terminate the Forum-env and there should new instance created in a few minutes.

EBS Environments
EBS-Envs

EBS Admin Application
EBS-Admin

EBS Admin Application
EBS-Forum

Application Load Balancer Listener Rules
ALB-Listener-Rules

EC2 Instances
EC2_Instances

EBS Admin Auto Scaling Activity
EBS-Admin-AS-1

EBS Forum Auto Scaling Activity
EBS-Admin-AS-2

EC2 Instances: Only one new Admin instance
EBS-Admin-AS-3

EC2 Instances: Forum Instance terminated manually and new instance created by Auto Scaling
EBS-Admin-AS-4

EBS Forum Auto Scaling Activity
EBS-Admin-AS-5


Clean Up

  1. Select each environment under Elastic Beanstalk > Environments, Select Actions > Terminate Environment.
  2. Select each application under Elastic Beanstalk > Applications, Select Actions > Delete Application.
  3. Delete SharedALB under Load Balancers
  4. Delete Security Group EBSSG.
  5. After both environments are terminated, Empty and Delete S3 bucket prefixed with elasticbeanstalk-us-east-1-...

Summary

  • We learned how to deploy and configure different settings using Elastic Beanstalk.
  • We also learned about shared application load balancer, which can save costs.

Referrals

Latest comments (0)