credit: AWS Blog image

Implementation of a Scalable Web Application using AWS Elastic Beanstalk, DynamoDB and CloudFront

Bolaji A. Adetoye
6 min readJun 30, 2023

Project description:

In this project, based on a real-world scenario, I implemented 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.

This event was broadcast online and in person and some vouchers were drawn for 3 Cloud certifications. At that moment, more than 10,000 people in the audience registered their emails to guarantee their participation in the raffle.

AWS Elastic Beanstalk service was used to deploy the web application, DynamoDB to store emails of the participants in a table and Amazon CloudFront to cache static and dynamic files in an Edge Location close to the users.

Solution Architecture

Step 1: Create a Table to hold partcipant email addresses in DynamoDB

DynamoDB > Tables > Create table

Step 2: Create the Application environment in Elastic beanstalk

Environment tier | Web server environment | Application information and specify a name for the application.

Platform | Platform type — Managed platform. Choose a platform for the application. Python was selected. Platform branch | Python 3.7 |Platform version 3.5.3 (recommended). Application code | Upload your code (upload the source bundle for Amazon S3). Specify a suitable version label for the application. Put the Public S3 URL and select “high availability” for confiuration presets. Click “Next”. Configure service access | service role > Create and use new service role. Select EC2 Key Pair if this was created ealier or open another browser tab to create an EC2 key pair. Click the Refresh button and select the key pair. To create the EC2 instance profile, open a new browser tab and create one — IAM | Roles | Create Role | Trusted entity type: AWS service | common use cases — EC2 and click “Next “ .

Filter the permission policies with “Elasticbeanstalk” and add these 3 permission to the role.

Select the permissions and click “Next”. Enter a name to identify this role and click “create role” button. Refresh the EC2 instance profile textbox and select the newly created profile. Click “Next”

Step 3: Setup Networking and instance settings

Select the default VPC, ensure that the Public IP address is set to “activated” and selcet one instance subnet and leave the database part as is. Click “Next”.

Step 4: Configure instance traffic and scaling

Instances

Root volume type: General Purpose (SSD)
Size: 10 GB

Capacity

Auto scaling group
Load balanced
Min: 2
Max: 4
Fleet composition: select On-Demand instances
Instance types: t2.micro

Scaling triggers

Metric: CPUUtilization
Unit: Percent
Min: 1
Min: 1
Upper: 50
Scale up: 1
Lower: 40
Scale down: -1

Load balancer network settings

Visibility: Public
Load balancer subnets
[ ✔ ] check all

Note: Ensure that all subnets are selected for instance settings in the previous step (step 3) and continue

Step 5: Configure updates, monitoring, and logging

Scroll all the way down to “Environment properties” section and add “AWS_REGION” with “us-east-1” as its value.

Click “Next” to the continue to the review page and click “submit”. Elastic beanstalk will launch the environment but this may take a few minutes before it is completed.

Validate the Resources Created

To confirm the application deployed, copy the domain address to the browser.

Before testing with any email address, we need to add the required permission to elasticbeanstalk-ec2 IAM role earlier created otherwise this would flag an “internal server error” message.

IAM | Roles > aws-elasticbeanstalk-ec2-role
Add permissions | Attach policies > AmazonDynamoDBFullAccess

Now, let’s test with sample email addresses and check the DynamoDB table to view the registered email addresses for the participants.

Step 6: Creating the CloudFront | CDN — Content Delivery Network

Amazon CloudFront is a Web service used to distribute content to end users with low latency and high data transfer speeds.

Search for CloudFront from the services under Networking & Content Delivery | CloudFront >

Origin domain: select the ‘Elastic Load Balancer’ created by Elastic Beanstalk
Protocol: HTTP only

Allowed HTTP methods: GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE

Cache key and origin requests
Select — Cache policy and origin request policy (recommended)
Cache policy: CachingOptimized

Web Application Firewall (WAF)
Select — Enable security protections

Click “Create Distribution” button and wait for the exercise to complete.

— Testing CloudFront

Copy the generated “Distribution domain name” to the browser to verify, register any email address and validate the entry at DynamoDB table.

— Stress testing the App:

This test is done to see the autoscaling functionality of the ASG in the Elastic Beanstalk in action when the resources encounter intense load or traffic to a breaking point. I will install the “stress” test tools in an instance and see how this is impacted. A new instance is added to the environment when an EC2 instance’s CPU is overwhelmed as specified in the “scaling triggers” section of the Auto scaling group.

Let’s connect to one of the instances using a secure shell (SSH) and install the stress tools. Run the following commands in any chosen EC2 instance of your deployment.

sudo amazon-linux-extras install epel -y
sudo yum install stress -y

Perform the stress test by executing the “stress” command

stress -c 4

Let’s open a new SSH connection and check the process running in the EC2 instance. Note the CPU consumption or ulilization in percentage.

ps aux
ps aux - sort=-pcpu
top
CPU Utilization

Let’s check the resources.

Event tab after stress test
Elastic Beanstalk Health Warning
New EC2 instance added
Event tab after a new instance was added
Environment Health restored
One EC2 instance was automatically terminated by the ASG when the load/traffic subsided

Summary

In this project, I showed how to implement a web application to register partcipants email addresses at a conference using Amazon DynamoDB to keep records of email addresses, Elestic Beanstalk to deploy a scalable application and CloudFront to cache and distribute content to end users. So also, I showed the Auto scaling functionality of the Auto scaling group to scale up when exposed to intense traffic to break point and scale down when the traffic subsided.

I hope this is informative and I will see you in the next one. Cheers!

--

--

Bolaji A. Adetoye

IT Tech. Support | Aspiring MultiCloud & DevOps Engineer | AWS | Microsoft Azure | Google Cloud | Oracle Cloud