This chapter covers:
2.1 Creating your infrastructure
You’ll use four different AWS services to copy the old infrastructure to AWS:
■ Elastic Load Balancing (ELB)—AWS offers a load balancer as a service. The Elastic Load Balancer (ELB) distributes traffic to a bunch of servers behind it. It’s highly available by default.
■ Elastic Compute Cloud (EC2)—A virtual server is provided by the Elastic Compute Cloud (EC2) service. You’ll use a Linux server with an optimized distribution called Amazon Linux to install Apache, PHP, and WordPress. You aren’t limited to Amazon Linux; you could also choose Ubuntu, Debian, Red Hat, or Win-dows. Virtual servers can fail, so you need at least two of them. The load bal-ancer will distribute the traffic between them. In case of a server failure, the load balancer will stop sending traffic to the failed server, and the remaining server will need to handle all the requests until the failed server is replaced.
■ Relational Database Service (RDS) for MySQL—WordPress relies on the popular MySQL database. AWS provides MySQL as a Relational Database Service (RDS).
You choose the database size (storage, CPU, RAM), and RDS takes care of the rest (backups, updates). RDS can also provide a highly available MySQL data-base by replication.
■ Security groups—Security groups are a fundamental service of AWS to control network traffic like a firewall. Security groups can be attached to a lot of services like ELB, EC2, and RDS. With security groups, you can configure your load bal-ancer so that it only accepts requests on port 80 from the internet, web servers only accept connections on port 80 from the load balancer, and MySQL only accepts connections on port 3306 from the web servers. If you want to log in to your web servers via SSH, you must also open port 22.
Figure 2.1 shows all the parts of the infrastructure in action. Sounds like a lot of stuff to set up, so let’s get started!
36 CHAPTER 2 A simple example: WordPress in five minutes
If you expect pages of instructions, you’ll be happy to know that you can create all that with a few clicks. The following tasks are performed automatically in the background:
1 Creating an ELB
2 Creating a RDS MySQL database
3 Creating and attaching security groups
4 Creating two web servers:
– Creating two EC2 virtual servers
– Installing Apache and PHP via yum install php, php-mysql, mysql, httpd – Downloading and extracting the latest version of WordPress from http://
wordpress.org/latest.tar.gz
– Configuring WordPress to use the created RDS MySQL database – Starting Apache
To create the blogging infrastructure, open the AWS Management Console at https://
console.aws.amazon.com. Click Services in the navigation bar, and click the Cloud-Formation service. You’ll see a page like the one shown in figure 2.2.
NOTE All examples in this book use N. Virginia (also called us-east-1) as the default region. Exceptions are indicated. Please make sure you switch to the region N. Virginia before working on an example. When using the AWS Man-agement Console, you can check and switch the region on the right side of the main navigation bar.
Incoming requests
Distribute traffic to web servers
Security groups act as a virtual firewall.
AWS takes care of them to protect your system from malicious traffic.
Elastic Load Balancing (ELB) is a SaaS providing a managed load balancer.
The service is fault-tolerant. Service (RDS) is a SaaS providing a managed MySQL database. AWS takes care of backups, updates, and replication.
Elastic Compute Cloud (EC2) is an IaaS providing virtual servers (Linux and Windows). You can install any software you like on them.
Figure 2.1 The company’s blogging infrastructure consists of two load-balanced web servers running WordPress and a MySQL database server.
Click Create Stack to start the four-step wizard, as shown in figure 2.3.
Click to create a new infrastructure from a blueprint.
Reload the page.
You haven’t created an infrastructure from a blueprint at the moment.
Figure 2.2 CloudFormation screen
Step 1 of 4 Name your
infrastructure.
Here you select the blueprint for the infrastructure. You can select a sample, upload, or provide an URL. Insert URL of CloudFormation template.
Figure 2.3 Creating a blogging infrastructure: step 1 of 4
38 CHAPTER 2 A simple example: WordPress in five minutes
Enter wordpress as the Name. For Source, select Specify an Amazon S3 Template URL, and copy this URL: https://s3.amazonaws.com/awsinaction/chapter2/template .json. Click Next to set the KeyName to mykey, as shown in figure 2.4.
Click Next to create a tag for your infrastructure. A tag consists of a key-value pair and can be used add information to all parts of your infrastructure. You can use tags to differentiate between testing and production resources, add the cost center to eas-ily track costs in your organization, or mark resources that belong to a certain applica-tion if you host multiple applicaapplica-tions in the same AWS account.
In this example, you’ll use a tag to mark all resources that belong to the wordpress system. This will help you later to easily find your infrastructure. Use system as the key and wordpress as the value. Figure 2.5 shows how to configure the tag.
Step 2 of 4 Specify the key pair you
created in chapter 1.
Figure 2.4 Creating a blogging infrastructure: step 2 of 4
Pitfall: media uploads and plugins
WordPress uses a MySQL database to store articles and users. But by default, Word-Press stores media uploads (images) and plugins in a folder called wp-content on the local file system: the server isn’t stateless. Using multiple servers isn’t possible by default because each request will be served by another server, but media uploads and plugins are stored on only one of the servers.
The example in this chapter is incomplete because it doesn’t handle this problem. If you’re interested in a solution, see chapter 14, where plugins are installed automati-cally during bootstrapping virtual servers and media uploads are outsourced to an ob-ject-storage service.
Click Next. Finally, you’ll see a confirmation page, as shown in figure 2.6. In the Estimate Cost row, click Cost. This will open a new browser tab in the background; you’ll deal with it in the next section. Switch back to the original browser tab and click Create.
Step 3 of 4
Use tags to identify your infrastructure.
A tag consists of a key-value pair.
Figure 2.5 Creating a blogging infrastructure: step 3 of 4
Step 4 of 4
Name of your infrastructure
URL for the wordpress blueprint from the book
Specified key pair you created in chapter 1
Opens a new browser tab to estimate costs with the Simple Monthly Calculator
Tags identify your infrastructure.
Figure 2.6 Creating a blogging infrastructure: step 4 of 4
40 CHAPTER 2 A simple example: WordPress in five minutes
Your infrastructure will now be created. Figure 2.7 shows that wordpress is in state CREATE_IN_PROGRESS. It’s a good time to take a break; come back in 5-15 minutes, and you’ll be surprised.
Take a look at the result by refreshing the page. Select the Wordpress row, where Status should be CREATE_COMPLETE. If the status is still CREATE_IN_PROGRESS, be patient until the status becomes CREATE_COMPLETE. Switch to the Outputs tab, as shown in figure 2.8. There you’ll find the URL to your wordpress system; click it to visit the system.
Infrastructure is being created.
You have created one infrastructure from a blueprint at the moment.
Reload the page.
Figure 2.7 Review screen
URL to your newly created WordPress
Infrastructure has been created
Figure 2.8 Blogging infrastructure result
You may ask yourself, how does this work? The answer is automation.
You’ll explore the blogging infrastructure in the next section to get a better under-standing of the services you’re using.