
Deploy a Web Application on AWS EC2 Using VPC and User Data
Learn how to create an AWS VPC, configure public subnets, security groups, and deploy a web application on Amazon EC2 using user data.
Series: Skill Builder Digital Classroom - AWS Cloud Technical Essentials (11 articles)
- …
- 5Deploy a Web Application on AWS EC2 Using VPC and User Data This article
How to Create an AWS VPC and Deploy a Web Application on EC2: Step-by-Step Hands-On Lab
Your EC2 instance can be running perfectly and your website can still be completely inaccessible.
Why?
Because launching a server is only half the job.
The other half is networking.
A web application needs more than compute power. It needs a network, a path to the internet, the right firewall rules, and a way to configure itself when the server starts.
Miss one piece, and the application may remain invisible to every browser trying to reach it.
That's exactly what we're going to solve in this hands-on AWS lab.
We'll build a custom Amazon VPC, configure two public subnets across different Availability Zones, create internet connectivity, secure inbound traffic, and deploy an Employee Directory web application on an Amazon EC2 instance.
And here's the interesting part:
We'll deploy the application automatically, without manually connecting to the server.
Let's build it.
What You'll Learn in This AWS Networking Lab
By the end of this tutorial, you'll understand how to:
- Create an Amazon VPC with two public subnets.
- Configure an Internet Gateway and a public route table.
- Distribute subnets across two Availability Zones.
- Create a custom security group allowing HTTP traffic.
- Launch an Amazon Linux 2023 EC2 instance.
- Automate application deployment using EC2 user data.
- Verify that your web application is accessible through a public IPv4 address.
AWS Region: Asia Pacific (Sydney)
ap-southeast-2 Important: Use the same AWS Region throughout the lab.
Understanding the Architecture Before We Begin
Think of a cloud application as a building.
Amazon VPC is your private property boundary.
Subnets divide that property into smaller sections.
An Internet Gateway provides a connection to the outside world.
A route table tells traffic where to go.
A security group decides which traffic is allowed through.
And Amazon EC2 provides the computing resources that run your application.
Each component has a different responsibility.
Together, they make a publicly accessible application possible.
In this lab, we're creating a VPC with two public subnets in separate Availability Zones. Our web application will run on an EC2 instance in the first public subnet.
The second subnet demonstrates how a network can span multiple Availability Zones, although we're deploying only one EC2 instance.
Key lesson: Building across two Availability Zones does not automatically make a single-instance application highly available.
That requires additional compute resources and appropriate traffic distribution.
Now, let's create the network.
Task 1: Create an Amazon Virtual Private Cloud (VPC)
Amazon Virtual Private Cloud lets you define a logically isolated virtual network within AWS.
You control its IP address range, subnets, routing, and connectivity.
Instead of launching infrastructure into an unspecified network environment, you design the network your application will use.
For this lab, we need four networking components:
- A VPC.
- Two public subnets in separate Availability Zones.
- An Internet Gateway.
- A route table with a public route to the internet.
The AWS VPC and more creation workflow allows us to create these resources together.
Task 1.1: Create the VPC, Public Subnets, Route Table, and Internet Gateway
Step 1: Open the Amazon VPC Console
Sign in to the AWS Management Console.
In the search bar at the top, search for VPC and open the VPC service.
Choose Create VPC.
Under Resources to create, select:
VPC and more This option allows AWS to create the VPC and its associated networking resources in one workflow.

caption: Creating a custom AWS network using the VPC and more workflow.
Step 2: Configure the VPC Settings
Under Name tag auto-generation, enable Auto-generate.
Enter:
lab-2 This naming prefix helps identify the resources created by the workflow.
Next, configure:
Setting | Value |
|---|---|
Name tag auto-generation | lab-2 |
IPv4 CIDR block | 10.0.0.0/16 |
IPv6 CIDR block | No IPv6 CIDR block |
Tenancy | Default |
The IPv4 CIDR block is particularly important.
10.0.0.0/16 defines the private IPv4 address range for our VPC.The
/16 prefix represents a range containing 65,536 IPv4 addresses, including addresses AWS reserves when allocated to subnets.We will divide part of this larger address space into smaller subnet ranges.
Cloud networking principle: Plan your IP ranges before deploying infrastructure. Overlapping address ranges can make future network connectivity more complicated.

Step 3: Configure Availability Zones and Subnets
In the VPC creation workflow, enter these values:
Setting | Value |
|---|---|
Number of Availability Zones | 2 |
Number of public subnets | 2 |
Number of private subnets | 0 |

Why two Availability Zones?
Because an Availability Zone represents an isolated location within an AWS Region.
Distributing resources across different Availability Zones creates the foundation for designing resilient architectures.
Each subnet belongs to one Availability Zone.
A subnet cannot span multiple Availability Zones.
For this lab, both subnets will be public because our network is being configured to support internet connectivity.
Step 4: Customize the Subnet CIDR Blocks
Expand Customize subnets CIDR blocks.
Configure the two public subnet ranges:
Public subnet | IPv4 CIDR |
|---|---|
Public subnet 1 | 10.0.0.0/24 |
Public subnet 2 | 10.0.1.0/24 |
The first subnet uses:
10.0.0.0/24 The second subnet uses:
10.0.1.0/24 Each
/24 range contains 256 total IPv4 addresses. AWS reserves five addresses in each subnet, leaving 251 usable addresses.Both subnet ranges belong to the larger
10.0.0.0/16 VPC network.

Configuring two public subnets across different AWS Availability Zones.
Step 5: Configure NAT Gateways, Endpoints, and DNS
Continue through the VPC settings.
For NAT gateways, select:
None For VPC endpoints, select:
None Under DNS options, enable both:
- Enable DNS hostnames
- Enable DNS resolution
Here's why these settings matter.
DNS hostnames allow eligible EC2 instances with public IPv4 addresses to receive public DNS hostnames.
DNS resolution allows resources within the VPC to use AWS-provided DNS resolution.
We're not creating NAT gateways because this lab doesn't include private subnets that need outbound internet connectivity through NAT.
We're also not configuring VPC endpoints.
The network is intentionally simple.
The goal is to understand the essential networking components before adding more complexity.

Step 6: Review the VPC Preview
On the right side of the page, locate the Preview section.
Before proceeding, confirm that AWS will create:
- The VPC named
lab-2-vpc.
- Two public subnets.
- A public route table.
- An Internet Gateway.
The preview provides a valuable final checkpoint.
It helps you catch configuration mistakes before AWS creates the resources.

caption: Reviewing the network resources before creating the Amazon VPC.
Once the configuration is correct, choose Create VPC.
Step 7: Verify the VPC Creation Workflow
AWS now creates the networking resources.
Wait until the workflow finishes successfully.
The workflow should show that AWS has:
- Created the VPC.
- Created both public subnets.
- Created an Internet Gateway.
- Attached the Internet Gateway to the VPC.
- Created the required route table.
- Associated the public subnets with the route table.

caption: AWS successfully creates the VPC, public subnets, Internet Gateway, and route table associations.
One important detail deserves attention.
An Internet Gateway alone does not make an application publicly accessible.
The subnet's route table must also provide a route to the gateway, and the instance must have an appropriate public address and security configuration.
These components work together.
Choose View VPC.

Your custom VPC and its networking components are now ready.
Task 1 completed: We've created the underlying AWS network architecture.
But we haven't given incoming web requests permission to reach our future EC2 instance.
That's our next step.
Task 2: Create a VPC Security Group
A public route provides connectivity. A security group controls access.
These are two different responsibilities.
An Amazon EC2 security group acts as a virtual firewall.
It controls the inbound and outbound traffic allowed for the resources associated with it.
For example, an EC2 instance may have a public IP address and a valid route to the internet.
But if its security group doesn't allow incoming HTTP requests, a browser still won't be able to reach the application on port 80.
In this task, we'll create a security group that allows inbound HTTP traffic.
Step 1: Open the Security Groups Console
Within the VPC console, locate the Security section in the left navigation pane.
Choose Security groups.
Then select Create security group.

Step 2: Configure the Basic Details
Enter the following values:
Field | Value |
|---|---|
Security group name | Web Security Group |
Description | Enable HTTP access from anywhere |
VPC | lab-2-vpc |
Make sure you select the VPC created in Task 1.
If the default VPC is preselected, remove it and choose:
lab-2-vpc Security groups are associated with a specific VPC, so selecting the correct network matters.


caption: Creating a custom security group for the web application.
Step 3: Add an Inbound HTTP Rule
In the Inbound rules section, choose Add rule.
Configure:
Setting | Value |
|---|---|
Type | HTTP |
Source | Anywhere-IPv4 |
Description | Allow web requests from anywhere |
Selecting HTTP configures TCP port 80.
Choosing Anywhere-IPv4 allows incoming requests from:
0.0.0.0/0 This means IPv4 clients from any source address can attempt to connect to the instance on the permitted port.
For a public demonstration website, this allows us to test the application using a browser.
However, there's an important security distinction.
Publicly reachable is not the same as securely designed.
In production environments, you should use HTTPS, apply the principle of least privilege, and restrict administrative access.
For this lab, we're following the provided HTTP configuration.

caption: Allowing inbound HTTP traffic on port 80 through the EC2 security group.
Step 4: Add the Security Group Tag
Under Tags - optional, choose Add new tag.
Enter:
Field | Value |
|---|---|
Key | Name |
Value | WebAppSG |
Tags help organize and identify resources.
They're especially useful when an AWS environment contains multiple applications, networks, and security groups.
Choose Create security group.

Your security group is ready.
Task 2 completed: We've created a custom firewall configuration that permits incoming HTTP web requests.
Now we have the network.
We have the internet connection.
We have the firewall rule.
It's time to launch the server and deploy the application.

Task 3: Launch an Amazon EC2 Instance and Deploy the Web Application
Amazon Elastic Compute Cloud (EC2) provides virtual servers in the AWS Cloud.
You choose the operating system, instance type, networking configuration, storage, and security settings.
But launching a server doesn't automatically make it useful.
The operating system still needs the application runtime, dependencies, application files, and startup commands.
This lab uses EC2 user data to automate those tasks.
Instead of manually signing in to the instance and typing commands, we'll provide a bootstrap script that runs during the instance's initial launch.
Step 1: Open the Amazon EC2 Console
From the AWS Management Console search bar, search for:
EC2 Open the EC2 service.
In the navigation pane, under Instances, choose Instances.
Then select Launch instances.

Step 2: Configure the EC2 Instance Name
Under Name and tags, enter:
Web Application This name will help identify the instance in the EC2 console.

Step 3: Select the Amazon Machine Image (AMI)
An Amazon Machine Image is a template used to launch an EC2 instance.
It contains the operating system and associated software configuration needed to start the virtual server.
In Application and OS Images, locate the Quick start section.
Select:
Amazon Linux 2023 kernel-6.1 AMI Under Architecture, choose:
64-bit (x86) Amazon Linux 2023 is the operating system used throughout this lab.

caption: Selecting Amazon Linux 2023 as the operating system for the EC2 web server.
Step 4: Select the EC2 Instance Type
Under Instance type, choose:
t3.micro An instance type determines the virtual server's compute and memory configuration.
The
t3.micro instance is sufficient for the lightweight application used in this lab.In a real environment, instance sizing should reflect workload requirements, traffic expectations, and performance testing.
Step 5: Configure the Key Pair
Under Key pair (login), select:
Proceed without a key pair (Not recommended) Why would we launch an instance without a key pair?
Because this specific lab does not require interactive SSH access.
We'll configure the application automatically using user data.
Normally, administrators should plan a secure method for managing EC2 instances, such as AWS Systems Manager Session Manager.
Automation can reduce the need for manual server access, but it does not eliminate the need for a secure management strategy.
Step 6: Configure the EC2 Network Settings
Expand Network settings by choosing Edit.
Select the VPC:
lab-2-vpc For the subnet, select:
lab-2-subnet-public-1-[az-a] Here,
[az-a] represents the first Availability Zone in your selected AWS Region.Under Auto-assign public IP, choose:
Enable This setting is essential for our browser test.
It assigns a public IPv4 address to the EC2 instance.
Remember the connectivity requirements:
The instance needs a public IP address, the appropriate subnet routing, and a security group that permits inbound HTTP requests.
Without all three, simply having a running instance won't guarantee public accessibility.

Connecting the EC2 instance to the custom public subnet and enabling its public IPv4 address.
Step 7: Attach the Existing Security Group
In the Firewall (security groups) section, select:
Select an existing security group Under Common security groups, choose:
Web Security Group This is the security group created in Task 2.

It allows incoming HTTP requests on port 80.
We are not creating a new security group here.
We're reusing the one already configured for the application.
Step 8: Keep the Default Storage Configuration
In the Configure storage section, leave the default values unchanged.
The default storage configuration is sufficient for this lab.
Next comes the most interesting part of the deployment.

Step 9: Automate Web Application Deployment with EC2 User Data
A server that configures itself is more useful than a server that waits for manual instructions.
EC2 user data allows you to provide initialization scripts when launching an instance.
On Amazon Linux, a shell script can install software, download files, configure dependencies, and start an application.
In this lab, our application uses Node.js.
We'll use a user data script to install the required runtime and deploy the application automatically.
Open Advanced details.
Locate the User data - optional text box.
Paste the following script.
EC2 User Data Script
The original lab's pasted script had several lines joined together. The line breaks below have been restored while preserving its command sequence.
#!/bin/bash -ex
# Update yumyum -y update
# Install nvm (Node Version Manager)curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
# Download and install Node.jsnvm install 20
# Create a dedicated directory for the applicationmkdir -p /var/app
# Get the app from S3wget https://aws-tc-largeobjects.s3-us-west-2.amazonaws.com/ILT-TF-100-TECESS-5/app/app.zip
# Extract it to the desired folderunzip app.zip -d /var/app/
cd /var/app/
# Install dependenciesnpm install
# Start the appnpm start

Automating Node.js installation and application deployment using Amazon EC2 user data.
What Does This Script Actually Do?
Understanding the script matters more than simply copying it.
Let's break down its execution.
1. Update system packages
yum -y update The script updates installed system packages.
This helps prepare the operating system before additional software is installed.
2. Install Node Version Manager
The script downloads and runs the NVM installer.
NVM provides a convenient way to manage Node.js versions.
3. Configure the NVM environment
The script sets
NVM_DIR and loads the relevant NVM shell configuration.This makes the NVM command available to subsequent steps.
4. Install Node.js 20
nvm install 20 This installs Node.js version 20 through NVM.
The application needs Node.js to execute its JavaScript code.
5. Create an application directory
mkdir -p /var/app This creates a dedicated directory for the application.
6. Download the application files
The
wget command downloads an application archive from the S3-hosted URL provided in the lab.The archive contains the files required for the Employee Directory application.
7. Extract the application
unzip app.zip -d /var/app/ The script extracts the downloaded archive into the application directory.
Then it changes into that directory.
8. Install the application dependencies
npm install NPM installs the application dependencies declared by the project.
9. Start the application
npm start This runs the application's configured start command.
The lab application is expected to listen for HTTP requests on port 80.
The listener configuration comes from the application itself; it is not explicitly set by a separate command in the provided script.
Why User Data Matters in Cloud Operations
Imagine launching 20 servers.
Would you rather configure each one manually?
Or define the initialization process once and let the servers execute it automatically?
That is the operational value of bootstrap automation.
It makes server initialization more repeatable and reduces manual configuration steps.
However, this script is appropriate as a learning example, not a complete production deployment strategy.
A production application would typically need stronger lifecycle management, monitored services, secure dependency handling, and a process that automatically restarts the application after failures or reboots.
The user data script demonstrates the foundation: automated initialization.
Step 10: Launch the EC2 Instance
Scroll to the Summary section.
Under Number of instances, enter:
1 Review the selected configuration.
Configuration | Selected value |
|---|---|
Instance name | Web Application |
AMI | Amazon Linux 2023 kernel-6.1 |
Architecture | 64-bit (x86) |
Instance type | t3.micro |
Key pair | Proceed without a key pair |
VPC | lab-2-vpc |
Subnet | First public subnet |
Public IPv4 | Enabled |
Security group | Web Security Group |
Storage | Default |
User data | Node.js application bootstrap script |
Number of instances | 1 |
Choose Launch instance.
AWS begins provisioning the virtual server.
You should see a confirmation similar to:
Successfully initiated launch of instance (instance-id)

caption: Successfully initiating the launch of the web application EC2 instance.
Choose View all instances.
Step 11: Verify the EC2 Instance Status
The newly launched instance may initially appear as:
Pending Or it may still be initializing.
Refresh the Instances page if necessary.
Wait until the instance displays:
Instance state: Running
Status check: 3/3 checks passed
These are the expected health indicators in the provided lab.

Verifying that the EC2 instance is running and has passed its status checks.
An important distinction:
A healthy EC2 instance does not automatically mean the web application is healthy.
Instance status checks help validate the underlying compute environment.
The application must still be tested separately.
That is why our final step is not checking the instance state.
It's opening the application in a browser.
Step 12: Access the Web Application Through Its Public IP
Select the running Web Application instance.
In the Details tab, find:
Public IPv4 address Copy the address.
Open a new browser tab and enter:
http://YOUR-PUBLIC-IP Replace
YOUR-PUBLIC-IP with the instance's actual public IPv4 address.For example, the address format should resemble:
http://203.0.113.10 The example IP above is illustrative; use the public address assigned to your own instance.
Important: Use
http:// , not https:// .This lab application is configured for HTTP on port 80.
It does not include HTTPS or a TLS certificate.
If deployment succeeds, the browser should display the Employee Directory web application.
The expected page contains a navigation area and the main employee directory interface.

Successfully accessing the Employee Directory web application hosted on Amazon EC2.
This is the moment when all the networking components come together.
The browser sends a request.
Internet connectivity and routing provide the network path.
The security group permits HTTP traffic.
The EC2 instance receives the request.
The Node.js application responds.
And the user sees the web page.
That's what infrastructure is supposed to do: turn correctly connected components into a working service.
Step 13: Review the Completed AWS Architecture
Now that the application is working, review the complete architecture.

Network layer: VPC, subnets, route table, and Internet Gateway.
Security layer: Security group.
Compute and application layer: EC2 instance, Node.js runtime, and Employee Directory application.
This separation is essential when troubleshooting AWS deployments.
If an application is inaccessible, you need to determine whether the failure occurs in networking, security, operating system configuration, or the application itself.
Once you've successfully accessed the application, close the browser tab.
Task 3 completed: We've launched an EC2 instance and deployed a web application using an automated user data script.
What This AWS Lab Actually Teaches You
It's tempting to think the goal of this lab was simply to launch a website.
But the larger lesson is about how AWS infrastructure components depend on each other.
Here are the most valuable takeaways.
1. A VPC Is the Foundation of Your Cloud Network
Before launching workloads, you need to understand where those workloads will run.
A VPC provides the network boundary and address space.
Subnets define smaller networks within that boundary.
The way you design these networks affects future connectivity, isolation, and scalability.
2. Public Connectivity Requires Multiple Components
An Internet Gateway provides a route between a VPC and the internet.
But public access also depends on route tables, public IP addressing, and security rules.
No single component provides the complete solution.
3. Security Groups Should Be Designed Intentionally
Security groups determine which traffic can reach an instance.
For this lab, TCP port 80 is open to all IPv4 addresses.
For a production deployment, evaluate exposure carefully, use HTTPS, and allow only the traffic required by the application.
4. Automation Reduces Manual Configuration
EC2 user data allows you to automate initial server configuration.
Instead of manually installing Node.js and downloading the application, the bootstrap script performs those tasks.
This is a starting point for more advanced automation using tools such as AWS CloudFormation, Terraform, and configuration management systems.
5. Infrastructure Health and Application Health Are Different
An EC2 instance can pass its status checks while the application remains inaccessible.
Always validate the service from the perspective of the user.
In this lab, that means opening the public IP address in a web browser and confirming that the Employee Directory application loads.
Conclusion: From an Empty VPC to a Working Web Application
We started with a simple goal:
Deploy a web application on Amazon EC2.
But to make that application accessible, we had to build the infrastructure supporting it.
We successfully:
- Created a custom Amazon VPC.
- Configured two public subnets across separate Availability Zones.
- Created and attached an Internet Gateway.
- Established public routing through a route table.
- Created a security group allowing inbound HTTP traffic.
- Launched an Amazon Linux 2023 EC2 instance.
- Used EC2 user data to install Node.js and deploy the application.
- Verified application accessibility using the instance's public IPv4 address.
The biggest takeaway?
Cloud infrastructure isn't a collection of independent services. It's a system of dependencies.
An instance needs a network.
A public application needs connectivity.
Connectivity needs the correct routes.
Access needs security rules.
And a working server still needs a working application.
Understanding those connections is what turns basic AWS knowledge into practical Cloud Operations skills.
End Lab: Sign Out and Clean Up
After completing the browser test and reviewing your architecture, follow the lab's original closing sequence.
- Return to the AWS Management Console.
- In the upper-right corner, choose AWSLabsUser.
- Select Sign out.
- Choose End Lab and confirm.
This ends the guided lab environment.
If you reproduce the architecture in a personal AWS account rather than a managed lab environment, review and delete unneeded resources to avoid ongoing charges.
Additional AWS Learning Resources
For further learning, explore the official AWS documentation:
- Amazon Virtual Private Cloud: https://docs.aws.amazon.com/vpc/
- Amazon Elastic Compute Cloud: https://docs.aws.amazon.com/ec2/
Final thought: A running server is not the finish line. A reachable, correctly configured, and secure application is the real objective.
Open to Cloud Ops Remote and technical writing projects.
Series: Skill Builder Digital Classroom - AWS Cloud Technical Essentials (11 articles)
- …
- 5Deploy a Web Application on AWS EC2 Using VPC and User Data This article
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article