How to Deploy a Dynamic Web Application on AWS (Beginner-Friendly Guide)
Source: Dev.to
Deploying a dynamic web application on AWS can feel overwhelming at first, especially with so many services involved. This guide walks through a simple, practical approach that’s perfect for beginners learning cloud computing and DevOps.
What is a Dynamic Web Application?
Unlike static websites, dynamic web applications:
- Process user input
- Connect to databases
- Generate content in real time
Common examples include login systems, dashboards, e‑commerce sites, and web apps built with PHP.
AWS Services We’ll Use
The deployment relies on core AWS services such as EC2, VPC, Security Groups, S3, IAM, RDS, Application Load Balancer (ALB), Auto Scaling, and related networking components.
Step‑By‑Step Deployment
1. Choose a Region
Select the AWS region where you want to host your application.
2. Create a VPC
Enable DNS hostnames for the VPC.
3. Set Up Security Groups
| Security Group | Purpose | Inbound Rules |
|---|---|---|
| EICE‑sg (EC2 Instance Connect Endpoint) | Connect endpoint | SSH (limit to VPC CIDR) |
| ALB‑sg | Application Load Balancer | HTTP & HTTPS (allow from anywhere) |
| web‑sg | Web server | HTTP & HTTPS (allow from ALB‑sg), SSH (limit to EICE‑sg) |
| db‑sg | Database | MySQL (allow from web‑sg) |
| dms‑sg | Data migration | SSH (limit to EICE‑sg) |
4. Create an EC2 Instance Connect Endpoint
- Place it in a private subnet (e.g.,
private-app-az2). - Attach EICE‑sg.
5. Create an S3 Bucket
Upload your application code to the bucket.
6. Create an IAM Policy
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:ListBucket"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"secretsmanager:GetSecretValue",
"secretsmanager:DescribeSecret"
],
"Resource": "*"
}
]
}
For practice you can allow all resources; in production, limit the ARN.
7. Create an IAM Role
- Trust entity: EC2.
- Attach the policy created above.
- Give the role a meaningful name (e.g.,
WebAppS3AccessRole).
8. Create a DB Subnet Group
Select the VPC and two private subnets in different AZs.
9. Launch an RDS MySQL Instance
- Standard create → MySQL (latest engine version).
- Choose the Free Tier.
- Set DB instance identifier and initial database name.
- Enable AWS Secrets Manager for credentials.
- Use the previously created Subnet group and db‑sg.
- Pick an AZ and configure any additional settings as needed.
10. Migrate Data to RDS
- Launch a temporary EC2 instance (no key pair) in a private subnet (
private-app-az2) with dms‑sg. - Attach the IAM role created in step 7.
- Connect via the console and run the migration script.
- Scripts are available at:
After migration, terminate the temporary EC2 instance.
11. Deploy the Web Server
- Launch another EC2 instance (no key pair) in a private subnet with web‑sg.
- Attach the S3‑access role.
- Run the deployment script (same GitHub repo as above) to pull code from S3 and start the application.
12. Create a Target Group
- Type: Instance
- VPC: your VPC
- Health check path: default (or custom) – include HTTP codes
200,301,302. - Register the web server instance.
13. Set Up an Application Load Balancer
- Choose the VPC and two public subnets (one per AZ).
- Attach ALB‑sg.
- Listeners:
- HTTP → Redirect to HTTPS (full URL).
- HTTPS → Forward to the target group created above; attach your SSL certificate.
14. Configure DNS
Create a DNS A (Alias) record (e.g., www.example.com) that points to the ALB.
You can now access your web application via the domain name.
15. Prepare for Traffic Spikes – Auto Scaling
- Create an AMI from the running web server instance (Actions → Image → Create Image).
- Launch Template: define the AMI, instance type, security groups, IAM role, etc.
- Auto Scaling Group:
- VPC: select the private subnets.
- Attach the ALB and target group.
- Configure health checks and desired capacity (min/max/desired).
The Auto Scaling group will launch additional instances as traffic grows and terminate them when load decreases.
Final Thoughts
Learning AWS becomes easier when you build real projects. Deploying a dynamic web application is an excellent beginner exercise to understand how cloud services work together. Give it a try, and stay tuned for more practical posts on AWS, Docker, and cloud computing.