In the previous post previous post we completed our cloud based viewer by adding Amazon Web Services functionalities, so our data could be hosted and retrieved from the cloud, although our custom web service was still running locally. Today we are going to deploy that same web service on a cloud machine, so it will become a real cloud hosted service accessible from any desktop computer connected to the Internet.
For deploying our service on the cloud, we will continue our investigation of the services provided by the Amazon platform, focusing for that on EC2, the Elastic Cloud Computing service. You will be able to find a lot more information about this service, pricing and so on here: http://aws.amazon.com/ec2/
I’m going to present you how to create and configure a basic virtual machine instance running on EC2 and to deploy our viewer service on it. The whole process should take you about 15 to 20 minutes, including at least 10 minutes waiting for the virtual machine to be created, so that’s 5 minutes of effective work! Don’t mention that to your boss;)
I – Creating an EC2 instance
You first need to sign up for Amazon EC2 which is free, but the actual use of a cloud machine and the storage is not. Once you’ve signed up, go to EC2 and the first thing to determine is where your cloud machine will be based. Although it will be accessible from anywhere on the web, you might want to choose a geo location that makes sense depending on where your users are likely to be located in order to reduce latency time. Once the machine is launched from a specific region, it won’t be possible to move it across another geo, so you don’t want to mess this one up…
I select US East (Virginia) for my example:
Then click the Launch Instance button:
You will be proposed in preconfigured set of virtual machines running either Windows, Linux, Unix, … OS’s.
Our web service is implemented in WCF, so we need a Windows OS. I select the Windows Server 2008 with SQL Express and IIS already installed. The only thing you will need to install on that virtual machine once it’s up and running is the Web Deploy for IIS like we did in the first post.
You can keep going by accepting a couple of default options. Create a new key (alternatively use an existing one for subsequent machines you will create) that will be used to retrieve the generated password of the virtual machine.
The next step is to create a Security Group that will define which ports will be open to the external web. Keep in mind that those settings will be completely independent of the firewall settings defined inside your virtual OS, so depending on which ports you want to have open, you will also need to configure the OS firewall separately.
I want my service to run on HTTP port 80 for a start, so I’m adding a predefined HTTP rule to allow any IP (that’s why my source equals 0.0.0.0/0) to connect through that port. It won’t be possible to affect a different security group once the instance is running, however you can modify an existing one at any time, just keep that in mind:
Let’s click continue when you are done configuring rules and you will land to the final dialog that recaps your new virtual machine settings. Click “Launch” and allow 10 to 15 minutes for the virtual machine to be ready:
When the machine is ready to be connected, you should see something like the following (in that case we have other machines running, but just focus on Leefsmp1):
A final step will be to assign what they call an Elastic IP address to our machine, it is the IP that will be visible from the outside world wide web. So go to Elatic IPs in the left menu of the AWS management console and click “Allocate New Address”:
You then need to associate the EIP to your instance:
And done! You now need to connect through Remote Desktop to your running instance, click “Connect” from the right-click menu option display from your instances list, you should be able to retrieve the default password using the key file you generated in previous step:
All the actions described above have been performed from the AWS management console, but I wanted to mention that Amazon also provides a nice little plug-in that integrates inside Visual Studio and that allows you to do pretty much the same (with some limitations though comparing with the online console).
At least once your machine is up and running, it is very convenient to use it to Remote Desktop into your instance, it can also remember your credentials:
II- Deploying our web service to the cloud instance
This step will be 100% identical to the local machine deployment in IIS I detailed in the previous post, so I won’t expand on that again. You can just copy the generated WCF service package compiled on your development machine to the remote instance and deploy it using IIS.
The only thing I needed to copy separately was the AWSSDK.dll and place it in the same folder than my WCF Service dll. If you know how to let Visual Studio automatically include that dependency in the package, feel free to let me know…
You will need to update your console and client app config files with the relevant IP of the cloud instance, here is how my endpoints declaration look like:
Compile, run and boom! You can see there my client and console apps connected to my cloud service. The changes to the source are so minimalistic here that I won’t provide an attachment, you can just refer to the project I provided in the previous post.
You can follow this conversation by subscribing to the comment feed for this post.