Do you ever wanted to get started with BlazeDS? A bug bit me yesterday that forced me to sit at my computer for hours on end until I could achieve two things: setting up Amazon’s EC2 Webservice and getting up and running with BlazeDS.
I had to do quite a bit of hunting due to my inexperience with a few things, which led me to the conclusion that someone else out there might want to benefit from my Googling and bookmarking.
Anyone who is on a Mac should be able to follow along fairly easily, and if you’re on Windows, it shouldn’t be too bad to translate.
Setting up EC2
Shared hosting is soon become something of yesteryear. With resources like Amazon’s Web Services, you can set up and have complete control over your own virtual web server with a very reasonable (and sensible) pricing system. It’s ultra-scalable. You only pay for the storage, transfer, and server instances that you use. Little use = little money, yet if you find yourself having to scale for whatever reason, Amazon doesn’t require you to do anything. You just get the bill for the extra usage that month. Perfect for someone like me.
Step 1: Sign up for EC2
This one’s pretty easy, and I won’t go into too much detail unless you have great difficulties filling out forms and registering credit card information.
The important part of this is that you’ll get two things that are vital for your EC2 setup: a X509 certificate and a private key file. You can access these through the “View Access Key Identifiers” link under “Your Web Services Account.” Your files should look something like this:
pk-HKZYKTAIG2ECMXYIBH3HXV4ZBZQ55CLO.pemOn to the next step.
Step 2: Set up command line tools
For this step, you’ll need to start Terminal and have downloaded the command line tools from Amazon. The command line tools are simply some java classes that need to be unzipped to the location of your choice. I unzipped them to this location (.ec2) that I created: /Users/Cahlan/.ec2/
Now we’re going to set up some environment variables. This will allow your ec2 command line tools to function. There are only a few, and you input them like so:
Mine was /Users/Cahlan/.ec2 or ~/.ec2 if you’re already in the “Cahlan” folder.
This sets our private key file, and
this sets our certificate file.
And since I’m on a Mac, I also have to set the environment variable for JAVA_HOME:
Step 3: Create keypair
One last step before we get dirty. We have to create a keypair so that we can authenticate with the web service. You’ll do this with this command “ec2-add-keypair gsg-keypair” which will output the key to the terminal. I tried copying and pasting this into a text file with disastrous results. We’ll just store the output to a file, it’s a much easier way:
ec2-add-keypair gsg-keypair >> /Users/Cahlan/.ec2/keypair
Now the keypair is stored in a file called “keypair” in our .ec2 folder. We have to make sure the file is protected, or our SSH sessions won’t work. Type this command to set the right permissions for your newly-made keypair file:
chmod 600 /Users/Cahlan/.ec2/keypair
Now we’ll actually create our virtual server on EC2.
Step 4: Create Server Instance
If you’ve done everything right up until this point, you should be able to type the command
to see all of the available Amazon-supported images that you can use. If that didn’t work, you’ll need to review the previous steps to find out where you went wrong.
ec2-describe-images -o amazon
So, now we need to pick an image. I chose a Linux Fedora distro with Apache and MySQL already installed, looks like this:
To actually install this image, you’ll type a command similar to this:
ec2-run-instances ami-25b6534c -k gsg-keypair
We got that ami code from the previous “describe” command. This will start your instance up and running. You may need to wait a few moments for it to fully initialize, you can check the progress with
You’ll know it’s up and running when you see something very similar to this:
RESERVATION r-xxxxxxxx ############ default
INSTANCE i-xxxxxxxx ami-25b6534c ec2-##-##-##-##-##-##.z-2.compute-1.amazonaws.com running gsg-keypair
Sweet! Now we need to quickly enable some ports:
ec2-authorize default -p 22
for HTTP, and
ec2-authorize default -p 80
ec2-authorize default -p 8400
Test your new setup by navigating to this URL in your web browser: “ec2-##-##-##-##-##-##.z-2.compute-1.amazonaws.com” replacing of course the “#” with the correct numbers from your ec2-describe-instances statement.
We’re halfway there.
Set up BlazeDS
Step 5: Download Java JDK
Now we’ll SSH into our server with the following command:
ssh -i /Users/Cahlan/.ec2/keypair root@ec2-##-##-##-##-##-##.z-2.compute-1.amazonaws.comIf you’ve done everything right, you’ll see some ASCII art and a greeting from Amazon.
Now we need the Java JDK installed. After changing to the root directory and creating a directory called “java” (mkdir java), I executed a wget:
wget -O /java/jdk-6u5-linux-i586.bin http://22.214.171.124/ECom/EComTicketServlet/BEGIN2FCA82FFFBA7733BAEFFC22E660E1F22/(line wrapped)
You’ll need to verify with the Java website that you get the correct URL. Your URL will probably be similar, or at least as painfully long.
A couple last steps, we’ll change the permissions on the bin file and then execute it:
chmod +x /java/jdk-6u5-linux-i586.bin
You’ll need to agree to the terms displayed in the output and then java will be installed.
Before we move on, let’s set the appropriate environment vars for our BlazeDS to work.
Some helpful links for this section:
JDK Downloads Page JDK Install Instructions
Step 6: Download BlazeDS
We’re pretty close now. We need to download BlazeDS, doing something very similar to what we did for the JDK:
Go back to root, make a “blaze” directory:
We’re using the turnkey download of BlazeDS because it comes packaged with an integrated Tomcat server.
Now we just need to unzip the file:
Step 7: Startup Tomcat
Finally, we’ll start our newly unpacked Tomcat server using this command:
We should also start the sampledb for the samples app to work correctly:
Step 8: Check it Out
You can now admire and test your newly deployed BlazeDS install by going to http://your.long.url.amazon.com:8400
Not bad for implementing an entire LAMP setup along with Tomcat and BlazeDS in one sitting! See how your boss/clients react when you use all of these buzzwords in a sentence: Amazon EC2, Linux Fedora, Compute Cloud, BlazeDS, Tomcat. Kudos for whoever can make the sweetest sounding sentence with all of these. Or maybe some sweet rhyme?