Mapping a custom domain (e.g., yourdomain.com or api.yourdomain.com) to an Amazon EC2 instance involves reserving an Elastic IP (Static IPv4), opening Security Group ports, updating your DNS registrar records, and binding your web server with an SSL/TLS certificate.
Technical Overview & Architecture
User Request ──> https://api.yourdomain.com
│
▼ (DNS Registrar - A Record)
AWS Elastic IP (Static IPv4)
│
▼ (EC2 Security Group)
Ports 80/443 Open
│
▼ (AWS EC2 Web Server)
Nginx / Apache / IIS / Reverse Proxy
AWS Infrastructure: Linux or Windows EC2 Instance.
Network Requirement: AWS Elastic IP Address (Static IPv4).
DNS Registrar Access: Ability to edit DNS zone records (GoDaddy, Route 53, Cloudflare, Namecheap, etc.).
Step 1: Allocate and Associate an AWS Elastic IP
By default, EC2 public IP addresses are dynamic and change every time the instance is stopped or restarted. An Elastic IP provides a persistent public IPv4 address.
Log in to the AWS Management Console and open the EC2 Console.
In the left navigation pane under Network & Security, click Elastic IPs.
Click Allocate Elastic IP address.
Choose Amazon's pool of IPv4 addresses and click Allocate.
Select the newly allocated Elastic IP from the list, click Actions, and choose Associate Elastic IP address.
Set Resource type to Instance.
Select your Instance ID and its Private IP address.
Click Associate.
Copy your Elastic IP address for use in Step 3.
Step 2: Configure EC2 Security Group Inbound Rules
Ensure your EC2 instance permits incoming HTTP (Port 80) and HTTPS (Port 443) traffic.
In the EC2 Console left menu under Network & Security, click Security Groups.
Select the Security Group attached to your EC2 instance.
Click the Inbound rules tab and select Edit inbound rules.
Add the following two rules if they do not already exist:
| Type | Protocol | Port Range | Source | Description |
|---|---|---|---|---|
| HTTP | TCP | 80 | 0.0.0.0/0 | Allow web traffic from anywhere |
| HTTPS | TCP | 443 | 0.0.0.0/0 | Allow secure web traffic from anywhere |
Click Save rules.
Step 3: Configure DNS Records at Your Registrar
Log in to your DNS management provider (GoDaddy, Route 53, Cloudflare, Namecheap, etc.) and create the necessary DNS records.
Join the conversation! Your thoughts help the community grow.