In this guide, you will create an Amazon EC2 Windows Instance. The learning in this guide corresponds to the AWS Associate Exam Blueprint section 2.1.
Access the AWS Console
- Go to https://aws.amazon.com
- On the Sign In screen, enter your E-mail or mobile number, and password. Then click Sign in using our secure server.
- When your login completes, you should see the AWS Console.
Select an AWS Region
- Select the AWS Region where you want to create your VM instance.
Launch a Windows Instance
- Select Services→EC2.
- On the EC2 Dashboard, click Launch Instance.
- On Step 1: Choose an Amazon Machine Image, click Select next to the Microsoft Windows Server 2012 Base AMI.
- On Step 2: Choose an Instance Type set, select t2.micro (Free tier eligible) and click Next: Configure Instance Details.
- On Step 3: Configure Instance Details, expand the Advanced details section.
- In User data, verify that As text is selected.
- Copy and paste the following text into the User data text box. The User data will execute as a script on the instance the first time that it starts. In this case, we will be installing a web server (httpd), configuring it to start at boot, and starting it.
- Click Next: Add Storage.
- By default, Step 4: Add Storage shows the volume required to boot the instance. You can optionally add addition volumes on this screen. Click Next: Tag Instance.
- On Step 5: Tag Instance, you can optionally add metadata to the Instance. Enter a Name for your instance and click Next: Configure Security Group.
- On Step 6: Configure Security Group, you can configure the firewall that filters network access to the instance. Since we want to run the HTTP service, we need to add the port that this service uses (port 80) to the security group.
- Confirm that Assign a security group is selected.
- Optionally, set a custom Security group name.
- Optionally, set a custom Description.
- Click Add Rule and set the Type to HTTP.
- Click Review and Launch.
- On Step 7: Review Instance Launch, you may see a security warning that your instance is open to the world. This is because we didn’t restrict the source IP range on the RDP rule. If this were a production instance instead of a training instance, the source range for RDP should be restricted. Review the details and click Launch.
- In the Key Pair Dialog Box, choose Select an existing key pair and check the acknowledgement box. If you no longer have access to this key pair, create a new key pair and download the new key pair.
- Click Launch Instances.
- From the Launch Status page, you View the launch log, Create Billing alerts and access other helpful resources. Billing alerts are useful to warn that you have exceeded the free usage tier. Click View Instances.
<powershell> install-windowsfeature web-server -IncludeAllSubFeature install-windowsfeature web-mgmt-tools </powershell>
Retrieve Public DNS Name
- From the EC2:Instances:Instances screen, select your instance. Copy the Public DNS name.
OSX/Linux: Connect using RDP
- Click Connect.
- Save the RDP file
- Click Get Password
- On the Get Password screen, for Key Pair path, click Choose File.
- Select the Key Pair that was used to create this instance.
- Click Decrypt Password.
- Copy the Password to the clipboard.
- Open the RDP file that you saved earlier.
- While connecting, the Remote Desktop Client will ask for credentials. Confirm that User name is Administrator, paste the password that you copied earlier, and click OK.
- Click Connect to ignore the certificate warning.
- Your Windows Remote Desktop connection should look similar to the following:
- Open Server Manager.
- Confirm that IIS is installed.
- If you don’t see the expected results, you can troubleshoot the commands that you provided in User data by inspecting the
C:\Program Files\Amazon\Ec2ConfigService\Logs\Ec2ConfigLog.txtfile. If you made mistakes in the User data, you can either launch a new instance with corrected user data, or just repair the current instance by running the commands again.
- Enter the Public-DNS-Name of your instance in your browser. Confirm that the IIS test page loads.
On the Connect To Your Instance screen, click Download Remote Desktop File.
For the most part, you can manage an EC2 instance as you would any other Linux host. For example, you can install additional applications.
- Run the following commands to install …
Access EC2 Metadata
You can access information about a running instance from inside the instance. For more information on this topic, refer to http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html
- Open Powershell
- Run the following commands to retrieve the instance ID, local hostname, local IP, public hostname, and public IP.
Note that Amazon instances have separate internal and external IP addresses. Instances also have separate internal and external hostnames. When connecting to instances from the Internet, be sure you are using the external hostname and IP address.
Access EC2 Metadata via the Web Page
You may find it more useful to access the EC2 Metadata via a web page running on the instance. I add a page like this to all of my web servers. It’s invaluable in setting up and diagnosing load balanced web servers — we will do this in a later guide.
- Use your favorite text editor to create a new web page at
C:\inetpub\wwwroot\default.aspthat contains the following. This new ASP page will override the IIS Test Page.
- Set permissions on C:\inetpub\wwwroot\default.asp to grant the user IUSR both Read & Execute and Read permissions.
- Reload the Public-DNS-Name of your instance in your browser.
<html> <body> <% url = "http://169.254.169.254/latest/meta-data/" set XmlObj = Server.CreateObject("Microsoft.XMLHTTP") XmlObj.open "POST", url & "instance-id", false XmlObj.send instance_id = XmlObj.responseText XmlObj.open "POST", url & "local-hostname", false XmlObj.send local_hostname = XmlObj.responseText XmlObj.open "POST", url & "local-ipv4", false XmlObj.send local_ipv4 = XmlObj.responseText XmlObj.open "POST", url & "public-hostname", false XmlObj.send public_hostname = XmlObj.responseText XmlObj.open "POST", url & "public-ipv4", false XmlObj.send public_ipv4 = XmlObj.responseText Response.write("<b>instance-id:</b> " & instance_id & "<br>") Response.write("<b>local-hostname:</b> " & local_hostname & "<br>") Response.write("<b>local-ipv4:</b> " & local_ipv4 & "<br>") Response.write("<b>public-hostname:</b> " & public_hostname & "<br>") Response.write("<b>public-ipv4:</b> " & public_ipv4 & "<br>") %> </body> </html>
Congratulations! You have successfully created an Amazon EC2 Windows instance. You may find the following additional resources helpful:
- Launch a Windows Virtual Machine
- Getting Started with Amazon EC2 Windows Instances
- Running Commands on Your Windows Instance at Launch
- Instance Metadata and User Data
Continue to the next lab guide: