WordPress on Amazon EC2: IP and Domain-Name Addressing

info

Update: May 2020

This article was originally created in 2018 and completely updated in May 2020. I will not be updating it going forward.


This is part of my Introduction to Hosting WordPress on Amazon Web Services (AWS) tutorial.

In the first two articles of this series I went over the steps to create an AWS EC2 instance from the WordPress Certified by Bitnami and Automattic image to host a WordPress site. In this article I am going to go over the steps to access that instance with an IP address, and how to assign a domain name to that instance using the Route 53 service from AWS. But first I’m going to go over something else: restarting or shutting down an EC2 instance.

Restarting or Shutting Down an EC2 instance

  1. Log in to your AWS account.
  2. From the AWS Management Console, type EC2 into the Find Services search box.
  3. To see your instances, click Instances in the left sidebar under Instances or click Running Instances in the Resources pane.
    Screenshot: naming AWS EC2 instances and volumes, and creating snapshots.
  4. Select an instance from the list on the Instances screen. (In this screenshot, there is only one instance). If you look under the Description tab’s right column you will see fields for Public DNS (IPv4) and IPv4 Public IP, the IP address for your EC2 instance on the internet. Click the IP address and a copy icon will appear. Copy the address, which in this example is 35.183.27.211, and keep it for your records.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  5. After you create an instance, it is online and running and online until stop the instance (shut it down), or reboot (restart) it, or terminate (delete) it. If you’re not using an instance, you can shut it down so that you incur fewer charges on your AWS bill. Or you may want to reboot the instance as a way to troubleshoot an issue. To stop or reboot an instance, select the instance from the list, click the Actions button, click the Instance State submenu, and click either Stop or Reboot.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  6. For this demonstration, I select Stop to shut down the instance.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  7. A Stop Instances pop-up will warn you that by stopping the instance you risk losing any ephemeral data. Click Yes, Stop.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
    • If you had chosen to reboot, you would get a similar pop-up and would click Yes, Reboot.
      Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  8. Your instance will show a progress icon and the Instance State will change to stopping.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  9. When the instance has shut down, Instance State changes to stopped. The Description tab no longer displays an IP address.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  10. It’s time to start the instance again. Click the Actions button, click the Instance State submenu, then click Start.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  11. Click Yes, Start when the Start Instances pop-up appears.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  12. After restarting, the instance’s Instance State will display running.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  13. Under the Description tab, Public DNS (IPv4) and IPv4 Public IP are displaying IP address information again. But if you look at the values, they have changed. Before we stopped the instance, the IP address in the IPv4 Public IP field was 35.183.27.211; now it is 35.183.186.160.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.

So what did we learn? If you restart or stop your instance, the IP address will not persist, and AWS will assign you a new one. This will make it very difficult to keep track of your instance’s IP, and you need that IP address to do just about everything. AWS has a solution: the Elastic IP address.

Create an Elastic IP for your EC2 instance

  1. To create an Elastic IP and assign it to your instance, click EC2 Dashboard in the left sidebar.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  2. Click Elastic IPs in the left sidebar under Networking & Security or click Elastic IPs in the Resources pane.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  3. Click the Allocate Elastic IP address button on the Elastic IP addresses screen.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  4. The Allocate Elastic IP address screen gives you options about where your IP address will come from. You can bring your own address to AWS, but since I don’t have any IP addresses, I leave the radio button set to Amazon’s pool of IPv4 addresses and click Allocate.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  5. The new Elastic IP address is displayed in the Public IPv4 address column: 15.223.95.15.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  6. Now the Elastic IP address exists, it needs to “associated” with the instance. Click the Actions button and then click Associate IP address.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  7. On the Associate Elastic IP address screen. If the Resource Type does not default to Instance, select it.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  8. Click in the Instance box to search for and select the instance. Since I only have one, it immediately appears as a suggested result.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  9. However, I can search by the name of my instance with WordPress.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  10. I can also search by the Instance ID.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  11. Select the instance and click Associate.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  12. The Instance ID appears in the Associated Instance ID field. There is a properties pane at the bottom of the screen which you can expand with the handle.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  13. The Summary tab shows all of the Elastic IP’s properties. Add a name by clicking Tags.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  14. Click the Manage tags button.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  15. Tag the Elastic IP with a key/value pair click Save.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  16. A page that lists all of the properties of the Elastic IP address appears, including the Associated Instance ID. Click the Elastic IP addresses link above the IP address.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  17. You can now see the associated, named IP address in your list of Elastic IP addresses. As long as you have this Elastic IP address associated with an instance, that instance can be reached using the Elastic IP address.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.

Associate an Elastic IP with a Domain Name using Route 53

Once the EC2 instance is associated with an Elastic IP address, you can use that IP address to access the instance. You can also use that same Elastic IP address with AWS’s Route 53 service to associate the instance with a domain name.

  1. From the AWS Management Console, type route 53 into the Find Services search box and click Route 53.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  2. Route 53 provides several services, but I am using it because it is AWS’s domain name management system. Since I want to associate my EC2 instance with a domain name, click the Hosted zones link under DNS management.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  3. In this screenshot, there are two hosted zones for the two websites I host with this account, including massolit-media.com. But to demonstrate, I can create a new hosted zone and repeat the process. Click Create Hosted Zone.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  4. The Create Hosted Zone pane appears on the right side of the screen. I enter massolit-media.com as the Domain Name (the name of the new hosted zone), and add a Comment, TEST-ONLY. I leave the Type as the default Public Hosted Zone.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  5. Route 53 automatically populates the hosted zone with four name servers, which appear in this screenshot on the first row with Type: NS (a DNS record type of NS, or name server). The second row contains another DNS record, SOA, or Start of Authority, which provides administrative information about the domain name to the DNS system. Click Create Record Set.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  6. In the Create Record Set pane, you will see a Name: field, which has a text box followed by your domain name followed by a period, or the “trailing dot.” In this screenshot, the text box is followed by massolit-media.com., where the . you see after .com represents the end of the fully qualified domain name – just like the period at the end of a sentence. There is also a Type: field for the DNS record type. It defaults to A – IPv4 address; if this is not the value, use the drop-down to select that type.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  7. Enter the Elastic IP address into the Value: field. This is where we tie our EC2 instance and the Elastic IP address we associated with it to our domain name. Click Create.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  8. Back on the Hosted zones dashboard you can see your new record set for your domain name. It’s an A record and the Elastic IP address appears in its Value field, meaning the DNS system will point massolit-media.com. to 15.223.95.15, which is the public IP address for your EC2 instance and for your WordPress site you are hosting on it.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  9. I’m not sure how critical it is, but I also want to make sure my domain name can be reached in the event that somebody types www. before the domain name. Click Create Record Set.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  10. The Create Record Set pane opens on the right side of the screen. The radio button for Alias: defaults to No. Click Yes.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  11. The Alias: section expands to include an Alias Target: text field and lists the AWS resources that can be selected.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  12. Click in the text field and start typing the Name of the record set for your A record. Route 53 should suggest the domain name under Record sets in this hosted zone. Click the suggested search result, which in this case is massolit-media.com..
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  13. The domain name appears in the Alias Target: field, and an Alias Hosted Zone ID appears underneath it. Click the Create button to create the alias.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.
  14. The new record set normally appears at the bottom of the list. Its Name includes www. before the domain name, it is an A record, and the Value field identifies it as an ALIAS of the first A record you created for the Elastic IP. Click Back to Hosted Zones to return to the list of hosted zones.
    Screenshot: AWS EC2 instance, Elastic IPs, Route 53 DNS management, and restarting or shutting down the instance.