Assign a Domain Name to an EC2 Instance
2024
To assign your purchased domain name to an EC2 instance, you need to map the domain name to your EC2 instance’s public IP address using DNS settings. Here’s a step-by-step guide to help you with this process:
Steps to Assign a Domain Name to an EC2 Instance
1. Get Your EC2 Instance Public IP
- Go to the AWS Management Console and navigate to the EC2 Dashboard.
- Under Instances, find the EC2 instance you want to assign the domain to.
- Note down the Public IPv4 address or Elastic IP (if you’ve assigned one to your instance). If not, consider assigning an Elastic IP to ensure the IP doesn’t change on instance stop/start.
2. Go to Your Domain Registrar
- Log in to the account where you purchased your domain (e.g., GoDaddy, Namecheap, Google Domains).
- Look for the DNS Management section or DNS Settings for the domain.
3. Update DNS Records
- Create an A Record:
- In the DNS settings, create an A record (Address record).
- For the Name, enter either:
@
(for the root domain, e.g.,yourdomain.com
), orwww
(if you want it to work forwww.yourdomain.com
).
- For the Value, enter your EC2 instance’s Public IPv4 address or Elastic IP.
- Save the record.
- Create a CNAME Record (Optional):
- If you want both
www.yourdomain.com
andyourdomain.com
to point to the same EC2 instance, you can create a CNAME record: - Name:
www
- Value:
yourdomain.com
- If you want both
4. Wait for DNS Propagation
- DNS changes may take some time (usually up to 24 hours) to propagate globally, although it typically takes much less.
5. (Optional) Set Up HTTPS (SSL Certificate)
- If you want your domain to use HTTPS (recommended), you’ll need to set up an SSL certificate:
- You can use AWS Certificate Manager (ACM) to provision an SSL certificate, or use services like Let’s Encrypt.
- You’ll also need to configure your EC2 web server (e.g., Nginx or Apache) to handle SSL connections.
6. Test Your Domain
- After the DNS propagation period, visit your domain (
yourdomain.com
) in a browser. - If configured correctly, it should resolve to your EC2 instance.
An Elastic IP (EIP) in AWS is free under certain conditions but can incur charges depending on how it’s used. Here are the key points regarding Elastic IP pricing:
When Elastic IP is Free:
- One Elastic IP associated with a running instance: If you have one Elastic IP attached to an actively running EC2 instance, there is no charge.
When Elastic IP Incurs Charges:
- Unused Elastic IP: If you allocate an Elastic IP but do not associate it with any running instance (i.e., the Elastic IP is idle), AWS will charge you for keeping that IP address reserved.
- Multiple Elastic IPs per instance: AWS allows one free Elastic IP per running EC2 instance. If you associate more than one Elastic IP with the same instance, you will be charged for the additional Elastic IPs.
- Elastic IP associated with a stopped instance: If your instance is stopped or terminated but the Elastic IP is still allocated to your account (and not in use), you will be charged.
Pricing (Subject to AWS region):
- $0.005 per hour (or approximately $3.60 per month) for each idle or unused Elastic IP.
- $0.005 per hour for additional Elastic IPs associated with a single instance (beyond the first free one).
Key Recommendations:
- Release unused Elastic IPs: If you’re not using an Elastic IP, make sure to release it to avoid unnecessary charges.
- Use an Elastic IP only when necessary (e.g., when you need a static IP for your instance) to optimize costs.
You can check AWS Elastic IP pricing for your specific region in the AWS Pricing documentation.
Is ACM for SSL free when the domain is purchased via AWS?
Yes, AWS Certificate Manager (ACM) provides free SSL/TLS certificates when used with AWS services, such as Elastic Load Balancing (ELB), Amazon CloudFront, and API Gateway, regardless of where you purchased your domain.
Even if you buy a domain through AWS Route 53, ACM will still provide free SSL certificates for that domain as long as the certificate is used with eligible AWS services.
Key Points about AWS ACM SSL Certificates:
- Free of Charge:
- SSL certificates provided by ACM are free to request, issue, and renew.
- ACM automatically renews the certificates for you, so you don’t have to worry about manually renewing them.
- Limited to AWS Services:
- These certificates can only be used with AWS resources like Load Balancers, CloudFront distributions, or API Gateway.
- If you want to use an SSL certificate for external services (such as on-premise servers), you would need to purchase a certificate from a third-party provider, as ACM certificates cannot be exported.
- Domain Validation:
- You’ll need to validate that you own the domain (via DNS or email validation) when requesting an SSL certificate through ACM.
- Works with AWS Route 53:
- If you’ve purchased your domain through AWS Route 53, it simplifies the validation process for SSL certificates, particularly with DNS validation.
In summary:
Purchasing a domain from AWS Route 53 does not directly affect the cost of the SSL certificate itself, as ACM certificates are free for use with eligible AWS services, regardless of how or where the domain was purchased.