Implementation of a Scalable Web Application using the services of AWS Elastic Beanstalk, DynamoDB, CloudFront and Edge Location

Atul Saxena
11 min readMay 20, 2023

--

This project was based on a real-world scenario, my responsible was to implementing an application that needs to support the high demand of a large number of users accessing it simultaneously. This application has been used in a large conference that had more than 10,000 people, in-person and online, with participants from all over the world.

The event was both streamed online and conducted in-person, with 10 vouchers being drawn for three Cloud certifications. Over 10,000 audience members registered their emails to secure their chance in the raffle.

Cloud and Services & Technologies used in this implementation

The web application was deployed using AWS Elastic Beanstalk services, stored emails in DynamoDB, and cached static and dynamic files in CloudFront’s Edge Locations near the users.

The Cloud Bootcamp Conference
Auto scaling group will be responsible to create EC2 instances depending upon capacity and CPU usage.

I have divided implementation into three parts as stated below:

I have created a table in DynamoDB to store users email addresses. I have also created an Elastic Beanstalk application. During the application provisioning, the Elastic Beanstalk provisioned EC2 instances, Elastic Load Balancer and Auto Scaling group.

Created CloudFront Distribution

Performed load testing on the deployed application in the cloud

HANDS-ON PROJECT SOLUTION PART 1

STEP # 1 : I have created table in DynamoDB in order to store user’s email addresses

Click Create table
  • Create a new table
    ▪︎ name: users
    ▪︎ partition key: email

Table View

STEP # 2: Deploying application using Elastic Beanstalk.
Let us search Elastic Beanstalk

During the application provisioning the Elastic Beanstalk will go ahead and provision EC2 instances, Elastic Load Balancers and autoscaling group for us. In short, Elastic Beanstalk provisioned the entire infrastructure and deployed the Application — The Cloud Bootcamp Conference Voucher Raffle, in a single step.

Click Create application

Configure Environment

a. Environment tier
Web server environment
b. Application information
Application Name: tcb-conference
c. Application tags (optional)

💡 How tags help in organizing your application Tags in Elastic Beanstalk help in organizing and categorizing applications based on their characteristics, such as environment, project, or owner. This makes it easier to manage and search for applications in a large environment.

For example, suppose you have multiple applications running on Elastic Beanstalk. You could add tags to identify which applications belong to a particular project, such as “Project A” or “Project B.” Then, when you want to manage or search for applications related to a specific project, you can filter by the corresponding tag.

To add tags to an Elastic Beanstalk application, you can go to the “Tags” section of the “Create a new application” or “Edit application” page, and enter a key-value pair for each tag.

d. Environment Information
Environment name: Tcb-conference-env

Platform info

a. Platform type
Managed platform
b. Platform Version
Python 3.7 running on 64bit Amazon Linux 2

Application code

a. code
Upload your code
b. version
tbc-conference-source
c Public S3 URL
https://tcb-bootcamps.s3.amazonaws.com/bootcamp-aws/en/tcb-conf-app-EN.zip

Presets info

We need to select High availability as per business requirement and click Next button.

Configure service access

a. Service role
Create and use new service role
b. Name
aws-elasticbeanstalk-service-role
c. EC2 key pair
ssh-key
d. EC2 Instance profile
aws-elasticbeanstalk-ec2-role

STEP # 3: Setup networking, database, and tags
We will create CloudFront distribution that give us a route 53 DNS entries that can use to access our application now going through CloudFront

In this section, we have selected Virtual Private Cloud.

Select VPC

Instance Setting

a. Public IP Address
Activated
b. Instance subnets
us-east-1a

Click Next Button

STEP # 4: Configure instance traffic and scaling

Instance info

ROOT VOLUME (BOOT DEVICE)
a. Volume type
General Purpose SSD
b. Size
10 Gb
INSTANCE METADATA SERVICE (IMDS)
c. IMDSv1
with the current setting, the environment enables only IMDSv2.
✅ Deactivated

The General Purpose (SSD) volume type in AWS is suitable for a variety of workloads and provides a balance between performance and cost. When configuring instance traffic and scaling, choosing a General Purpose (SSD) volume with a size of 10 GB can have several advantages:

  1. Performance: General Purpose (SSD) volumes offer a good baseline performance level for most general-purpose workloads. They are designed to deliver low-latency performance and are capable of handling a moderate amount of I/O operations.
  2. Cost-efficiency: General Purpose (SSD) volumes are cost-effective compared to other types of storage options in AWS. They offer a balance between performance and cost, making them suitable for applications with moderate storage needs.
  3. Flexibility: A 10 GB volume size provides enough storage capacity for many small to medium-sized applications or instances. It allows you to store your application data, logs, configuration files, and other necessary files without requiring a larger volume that may incur unnecessary costs.
  4. Scalability: AWS allows you to easily scale your storage by increasing the volume size as your application’s needs grow. Starting with a 10 GB volume gives you the flexibility to scale up or down based on your application’s requirements without over provisioning initially.

However, it’s important to note that the specific volume size and type you choose should align with your application’s requirements and anticipated workload. If you have specific performance, throughput, or storage needs, you may need to consider other volume types or larger sizes to ensure optimal performance and cost-effectiveness.

Capacity info

Auto Scaling group
a. Environment type
Load balanced
b. Instances
Min : 2
Max: 4
c. Fleet composition
On-Demand instances
d. Architecture
x86_64
e. Instance type
t2.micro
Scaling triggers
a. Metric
CPUUtilization
b. Statistic
Average
c. Unit
Percent
d. Period
Min: 1
e. Breach duration
Min: 1
f. Upper threshold
50
g. Scale up increment
EC2 Instances: 1
h. Lower threshold
Capacity: 40
i. Scale down increment
EC2 Instances: -1

In summary, this Auto Scaling group uses load balancing and consists of a minimum of 2 and a maximum of 4 on-demand instances with an x86_64 architecture and t2.micro instance type. Scaling is triggered based on the average CPU utilization, with a period and breach duration of at least 1 minute. When the CPU utilization exceeds 50%, the group scales up by adding 1 EC2 instance. Conversely, when the capacity goes below 40%, the group scales down by removing 1 EC2 instance.

Load balancer networking settings

Load balancer network settings
a. Visibility
Public
b. Load balancer subnets
Availability Zone
✅ us-east-1d
✅ us-east-1f
✅ us-east-1e
✅ us-east-1b
✅ us-east-1a
✅ us-east-1c

Now, we have configured ‘t2.micro’ for the type of instances to be created. Go back to Step 3: Select all available zones in the region as shown below:

Go to STEP # 4 and Click [NEXT]

STEP # 5: Configure instance traffic and scaling

Add Environmental Variable AWS_REGION with value us-east-1

Click Next

STEP # 6: Review and Submit
Here is Elastic beanstalk

Elastic Beanstalk

Elastic Beanstalk has created following

a. Two EC2 instances

EC2 Instances

b. One Load balancer

Load balancer

c. Three Security Groups

First Security Group
Secondary Security Group
Third Security Group

d. Elastic Beanstalk Environment

Giving the permission AmazonDynamoDBFullAccess to the role
‘aws-eleasticbeanstalk-ec2-role’

Click Add Permission → Attach Policies

Search Amazon

Click Add permission

AmazonDynamoDBFullAccess has been added here.

If we do not add AmazonDynamoDBFullAccess Policies to this role, then we will get an error : user is not authorized to perform: dynamodb: PutItem on resource: ………

Let us launch our application

Here is our migrated application UI

I have registered two email address
1. ny.atul.saxena@gmail.com
2. jmdatul@gmail.com

DynamoDB

HANDS-ON PROJECT SOLUTION PART 2

Till this point, I have created dynamoDB and provision infrastructure using Elastic Beanstalk.

Amazon CloudFront is a content delivery network (CDN) that caches data at edge locations across the globe. When a user requests content, CloudFront serves it from the closest edge location, reducing the time it takes to load the content. By deploying CloudFront Distribution, the application’s static and dynamic files can be cached closer to the user, which can significantly improve the performance of the application.

Click a CloudFront as shown above and click create a CloudFront distribution

Amazon CloudFront
  1. Select Origin as shown below i.e. Elastic Load Balancer
    (The source of application that you want cloudFront to cache it for you. In our case it is Elastic Load balancer)

2. Allowed HTTP methods
→ We need Post method to insert the records in dynamoDB

3. Price class

On click Create distribution

Select Cache key as shown below

Enable Firewall security protection and click Create distribution button and see the following entry

Copy Domain name and paste it in your favorite browser.

I received the following Error

How to fix this error? Here is solution
Go to Distribution
→ Edit Origin → Settings
→ Change Origin domain from HTTPS Only to Match viewer
→ Save changes

Copy domain and paste in the new browser
Here is our Application in our browser
Now, it shows successful registration and eMail address.

Go into DynamoDB and you can view

HANDS-ON PROJECT SOLUTION PART 3

In this part we would perform some load testing

  • Install the stress tools to perform the load test
  • Explore resources created by the AWS Elastic Beanstalk and also the auto scaling process
  • Once it is complete, removing the elastic Beanstalk application & environment, disable & delete the cloudFront distribution, and finally delete the DynamoDB

This is the last leg of this Elastic Beanstalk project, we are going to do some loading tasks our architecture can scale up or scale down if needed. For example if CPU utilization in one of EC2 instances goes higher than 50% then autoscaling process must add one more instances to the deployment automatically.
Go to Auto Scaling groups and click any of the two instances and copy public IP Address. Open mac terminal, connect to EC2 instance as shown below:

In order to perform, we need to install couple of stress tools. Once installed all tools.

We need to run the stress command on our terminal as shown below

Next, go to AWS → Elastic Beanstalk and you would see the following screen

Warning in red

Click on ‘Tcb-conference-env’, you would see

Warning: 1 out of two instances are impacted
It has created one more instance

When I run top command, it provides me CPU Utilization is 100%

If you review EC2 instances, one more instance was added as shown below

Auto Scaling group one instance has been added

Registering user under stress, when 3 EC2 instances are running

Registered successfully

It shows that it is working under more CPU stress.

--

--

Atul Saxena
Atul Saxena

Written by Atul Saxena

The latest technologies with the truth | Formerly worked at Fortune 500 companies

No responses yet