Hosting A Web App
Hosting A Web App
All other trademarks not owned by Amazon are the property of their respective owners, who may or may not be affiliated with, connected
to, or sponsored by Amazon.
Getting Started with AWS Hosting a Web App
Table of Contents
Hosting a Web App ........................................................................................................................ 1
Web App Hosting Architecture ................................................................................................. 1
Tutorial ................................................................................................................................ 2
Pricing ................................................................................................................................. 3
Setting Up .................................................................................................................................... 4
Sign Up for AWS ................................................................................................................... 4
Create an IAM User ............................................................................................................... 5
Create a Key Pair .................................................................................................................. 6
Configure a Virtual Private Cloud (VPC) .................................................................................... 7
Step 1: Create an Application Server ................................................................................................ 9
Create a Security Group for Your Amazon EC2 Instance ............................................................... 9
Create an IAM Role ............................................................................................................. 10
Launch Your EC2 Instance .................................................................................................... 11
Step 2: Create a Database Server .................................................................................................. 12
Create a Security Group for Your DB Instance ........................................................................... 12
Launch a DB Instance .......................................................................................................... 13
Step 3: Deploy Your App ................................................................................................................ 16
Connect to Your Linux Instance .............................................................................................. 16
Configure the EC2 Instance ................................................................................................... 18
Start the Web Server .................................................................................................... 18
Install the App ............................................................................................................. 19
Test the Website .......................................................................................................... 22
Update Permissions ..................................................................................................... 24
Create a Custom AMI ........................................................................................................... 24
Step 4: Scale and Load-Balance Your Web App ................................................................................. 25
Configure Auto Scaling and Load Balancing ............................................................................. 25
Test Your Load Balancer ........................................................................................................ 27
Step 5: Associate a Domain Name with Your Website ......................................................................... 29
Register a Domain Name ...................................................................................................... 29
Create a Hosted Zone for Your Domain .................................................................................... 30
Create Resource Record Sets for Your Domain and Subdomain ................................................... 30
Set Up a DNS Provider ......................................................................................................... 30
Step 6: Clean Up ......................................................................................................................... 32
Delete the Amazon Route 53 Hosted Zone ............................................................................... 32
Delete the Auto Scaling Group ............................................................................................... 33
Delete the Load Balancer ...................................................................................................... 33
Delete Your Custom AMI ....................................................................................................... 33
Terminate the DB Instance .................................................................................................... 34
Related Resources ...................................................................................................................... 35
iii
Getting Started with AWS Hosting a Web App
Web App Hosting Architecture
A web app is any software that users access through a web browser or specialized web client. Web apps
are typically structured into logical tiers. For example, a common structure uses three tiers. The first tier
is the web browser, which is responsible for presenting the user interface. The middle tier is an application
server, which is responsible for the application's functionality. The third tier is a database server or file
system, which is responsible for data storage.
This tutorial walks you through the process of hosting a scalable, robust web app on AWS infrastructure.
We'll deploy a sample app, demonstrating best practices. By the end of this tutorial, you should be able
to do the following:
• Create a virtual server, called an EC2 instance, and use it as an application server in the cloud.
• Create a database server, called a DB instance.
• Deploy a sample web app to the application server.
• Set up scaling and load balancing to distribute traffic across a minimum number of application servers.
• Associate a domain name with your web app.
Requirement Solution
Low-cost, reliable application and • Amazon EC2 provides virtual servers in the cloud. You control
database servers specify the protocols, ports, and source IP address ranges that
can access your virtual servers.
• Amazon EBS provides a persistent file system for Amazon EC2
virtual servers.
• Amazon RDS provides a cost-efficient and resizable database
server that's easy to administer.
1
Getting Started with AWS Hosting a Web App
Tutorial
Requirement Solution
An easy way to provision servers • Elastic Load Balancing supports health checks on hosts, distributes
to handle peak capacity without traffic to virtual servers across multiple isolated locations, known
incurring costs when the extra as Availability Zones, and dynamically adds or removes virtual
capacity isn't needed servers from the load-balancing rotation.
• Auto Scaling supports groups of servers that can grow or shrink
on demand.
• CloudWatch collects metrics data for your virtual servers, which
can be used by Auto Scaling.
A reliable and cost-effective way • Amazon Route 53 maps human-readable names to IP addresses.
to route users to your web app
The following diagram shows an example architecture for a web app that employs the services described
in the previous table. The web and application tiers run on EC2 instances in public subnets. Access to
the EC2 instances over SSH is controlled by a security group, which acts as a firewall. The Auto Scaling
group maintains a fleet of EC2 instances that can scale to handle the current load. This Auto Scaling
group spans multiple Availability Zones to protect against the potential failure of a single Availability Zone.
The load balancer distributes traffic evenly among the EC2 instances. When the Auto Scaling group
launches or terminates instances based on load, the load balancer automatically adjusts accordingly.
The database tier consists of DB instances in private subnets, including a master and a local slave, located
in multiple Availability Zones for failover protection. Access to the DB instances from the EC2 instances
is controlled by a security group. Amazon Route 53 provides secure and reliable routing of your domain
name to your infrastructure hosted on AWS.
Tutorial
This tutorial walks you through the process of hosting a web app on AWS. We'll use the AWS Management
Console to access AWS.
2
Getting Started with AWS Hosting a Web App
Pricing
Alternatively, you can use Elastic Beanstalk to create, load balance, scale, and monitor your servers. For
more information, see Getting Started with AWS: Deploying a Web App or the AWS Elastic Beanstalk
Developer Guide.
Pricing
You can use the AWS Simple Monthly Calculator to estimate what it would cost to host your web app on
AWS.
Note that if you created your AWS account within the last 12 months, you are eligible for the AWS Free
Tier.
3
Getting Started with AWS Hosting a Web App
Sign Up for AWS
Before you start this tutorial, complete the following tasks if you haven't already.
Tasks
• Sign Up for AWS (p. 4)
• Create an IAM User (p. 5)
• Create a Key Pair (p. 6)
• Configure a Virtual Private Cloud (VPC) (p. 7)
If you created your AWS account less than 12 months ago, you can get started with AWS for free. For
more information, see AWS Free Tier.
If you have an AWS account already, skip to the next step. If you don't have an AWS account, use the
following procedure to create one.
Part of the sign-up procedure involves receiving a phone call and entering a PIN using the phone
keypad.
4
Getting Started with AWS Hosting a Web App
Create an IAM User
Create an IAM user, and then add the user to an IAM group with administrative permissions or and grant
this user administrative permissions. You can then access AWS using a special URL and the credentials
for the IAM user.
If you signed up for AWS but have not created an IAM user for yourself, you can create one using the
IAM console.
1. Sign in to the AWS Management Console and open the IAM console at https://
console.aws.amazon.com/iam/.
2. In the navigation pane, click Groups, then click Create New Group.
3. In the Group Name box, type Administrators and then click Next Step.
4. In the list of policies, select the check box next to the AdministratorAccess policy. You can use the
Filter menu and the Search box to filter the list of policies.
5. Click Next Step, then click Create Group.
To create an IAM user for yourself, add the user to the Administrators group, and create
a password for the user
1. In the navigation pane, click Users and then click Create New Users.
2. In box 1, enter a user name. Clear the check box next to Generate an access key for each user,
then click Create.
3. In the list of users, click the name (not the check box) of the user you just created. You can use the
Search box to search for the user name.
4. In the Groups section, click Add User to Groups.
5. Select the check box next to the Administrators group, then click Add to Groups.
6. Scroll down to the Security Credentials section. Under Sign-In Credentials, click Manage Password.
7. Select Assign a custom password, then enter a password in the Password and Confirm Password
boxes. When you are finished, click Apply.
To sign in as this new IAM user, sign out of the AWS console, then use the following URL, where
your_aws_account_id is your AWS account number without the hyphens (for example, if your AWS
account number is 1234-5678-9012, your AWS account ID is 123456789012):
https://your_aws_account_id.signin.aws.amazon.com/console/
Enter the IAM user name and password that you just created. When you're signed in, the navigation bar
displays "your_user_name @ your_aws_account_id".
5
Getting Started with AWS Hosting a Web App
Create a Key Pair
If you don't want the URL for your sign-in page to contain your AWS account ID, you can create an account
alias. From the IAM dashboard, click Customize and enter an alias, such as your company name. To
sign in after you create an account alias, use the following URL:
https://your_account_alias.signin.aws.amazon.com/console/
To verify the sign-in link for IAM users for your account, open the IAM console and check under IAM
users sign-in link on the dashboard.
If you haven't created a key pair already, you can create one using the Amazon EC2 console.
• If your computer runs Windows, use the following steps to convert your .pem file to a .ppk file
for use with PuTTY.
6
Getting Started with AWS Hosting a Web App
Configure a Virtual Private Cloud (VPC)
f. Click Save private key. PuTTYgen displays a warning about saving the key without a
passphrase. Click Yes.
g. Specify the same name that you used for the key pair (for example, my-key-pair) and
then click Save. PuTTY automatically adds the .ppk file extension.
If you have a default VPC, you can use it for this tutorial, and you can skip the next procedure. Otherwise,
use the following procedure to create a VPC with two public subnets for use with this tutorial.
To create a VPC
4. In the navigation pane, click Route Tables. Find the route table where the Main column is Yes. This
is the main route table. Click the Name column for the main route table, enter Main, and press Enter.
Click the Name column for the other route table, enter Custom, and press Enter.
5. Add a second public subnet as follows, so that you'll have two subnets for your application servers.
(Note that a default VPC already has a public subnet for each Availability Zone.)
7
Getting Started with AWS Hosting a Web App
Configure a Virtual Private Cloud (VPC)
Next, we need to add private subnets for your database servers to your default VPC or the VPC that you
just created.
For more information about Amazon VPC, see the Amazon VPC User Guide.
8
Getting Started with AWS Hosting a Web App
Create a Security Group for Your Amazon EC2 Instance
You can use Amazon EC2 to create a virtual server to run your web app. These virtual servers are called
EC2 instances. Typically, you start from a base image called an Amazon Machine Image (AMI).
To create a virtual server using Amazon EC2, complete the following tasks.
Tasks
• Create a Security Group for Your Amazon EC2 Instance (p. 9)
• Create an IAM Role (p. 10)
• Launch Your EC2 Instance (p. 11)
For this tutorial, we'll create a security group and add the following rules:
1. Decide who requires access to your instance; for example, a single computer or all the computers
on a network that you trust. For this tutorial, you can use the public IP address of your computer,
which you can get using a service. For example, AWS provides the following service: http://
checkip.amazonaws.com. To locate another service that provides your IP address, use the search
phrase "what is my IP address".
9
Getting Started with AWS Hosting a Web App
Create an IAM Role
If you are connecting through an ISP or from behind your firewall without a static IP address, you
need to find out the range of IP addresses used by client computers. If you don't know this address
range, you can use 0.0.0.0/0 for this tutorial. However, this is unsafe for production environments
because it allows everyone to access your instance using SSH.
2. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
Tip
You can also create a security group using the Amazon VPC console. However, you might
need to alter these directions if you're using the Amazon VPC console instead of the Amazon
EC2 console.
3. In the navigation bar, verify that US West (Oregon) is the selected region.
4. In the navigation pane, click Security Groups, and then click Create Security Group.
5. Enter WebServerSG as the name of the security group, and provide a description.
6. Select your VPC from the list.
7. On the Inbound tab, add the rules as follows:
a. Click Add Rule, and then select SSH from the Type list. Under Source, select Custom IP and
enter the public IP address range that you decided on in step 1 in the text box.
b. Click Add Rule, and then select HTTP from the Type list.
8. Click Create.
For more information, see Security Groups in the Amazon EC2 User Guide for Linux Instances.
We designed IAM roles so that you can effectively manage AWS credentials for software running on your
instances. You create an IAM role and configure it with the permissions that the software requires. For
more information about the benefits of this approach, see IAM Roles for Amazon EC2 in the Amazon
EC2 User Guide for Linux Instances and Roles (Delegation and Federation) in Using IAM.
The following procedure creates an IAM role that grants the web app full access to AWS. In production,
you can restrict the services and resources that a web app can access.
10
Getting Started with AWS Hosting a Web App
Launch Your EC2 Instance
a. T2 instances must be launched into a subnet. Select your VPC from Network and select one
of your public subnets from Subnet.
b. Ensure that for Auto-assign Public IP, Enable is selected in the list. Otherwise, your instance
will not get a public IP address or a public DNS name.
c. Select your IAM role from IAM role. Note that you must select an IAM role when you launch an
instance; you can't add a role to a running instance.
d. Click Review and Launch. If you are prompted to specify the type of root volume, make your
selection and then click Next.
7. On the Review Instance Launch page, click Edit security groups. On the Configure Security
Group page, click Select an existing security group, select the WebServerSG security group that
you created, and then click Review and Launch.
8. On the Review Instance Launch page, click Launch.
9. In the Select an existing key pair or create a new key pair dialog box, select Choose an existing
key pair, then select the key pair you created in Setting Up to Host a Web App on AWS (p. 4). Click
the acknowledgment check box, and then click Launch Instances.
10. In the navigation pane, click Instances to see the status of your instance. Initially, the status of your
instance is pending. After the status changes to running, your instance is ready for use.
11
Getting Started with AWS Hosting a Web App
Create a Security Group for Your DB Instance
You can use Amazon Relational Database Service (Amazon RDS) to run your database server. In this
step, you launch a Multi-AZ DB instance. This means that Amazon RDS automatically provisions and
maintains a synchronous standby replica in a different Availability Zone. Updates to your DB instance
are synchronously replicated across Availability Zones to the standby in order to keep them in sync and
protect your latest database updates against DB instance failure. During certain types of planned
maintenance, or in the event of DB instance failure or Availability Zone failure, Amazon RDS automatically
fails over to the standby. Because the name record for your DB instance remains the same, your app
can resume database operation without the need for manual administrative steps.
Tasks
• Create a Security Group for Your DB Instance (p. 12)
• Launch a DB Instance (p. 13)
12
Getting Started with AWS Hosting a Web App
Launch a DB Instance
Launch a DB Instance
Now that you've created your security group, you're ready to launch your instance
Important
You'll incur the standard Amazon RDS usage fees for this instance from the time that you launch
it until you terminate it, even if it remains idle. The total charges are minimal if you complete the
tutorial without interruption and terminate your DB instance when you are finished. For more
information, see Amazon RDS Pricing.
To launch an instance
5. In the navigation pane, click Instances, and then click Launch DB Instance.
6. On the Select Engine page, select the MySQL tab, and then click Select.
13
Getting Started with AWS Hosting a Web App
Launch a DB Instance
7. On the Do you plan to use this database for production purposes page, select Yes, use Multi-AZ
Deployment and Provisioned IOPS Storage as defaults while creating this instance, and then
click Next.
8. On the Specify DB Details page, do the following:
a. Keep the default license model and the default DB engine version.
b. Select db.t2.micro from the DB Instance Class list.
c. In Multi-AZ Deployment, select Yes. Although the Multi-AZ deployment is more expensive, it
is a best practice.
d. Select General Purpose (SSD) from Storage Type and keep the default value for Allocated
Storage.
e. In DB Instance Identifier, enter my-db-instance.
f. In Master Username, enter db_user.
g. Enter a password in Master Password and Confirm Password. Record your password in a
safe place.
h. Click Next.
a. Under Network & Security, select your VPC from VPC and select DBServerSG from VPC
Security Groups.
b. Under Database Options, in Database Name, enter my_database.
c. Click Launch DB Instance.
14
Getting Started with AWS Hosting a Web App
Launch a DB Instance
10. Launching can take a few minutes to complete. When you see the notice that your instance is being
created, click Close.
In the navigation pane, click Instances to see the status of your DB instance. Initially, the status of your
DB instance is creating. After the status changes to available, your DB instance ready for use.
15
Getting Started with AWS Hosting a Web App
Connect to Your Linux Instance
Deploy the app to your EC2 instance by completing the following tasks. For this tutorial, you'll install
Drupal and create a test page.
Tasks
• Connect to Your Linux Instance (p. 16)
• Configure the EC2 Instance (p. 18)
• Create a Custom AMI (p. 24)
Before you connect to your instance, get the public DNS name of the instance using the Amazon EC2
console. Select the instance and locate Public DNS on the Description tab.
Tip
If your instance doesn't have a public DNS name, open the VPC console, select the VPC, and
check the Summary tab. If either DNS resolution or DNS hostnames is no, click Edit and
change the value to yes.
Prerequisites
The tool that you use to connect to your Linux instance depends on the operating system running on your
computer. If your computer runs Windows, you'll connect using PuTTY. If your computer runs Linux or
Mac OS X, you'll connect using the SSH client. These tools require the use of your key pair. Be sure that
you created your key pair as described in Create a Key Pair (p. 6).
1. Start PuTTY (from the Start menu, click All Programs > PuTTY > PuTTY).
2. In the Category pane, select Session and complete the following fields:
16
Getting Started with AWS Hosting a Web App
Connect to Your Linux Instance
3. In the Category pane, under Connection type, expand SSH, and then select Auth. Complete the
following:
a. Click Browse.
b. Select the .ppk file that you generated for your key pair, as described in Create a Key Pair (p. 6),
and then click Open.
c. Click Open to start the PuTTY session.
4. If this is the first time you have connected to this instance, PuTTY displays a security alert dialog
box that asks whether you trust the host you are connecting to. Click Yes. A window opens and you
are connected to your instance.
1. Use the ssh command to connect to the instance. You'll specify the private key (.pem) file and
ec2-user@public_dns_name.
17
Getting Started with AWS Hosting a Web App
Configure the EC2 Instance
2. Enter yes.
Tasks
• Start the Web Server (p. 18)
• Install the App (p. 19)
• Test the Website (p. 22)
• Update Permissions (p. 24)
1. To ensure that your software packages are up to date, run the following command on your instance
to perform a quick software update.
2. Install the Apache web server and PHP software packages as follows.
3. (Optional) If you need PHP support for MySQL, as Drupal does, run the following command.
18
Getting Started with AWS Hosting a Web App
Install the App
5. Configure the Apache web server to start at each system boot using the following command.
6. Before you continue to the next step, verify that the web server is running. In a web browser on your
computer, paste the public DNS name of your instance into the address bar and press Enter. This
displays the Apache test page. If you don't see the test page for Apache, verify that your security
group allows HTTP traffic.
To install Drupal
1. Go to https://www.drupal.org/project/drupal and note the version of Drupal that you'd like to use.
2. On your instance, run the following command to download Drupal, where x.y is the Drupal version.
19
Getting Started with AWS Hosting a Web App
Install the App
3. Extract Drupal using the following command, where x.y is the Drupal version.
You can verify that the current directory contains the compressed and uncompressed versions.
[ec2-user ~]$ ls
drupal-x.y drupal-x.y.tar.gz
(Optional) To remove the compressed version of Drupal, run the following command, where x.y is
the Drupal version.
4. Grant ec2-user permission to write files to the Apache document root, /var/www/html as follows.
mv drupal-x.y/* /var/www/html/
20
Getting Started with AWS Hosting a Web App
Install the App
Drupal includes an installation wizard that you can run to configure your website. In the previous procedure,
you installed Drupal to the Apache document root, so you can run the installation wizard by opening the
website.
To configure Drupal
1. Open a web browser on your computer, and enter the public DNS address of your instance in the
address bar.
2. On the Choose profile page, click Standard and then click Save and continue.
3. On the Choose language page, click English (built-in), and then click Save and continue.
4. If you see the Verify requirements page, address any errors and then continue.
5. On the Set up database page, do the following:
21
Getting Started with AWS Hosting a Web App
Test the Website
22
Getting Started with AWS Hosting a Web App
Test the Website
To add a page
1. From your Drupal website, click Add new content and then click Basic page.
2. In the Title box, enter Hello World!.
3. In the button pane, select the Publishing options tab and then select Promoted to front page.
4. Click Save.
5. Refresh the website to see your new header and front page.
23
Getting Started with AWS Hosting a Web App
Update Permissions
Update Permissions
Now that your new site is created, you should remove write permissions from your default directory
and settings.php file as follows. Otherwise, the Drupal status report for your site warns you that your
settings.php file is not protected from modification and poses a security risk.
To view the status of your AMI, go to the AMIs page. While the AMI is being created, its status is pending.
If you go to the Snapshots page, you'll see that we created a snapshot that is used to create the root
device volume of any instance that you launch using your new custom AMI.
Now that you have a custom AMI, you no longer need the instance that you created it from, because we'll
use Auto Scaling to launch new instances in the next step. To terminate the instance, go to the Instances
page, select it, click Actions, select Instance State, and then click Terminate, and then click Yes,
Terminate.
24
Getting Started with AWS Hosting a Web App
Configure Auto Scaling and Load Balancing
In this step you'll configure Auto Scaling and Elastic Load Balancing for your EC2 instances. Auto Scaling
is designed to launch or terminate EC2 instances automatically based on the needs of your application.
Auto Scaling launches or terminates instances based on the scaling policies that you create. For example,
you can set up Auto Scaling to launch an additional instance whenever CPU usage exceeds 60 percent
for ten minutes, or you could tell Auto Scaling to terminate half of your instances over the weekend when
you expect traffic to be low. You can also monitor your instances to ensure that they are performing
optimally and that you always have at least one healthy instance running. For more information, see Auto
Scaling.
Elastic Load Balancing is designed to help you improve the availability and scalability of your application.
It makes it easy for you to distribute and balance incoming application traffic between two or more EC2
instances. You can dynamically add or remove instances from the load balancer as the capacity
requirements of your application change.
As soon as your load balancer becomes available, you're billed for each hour or partial hour that you
keep the load balancer running. Note that load balancing is a small cost relative to instance hours.
For more information, see Elastic Load Balancing Pricing. For more information about load balancers,
see the Elastic Load Balancing Developer Guide.
Tasks
• Configure Auto Scaling and Load Balancing (p. 25)
• Test Your Load Balancer (p. 27)
25
Getting Started with AWS Hosting a Web App
Configure Auto Scaling and Load Balancing
5. On the Assign Security Groups page, click Select an existing security group, and then select
your WebServerSG security group. Click Next: Configure Security Settings.
6. We are creating a basic load balancer, so you can click Next: Configure Health Check to continue
to the next step.
7. On the Configure Health Check page, do the following:
8. Click Next: Add Tags to skip the Add Instances to Load Balancer page. We'll use Auto Scaling
to add our EC2 instances to the load balancer.
9. Click Review and Create to skip adding tags.
10. Review your settings and then click Create. After the load balancer is created, click Close.
11. In the navigation pane, click Launch Configurations. If you are new to Auto Scaling, you see a
welcome page; click Create Auto Scaling group.
12. Click Create a new launch configuration, and then click Next Step.
13. On the Choose AMI page, select the My AMIs tab, and then select the AMI that you created in
Create a Custom AMI (p. 24).
14. On the Choose Instance Type page, select the General purpose tab, select the t2.micro instance
type, and then click Next: Configure details.
15. On the Configure details page, do the following:
a. Under Create Launch Configuration, enter a name for your launch configuration (for example,
my-lc) and select your IAM role from IAM role.
b. Expand Advanced Details.
c. In User data, select As text and then enter the following script.
#!/bin/bash
yum update -y
service httpd start
chkconfig httpd on
26
Getting Started with AWS Hosting a Web App
Test Your Load Balancer
16. On the Review page, click Edit security groups. Click Select an existing security group, select
the WebServerSG security group that you created, and then click Review.
17. On the Review page, click Create launch configuration.
18. In the Select an existing key pair or create a new key pair dialog box, select Choose an existing
key pair, then select the key pair you created in Setting Up to Host a Web App on AWS (p. 4). Click
the acknowledgment check box, and then click Create launch configuration.
19. On the Configure Auto Scaling group details page, do the following:
a. Enter a name for the Auto Scaling group. For example, my-asg.
b. In Group size, type 2 in the text box.
c. Select your VPC from the Network list and your two public subnets from the Subnet list. This
is a best practice for building fault-tolerant apps. If one Availability Zone experiences an outage,
traffic will be routed to the other Availability Zone.
d. Expand Advanced Details. Select Receive traffic from Elastic Load Balancer(s). Select your
load balancer from the text field.
e. Click Next: Configure scaling policies.
27
Getting Started with AWS Hosting a Web App
Test Your Load Balancer
Initially, your instances are in the Pending state. When their states are InService, they are ready for
use.
Next, verify that your instances are registered with the load balancer. From the Load Balancers page,
select your load balancer, and then select the Instances tab.
If the state of your instances is OutOfService, it's possible that they are still registering. When their
states are InService, they are ready for use. After your instances are ready, you can test your load
balancer as follows.
my-lb-xxxxxxxxxx.us-east-1.elb.amazonaws.com
3. In a web browser, paste the DNS name for the load balancer into the address bar and press Enter.
You'll see your website displayed.
28
Getting Started with AWS Hosting a Web App
Register a Domain Name
The easiest way for your customers to access your website is through a memorable domain name. In
the procedures on this page, replace "example.com" with your domain name.
Amazon Route 53 is a highly available and scalable Domain Name System (DNS) web service. It is
designed as an extremely reliable and cost-effective way to route visitors to websites by translating domain
names (such as www.example.com) into the numeric IP addresses (such as 192.0.2.1) that computers
use to connect to each other. With Amazon Route 53, you pay only for the domains you configure and
the number of queries that the service answers. For more information, see Amazon Route 53.
To associate a domain name with your website, use Amazon Route 53 to complete the following tasks.
Tasks
• Register a Domain Name (p. 29)
• Create a Hosted Zone for Your Domain (p. 30)
• Create Resource Record Sets for Your Domain and Subdomain (p. 30)
• Set Up a DNS Provider (p. 30)
• To use Amazon Route 53 to register a domain name, see Registering Domain Names Using Amazon
Route 53 in the Amazon Route 53 Developer Guide.
• For a list of accredited registrars, see the Accredited Registrar Directory.
29
Getting Started with AWS Hosting a Web App
Create a Hosted Zone for Your Domain
1. On the Hosted Zones page, select the hosted zone that you created for your domain.
2. Click Go to Record Sets.
3. Click Create Record Set.
4. Under Create Record Set, do the following:
Alternatively, if you're reusing a domain name that was previously associated with another website, you
might need to transfer other DNS records from your current DNS provider to Amazon Route 53 in order
to ensure the continued availability of the services hosted under the domain name. To determine which
DNS records you must replicate in Amazon Route 53, check the DNS record settings configured for the
domain in your current DNS provider. Two records that you should not transfer to Amazon Route 53 are
the Start of Authority (SOA) and Name Server (NS) records. These records were set by Amazon Route 53
when the name servers were allocated, and they should not be changed.
30
Getting Started with AWS Hosting a Web App
Set Up a DNS Provider
First, log into the domain name registrar that you used to register your domain name. Use the web interface
provided by the registrar to set the name servers for your domain to the name server values displayed
under Name Servers in the details for the hosted zone. How you do this depends on the registrar that
you used.
Wait between two to 48 hours for the Internet DNS resolver network to propagate name server changes.
To see if the name server change has gone through, use a command line utility such as dig (for Mac OS
X, Unix, or Linux) or nslookup (for Windows). The following example shows how use dig to see which
name servers are associated with your domain.
dig example.com
When the AUTHORITY SECTION of the output shows the AWS name servers that you allocated using
Amazon Route 53, the DNS changes have propagated through the DNS resolver network.
;; AUTHORITY SECTION:
example.com. 118928 IN NS ns-806.awsdns-36.net.
example.com. 118928 IN NS ns-1456.awsdns-54.org.
example.com. 118928 IN NS ns-1713.awsdns-22.co.uk.
example.com. 118928 IN NS ns-105.awsdns-13.com.
After your DNS changes have propagated, you'll be able to view your website using your custom domain
name.
If you open your www subdomain (such as www.example.com) in your web browser, it redirects to your
domain (such as example.com).
31
Getting Started with AWS Hosting a Web App
Delete the Amazon Route 53 Hosted Zone
Step 6: Clean Up
After completing this tutorial, be sure to delete the AWS resources that you created so that you no longer
accrue charges.
Tasks
• Delete the Amazon Route 53 Hosted Zone (p. 32)
• Delete the Auto Scaling Group (p. 33)
• Delete the Load Balancer (p. 33)
• Delete Your Custom AMI (p. 33)
• Terminate the DB Instance (p. 34)
32
Getting Started with AWS Hosting a Web App
Delete the Auto Scaling Group
33
Getting Started with AWS Hosting a Web App
Terminate the DB Instance
4. Select the AMI, click Actions, and then click Deregister. When prompted for confirmation, click
Continue.
5. In the navigation pane, click Snapshots.
6. Select the snapshot, click Actions, and then click Delete. When prompted for confirmation, click
Yes, Delete.
If this were a production database, we would recommend that you create a final snapshot so that
you could restore the DB instance later if needed.
34
Getting Started with AWS Hosting a Web App
Related Resources
The following table lists some of the AWS resources that you'll find useful as you work with AWS.
Resource Description
AWS Products & Services Information about the products and services that AWS offers.
AWS Documentation Official documentation for each AWS product, including ser-
vice introductions, service features, and API reference.
AWS Support Center The hub for creating and managing your AWS Support cases.
Also includes links to other helpful resources, such as forums,
technical FAQs, service health status, and AWS Trusted Ad-
visor.
AWS Support The home page for AWS Support, a one-on-one, fast-re-
sponse support channel to help you build and run applications
in the cloud.
AWS Architecture Center Provides the necessary guidance and best practices to build
highly scalable and reliable applications in the AWS cloud.
These resources help you understand the AWS platform, its
services and features. They also provide architectural guid-
ance for design and implementation of systems that run on
the AWS infrastructure.
AWS Security Center Provides information about security features and resources.
AWS Economics Center Provides access to information, tools, and resources to com-
pare the costs of Amazon Web Services with IT infrastructure
alternatives.
AWS Technical Whitepapers Provides technical whitepapers that cover topics such as ar-
chitecture, security, and economics. These whitepapers have
been written by the Amazon team, customers, and solution
providers.
35
Getting Started with AWS Hosting a Web App
Resource Description
AWS Blogs Provides blog posts that cover new services and updates to
existing services.
AWS Podcast Provides podcasts that cover new services, existing services,
and tips.
36