|
By Brian Desmond, Microsoft MVP
Deploying Microsoft ASP.NET applications on Amazon Elastic Compute Cloud (Amazon EC2) instances running Windows is almost identical to working with a normal dedicated server or shared hosting. Rather than running on physical hardware, however, your Amazon EC2 instances are virtual machines (VMs) running on hardware in Amazon's data centers. The bulk of the work required for deploying applications to Amazon EC2 instances is around the configuration of the instance and the storage. This tutorial provides the steps necessary to configure your workstation, deploy an Amazon EC2 instance, install and configure an ASP.NET application (FlexWiki), and make the Amazon EC2 instance accessible over the Internet.
Getting Started with Amazon EC2
You must be familiar with several terms before diving into Amazon EC2. The first is the concept of an instance. Instances are the individual VMs you are running on Amazon's network. Instances are based off Amazon Machine Images (AMIs). AMIs are templates preconfigured with an operating system and other components. In this case, you'll be working with the preconfigured AMIs running Windows Server 2008 R2. You can create custom AMIs based on those Amazon provides.
One of the important concepts to remember is that by default, the storage associated with your instances is volatile. Although the contents will survive a reboot, they will not survive if the instance is terminated or if a hardware failure or other issues occur. To present persistent storage to your instances, you must present a volume that is stored in the Amazon Elastic Block Store (EBS). EBS volumes are persistent and can be detached and attached to different instances. EBS volumes show up like a normal hard drive inside Windows.
You can perform all the management tasks necessary for provisioning VMs to run Windows through the Amazon Web Services (AWS) Management Console. You can also use the Amazon EC2 command-line tools; however, the AWS Management Console is much more user friendly.
Deploying an Amazon EC2 Instance
In the EC2 Dashboard section of the console, click Launch Instances. Select the Basic Windows Server 2008 AMI, and then complete the steps of the wizard. The administrator passwords for the Amazon EC2 instances to be created are protected by an encryption key, which you must generate prior to activating the instances. Be sure to save the file when you reach the key pairs step. The text file generated during this step will be required later.
Note: If you have an existing Amazon EC2 key pair, you can continue to use that key pair in lieu of creating a new one.
By default, the firewall protecting Amazon EC2 instances does not allow any traffic from the Internet; however, it permits all traffic between your Amazon EC2 instances. To configure the Amazon EC2 instances, you must permit Remote Desktop traffic to them. Additionally, permit Hypertext Transfer Protocol (HTTP) traffic to the Web server to make the content accessible to users.
Firewall rules are provisioned for security groups. When you reach the security groups step in the wizard, create a security group called web-Servers. Next, create a rule matching Figure 1 to permit Remote Desktop and HTTP.
Figure 1. Creating a Rule to Permit Remote Desktop and HTTP
Note: This rule permits Remote Desktop connections from anywhere. If you have a static IP address or subnet from which you connect, specify that in the Source column. For a specific IP address, specify a mask of /32for example, 1.2.3.4/32to permit connections only from host 1.2.3.4.
Switch to the Instances section of the management console. When the new instance is in the running state, right-click it, and then click Get Administrator Password. Paste the contents of the text file generated earlier during the key pair creation step into the Private Key text box, then click Decrypt Password to return the Windows administrator password. This password is necessary for initially logging in to the instance.
The bottom half of the page provides several key pieces of information about the VM you launched. The first is the public Domain Name System (DNS) name for the instance, such as ec2-75-101-250-82.compute-1.amazonaws.com. You use this name to access the instance from the Internet. The second DNS namesimilar to ip-10-250-58-21.ec2.internalis the internal DNS name that you use when communicating between instances. Instances have private IP addresses that are accessible from the Internet using Network Address Translation (NAT). Instances are deployed in availability zones, which are distinct locations isolated from failures in other availability zones. In this case, this instance is deployed in the us-east-1d availability zone. Finally, you can identify that the instance is in the "running" state.
After you have configured the firewall rule, you can use the Remote Desktop client to connect to the Amazon EC2 instance using its public DNS name (such as ec2-75-101-250-82.compute-1.amazonaws.com).
Note: When you permit Remote Desktop connections to the instance, you may receive a warning about the instance's certificate. It is safe to ignore this warning.
Setting Up the Elastic Block Store
Chances are, you want persistent storage to store the data your instance creates. In this tutorial, you deploy the free FlexWiki wiki package. You need a place to store the data for the wiki that is safe regardless of the state of the instance. To do this, create and attach an EBS volume to the instance.
To create an EBS volume, you need the availability zone in which you want to create the volume and the size. The availability zone must match the instance you are planning to attach the volume to (this data is available in the properties of the Amazon EC2 instance). Volumes can range from 1 gigabyte (GB) to 1 terabyte (TB) in size. To create a volume, go to the Volumes section of the AWS Management Console and click Create Volume. Complete a form similar to Figure 2.
Figure 2. Creating an EBS Volume
When the EBS volume's status shows "available," select it in the table, and then click Attach Volume on the toolbar. Select the Amazon EC2 instance you created earlier, and provide the device name /dev/sda2.
With the volume attached, you must initialize and format it using the Disk Management section of the Computer Management Microsoft Management Console (MMC) snap-in (accessible by clicking Start > Run and then typing compmgmt.msc). I've assigned the volume letter E for this tutorial.
Note: Use of the EBS will lead to additional charges on top of the base Amazon EC2 charges. You can review EBS-specific pricing information at http://aws.amazon.com/ec2.
Configuring the Application
The base AMI that Amazon provides does not include Microsoft Internet Information Services (IIS), so you need to install IIS using Server Manager. Inside Server Manager, expand Roles, and then click Add Roles. Select the Web Server (IIS) role, and then go to the Role Services wizard page. Select the ASP.NET check box, and then complete the remaining wizard pages.
When you have installed IIS, download a copy of the FlexWiki binaries from the FlexWiki site. At the time of writing, FlexWikiCore-2.1.0.274-web-full-Release.zip was the correct archive. Extract the archive to E:\FlexWiki.
Create a new application pool in IIS called FlexWikiPool. Set the application pool's Managed Pipeline Mode to Classic at the time of creation. Next, configure a new application in IIS by right-clicking the Default Web Site, and then clicking Add Application. Specify an alias of FlexWiki, and point the application to the root of E:\FlexWiki, as shown in Figure 3. Configure the application to run inside the FlexWikiPool application pool.
Figure 3. Virtual Directory Settings
Browse to http://localhost/flexwiki/default.aspx inside the instance to verify that the application is functioning correctly. You should see a page similar to Figure 4.
Figure 4. The Default FlexWiki Home Page
If you need to deploy an ASP.NET application directly from Microsoft Visual Studio, you can use the Copy Web Site Wizard available in Microsoft Visual Studio 2005 and later. The Copy Web Site Wizard allows you to deploy applications using File Transfer Protocol (FTP) or Microsoft Office FrontPage Server Extensions. To use FTP, you must install the FTP component of IIS as well as permit ports 20 and 21 through the firewall by modifying the web-servers security Group.
Configuring External Access
Before users can access your site, you must configure DNS with a friendlier URL. To provide a friendly URL, you should use a CNAME record in DNS. CNAMEs alias one DNS name to another. So, for example, you could create a CNAME flexwiki.briandesmond.com that is aliased to ec2-75-101-241-32.compute-1.amazonaws.com. Also, users could browse to http://flexwiki.briandesmond.com/flexwiki/default.aspx.
When you terminate an instance, the IP addresses associated with that instance are released. You will get new IP addresses when you create a new instance. To work around this behavior, you can leverage the Amazon EC2 Elastic IP Address service to associate permanent external IP addresses with your account.
To allocate an Elastic IP address, go to the Elastic IPs section of the AWS Management Console, and then click Allocate New Address on the toolbar. When an address has been allocated, select it, and then associate it with the Amazon EC2 instance created earlier. Set your DNS records for the FlexWiki environment to point to the Elastic IP address. For more information about Elastic IP addresses, see Feature Guide: Amazon EC2 Elastic IP Addresses.
Note: Use of Elastic IP addresses may lead to additional charges on top of the base Amazon EC2 charges. You can review Elastic IP-specific pricing information at http://aws.amazon.com/ec2.
Summary
With Amazon EC2, you can deploy ASP.NET applications on dedicated Windows instances running in Amazon's data centers. To deploy the application, you need to create an instance based on an AMI template. After creating the instance, you access the administrator password and create a Remote Desktop connection to the server. To provide persistent storage, you create an EBS volume, and then setup IIS and the ASP.NET application. You can deploy ASP.NET applications to the server with tools like Visual Studio or through FTP. Finally, you configure Elastic IP addresses and DNS entries to permit access by the public.
|