Create a Web Server using Amazon EC2
I launched an Apache web server on an Amazon EC2 instance, set it up automatically with a User Data script, and managed it through Session Manager instead of SSH.
Amazon Elastic Compute Cloud (EC2) is an AWS service that gives you scalable, resizable virtual servers, with the CPU, memory, storage and networking you choose, to run applications in the cloud.
Figure 1 illustrates the deployment architecture of the EC2 instance in the Singapore AWS Region, specifically within a public subnet. End users can access the Apache web server through the internet, while the system administrator can remotely manage the instance, install updates, and apply software patches using AWS Systems Manager Session Manager.
How I built it
1. Choosing the AMI
I launched an instance named apache-web-server and chose Amazon Linux 2023 as its Amazon Machine Image (AMI). It is Amazon's own Linux distribution, and it's free, lightweight and optimized for AWS.
An AMI is a preconfigured template with the operating system and software needed to start an instance, much like the operating system on a personal computer. The AMI you pick decides the operating system and starting software of your server.
2. Choosing the instance type
I selected t3.micro. The instance type sets the hardware resources of the server. In the name, the letter t is the instance family (General Purpose) and the number 3 is the generation. Newer generations usually bring better performance and efficiency.
General Purpose (T) instances balance CPU, memory and networking, which suits web servers. Other families cover different needs:
- Compute Optimized (C) for high processing power
- Memory Optimized (R, X, U) for large amounts of memory
- Storage Optimized (I, D, H) for fast, large storage
- Accelerated Computing (P, G, F, Inf) for GPUs and other accelerators, such as machine learning
3. Key pair
A key pair is two cryptographic keys that let you connect to an instance, usually over SSH, without a username and password. I chose to continue without a key pair because I connect to the instance with AWS Session Manager, which I turned on in the advanced details.
4. Network settings and security group
I used my own VPC, my-VPC, and picked Public Subnet 1, which already auto-assigns a public IP address. I then created a security group named Web Security Group with the description "enable inbound HTTP" and a rule allowing HTTP from anywhere, so everyone can reach the web server.
A security group is a virtual firewall for resources like EC2 instances. Inbound rules control incoming traffic and outbound rules control outgoing traffic. Common ports are 22 for SSH, 80 for HTTP and 443 for HTTPS. Security groups are stateful, which means response traffic is allowed automatically. They only support allow rules, and changes apply right away without restarting the instance.
5. Storage
I kept the default storage because this project is a demonstration and needs no extra space.
6. Advanced details
Under IAM instance profile I selected SSM_EC2, a role I created earlier in IAM. An IAM role gives temporary, secure permissions to AWS resources. This one lets me manage the instance through AWS Systems Manager without a key pair or SSH.
In the User Data field I added a script that installs Apache (httpd) and sets up the web page. User Data runs automatically the first time an instance launches, so the web server is ready as soon as the instance starts, without me connecting to it.
7. The figure below shows the successful deployment and verification of the web server.
Summary
- Instance
apache-web-serveron Amazon Linux 2023, typet3.micro - No key pair, with access through Session Manager and the
SSM_EC2IAM role my-VPCandPublic Subnet 1, withWeb Security Groupallowing inbound HTTP- Default storage
- User Data script that installs and configures Apache automatically