Table of Contents
- Introduction
- Create a Security Group
- Create an Application Load Balancer
- Create Elastic Beanstalk Admin App
- Create Elastic Beanstalk Forum App
- Auto Scaling Verification
- Clean Up
- Summary
- 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
We are going to create a Security Group for Elastic Beanstalk
-
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 from0.0.0.0/0
(IPV4) and::/0
(IPV6)
- Name:
Step 2. Create an Application Load Balancer
- Navigate to EC2 > Load Balancers.
- Click Create Load Balancer.
- 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
andus-east-1b
AZs.
- Name:
- Click Next: Configure Security Settings.
- Note: Ignore the warning as we are not using HTTPS.
- Select
EBSALB
and Click Next - Configure Routing, enter the following values and then Click Next:
- Name:
EBS-TG
- Target type:
Instance
- Protocol:
HTTP
- Port:
80
- Path:
/index.html
- Name:
- Click Next: Register Targets.
- Click Next: Review.
- Click Create
-
Wait until the Application Load Balancer
SharedALB
is Active.Shared Application Load Balancer
Step 3. Create Elastic Beanstalk Admin App
- Navigate to Elastic Beanstalk > Environments.
- Click
Create a new environment
. - Select
Web server environment
- Enter the following values:
- Name:
Admin
- Platform:
Node.js
- Select
Upload your code
and upload nodejs_admin.zip
- Name:
- Click
Configure more options
- Note: Step 6, 7 and 8 should be done in the same order.
- Select
High availability
underPresets
. - Click
Edit
next toNetwork
and select same twoAvailability Zones
forLoad Balancer
,Instance settings
andDatabase settings
. - Click
Edit
next toLoad Balancer
- Load balancer type:
Application Load Balancer
- Type:
Shared
- Load balancer ARN: Select the ARN of
SharedALB
- Select
default
under Processes and clickActions
>Edit
> enter Path as/admin.html
and clickSave
- Click
Add Rule
underRules
, EnterName
asadmin
,PathPattern
as/*
,Process
asdefault
and clickAdd
- Load balancer type:
- Click
Save
. - Click
Create Environment
. - 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 * .[^.]*
you might notice this error if you do not select the shared load balancer
Step 4. Create Elastic Beanstalk Forum App
- Navigate to Elastic Beanstalk > Environments.
- Click
Create a new environment
. - Select
Web server environment
- Enter the following values:
- Name:
Forum
- Platform:
Node.js
- Select
Upload your code
and upload nodejs_forum.zip
- Name:
- Click
Configure more options
- Note: Step 6, 7 and 8 should be done in the same order.
- Select
High availability
underPresets
. - Click
Edit
next toNetwork
and select same twoAvailability Zones
forLoad Balancer
,Instance settings
andDatabase settings
. - Click
Edit
next toLoad Balancer
- Load balancer type:
Application Load Balancer
- Type:
Shared
- Load balancer ARN: Select the ARN of
SharedALB
- Select
default
under Processes and clickActions
>Edit
> enter Path as/forum.html
and clickSave
- Click
Add Rule
underRules
, EnterName
asadmin
,PathPattern
as/*
,Process
asdefault
and clickAdd
- Load balancer type:
- Click
Save
. - Click
Create Environment
. - 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 * .[^.]*
Step 5. Auto Scaling Verification
- Navigate to
EC2
>Instances
- Select
Admin-env instance
- Click
Actions
>Instance State
andTerminate
- 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. - Similarly
Terminate
theForum-env
and there should new instance created in a few minutes.
Application Load Balancer Listener Rules
EBS Admin Auto Scaling Activity
EBS Forum Auto Scaling Activity
EC2 Instances: Only one new Admin instance
EC2 Instances: Forum Instance terminated manually and new instance created by Auto Scaling
EBS Forum Auto Scaling Activity
Clean Up
- Select each environment under
Elastic Beanstalk
>Environments
, SelectActions
>Terminate Environment
. - Select each application under
Elastic Beanstalk
>Applications
, SelectActions
>Delete Application
. - Delete
SharedALB
underLoad Balancers
- Delete Security Group
EBSSG
. - 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
- Configuring a shared Application Load Balancer using the Elastic Beanstalk console
- The application code is from Tutorials and samples and I have added admin.html and forum.html.
Top comments (0)