Karmona's Pragmatic Blog

Don't get overconfident… Tiny minds also think alike

Karmona's Pragmatic Blog

Run “Hello World!!!1” Servlet on EC2 using AWS Toolkit for Eclipse

September 15th, 2010 by Moti Karmona | מוטי קרמונה · 12 Comments

It started like yetanother-weekend-experiment but once you start a weekend experiment you never know when or how it will end… ;)

I was very curios to take AWS for a quick test drive so I lost six hours of a precious beauty sleep and compiled this blog-post-capsule for future generations.

 

 

The Quest

* Run an “Hello World!!!1” Servlet on EC2 (less than $0.01 per hour)
Create a local development environment using EclipseAWS Toolkit for Eclipse (seems like a really interesting toolchain)

Preliminary Steps

Issues with AWS Toolkit defaults

The plan was to use this tutorial but surprisingly enough this did not work out-of-the-box (apparently due to Tomcat/JDK versions on the default AMI the plug-in is using but I didn’t waste time in making sure this is the issue) so I moved to plan B

 

Plan B – Create a custom EC2 AMI with Tomcat 6.something and JDK 1.6

* Launch an EC2 instance using Amazon’s ami-84db39ed AMI.  (basic Fedora 8 image)
* Use Putty connect to your instance

 

* Install Java on EC2 Instance

Download JDK (“Linux RPM in self-extracting JDK file”)

mkdir /usr/local/java
cd /usr/local/java
curl http://download.java.net/jdk6/6u23/promoted/b01/binaries/jdk-6u23-ea-bin-b01-linux-i586-30_aug_2010-rpm.bin > jdk1.6.0.23-rpm.bin
* Install the JDK
chmod 755 jdk1.6.0.23-rpm.bin # Change the permission of the file
./jdk1.6.0.23-rpm.bin #Install
updatedb; locate javac | grep bin  # this step merely serves to verify the installation
/usr/sbin/alternatives –install /usr/bin/java java /usr/java/jdk1.6.0_23/bin/java 100
/usr/sbin/alternatives –install /usr/bin/jar jar /usr/java/jdk1.6.0_23/bin/jar 100
/usr/sbin/alternatives –install /usr/bin/javac javac /usr/java/jdk1.6.0_23/bin/javac 100
/usr/sbin/alternatives –config java # Change the default JVM from gcj to Sun’s version (if needed)

* Install Tomcat on EC2 Instance

* Download Tomcat 6.0
mkdir /usr/tomcat
cd /usr/tomcat
curl http://apache.spd.co.il//tomcat/tomcat-6/v6.0.29/bin/apache-tomcat-6.0.29.tar.gz > apache-tomcat-6.0.29.tar.gz
tar zxvf apache-tomcat-6.0.29.tar.gz
* Start Tomcat and to verify the installation, load the root page from a web browser: http://your_instance_name:8080
cd apache-tomcat-6.0.29
bin/startup.sh  # Start Tomcat
* Configure Tomcat to launch automatically – Create a file “/etc/rc.d/init.d/tomcat” with the following content:
#!/bin/sh
# Tomcat init script for Linux.
#
# chkconfig: 2345 96 14
# description: The Apache Tomcat servlet/JSP container.
JAVA_HOME=/usr/java/jdk1.6.0_23
CATALINA_HOME=/usr/tomcat/apache-tomcat-6.0.29
export JAVA_HOME CATALINA_HOME
exec $CATALINA_HOME/bin/catalina.sh $*
* Set the proper permissions for your init script and enable Tomcat for auto-launch:
chmod 755 /etc/rc.d/init.d/tomcat
chkconfig –level 2345 tomcat on
* Tomcat should now be automatically launched whenever your server restarts.

 

Are we there yet?

It could be but apparently the plug-in was poorly designed to use none-configurable command lines so I needed to add the following “tricks”:
* Set JAVA_HOME / PATH for your user – Login to your account and change your .bash_profile file
vi ~/.bash_profile
export JAVA_HOME=/usr/java/jdk1.6.0_23
export CATALINA_HOME=/usr/tomcat/apache-tomcat-6.0.29
* Create aliases to your Tomcat and JDK installation (these location are hard-coded in the plug-in)
ln -s /usr/java/jdk1.6.0_23/ /env/jdk
ln -s /usr/tomcat/apache-tomcat-6.0.29/ /env/tomcat
The EC2 instance is ready :)

 

What next?

* Create EBS Image AMI from your instance (it does takes couple of minutes to complete)
* Open your eclipse and start a new AWS project as described in the original link
* Define a new EC2 Server in Eclipse using your new AMI (reminder: the default didn’t work)
* Create your “Hello World!!!1” Servlet
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.getWriter().println(“Hello World!!!1”);
}
* Click Run… this will automatically deploy your Servlet and run it on the remote EC2 instance… Wow :)

 

That’s it – I hope this will help, it does take approx. 1 hour so if you know some other way to make it work, please don’t be shy and comment.

Additional references I used to make it this far:

* Amazon EC2 – Getting Started Guide

 

Free VI Tip for Dummies

80% of knowing VI is just: ESC ESC ESC, i, Type-Your-Stuff, ESC ESC ESC, :wq!

 

 

→ 12 CommentsTags: Cloud · Development · Simplicity · Tools

Just upgraded to WordPress 2.9 – Carmen

December 22nd, 2009 by Moti Karmona | מוטי קרמונה · No Comments

I have just upgraded to WordPress 2.9 – Carmen (named in honor of the jazz vocalist Carmen McRae) in less than 3 minutes…

WordPress 2.9 Highlights

* Global undo/”trash” feature
* Built-in image editor
* Batch plugin update and compatibility checking
* Easier video embeds
* Over 500 tickets, bugs and enhancements

→ No CommentsTags: Blogging · Simplicity · Tools · WordPress

Just upgraded to WordPress 2.8 – Baker

June 14th, 2009 by Moti Karmona | מוטי קרמונה · 1 Comment

Chet BakerI have just upgraded to WordPress 2.8 in less than 3 minutes…

WordPress 2.8 Highlights

* Speed!!!
* Theme Browser and Installer
* Ability to add Custom Headers
* New drag-and-drop widgets admin interface and new Widgets API
* New ways to customize dashboard widgets
* Syntax highlighting and function lookup built into plugin and theme editors
* Configurable Views on Management Pages
* Faster Loading Admin Pages

→ 1 CommentTags: Blogging · Simplicity · Tools · WordPress

Backup your Life with Amazon S3

February 1st, 2009 by Moti Karmona | מוטי קרמונה · 10 Comments

Head in the CloudsS3 (Simple Storage Device ) Overview

“Amazon S3 provides a simple web services interface that can be used to store and retrieve any amount of data, at any time, from anywhere on the web. It gives any developer access to the same highly scalable, reliable, fast, inexpensive data storage infrastructure that Amazon uses to run its own global network of web sites. The service aims to maximize benefits of scale and to pass those benefits on to developers.” (http://aws.amazon.com/s3/)

What can I do with this S3 thingy?

Many things… but I will focus on a pragmatic and more common use case – You can use S3 as the ultimate network drive to share your music collection, backup your documents or to store your blog images (a.k.a. CDN for the masses) etc.

Is it free???

Almost…   $0.15 per Giga (+ you can estimate your monthly bill using the AWS Monthly Calculator)

Amazon S3 Pricing

How do I start?

To use Amazon S3 service, you’ll simply need to open an Amazon account and register to the S3.

Interesting tools to simplify your S3 experience:

  • Amazon S3 Firefox Organizer – Simple Firefox add-on that provides an FTP like interface (Windows Explorer) to upload and manage files on S3 – “S3Fox Organizer helps you organize/manage/store your files on Amazon S3. It is easy to install and use as it is integrated into the browser…”
  • DropBox – New Amazon-S3-backed-storage service (thanks to Shlomo for the introduction) – Very simple to use and with 2GB storage limit on the default (free) account and paid upgrade to 50GB of space for $9.99 / month which is not that much above the $7.5 they need to pay to Amazon (before optimizations ;)

P.S. If you liked DropBox you might also like many others

→ 10 CommentsTags: Disruptive Technology · Simplicity · Tools

Vista Services Corruption Saga

December 12th, 2008 by Moti Karmona | מוטי קרמונה · 2 Comments

PlaceboWarning: This post could be an interesting reading material only if you have windows system-files corruptions and as a real alternative to the expert exchange conspiracy ;)

This small vista saga started when I found myself unable to access domain assets (exchange, domain servers, shared storage etc.)

Browsing quickly throughout Event Viewer System logs I found out that Workstation, Netlogon and Computer Browser services were down due to rather long and frustrating service dependencies failures:

  • The Netlogon service depends on the Workstation service which failed to start because of the following error: The dependency service or group failed to start. (Event ID 7001)
  • The Computer Browser service depends on the Workstation service which failed to start because of the following error: The dependency service or group failed to start. (Event ID 7001)
  • The Workstation service depends on the SMB 2.0 MiniRedirector service which failed to start because of the following error: The dependency service or group failed to start. (Event ID 7001)
  • The SMB 2.0 MiniRedirector service depends on the SMB MiniRedirector Wrapper and Engine service which failed to start because of the following error: The dependency service or group failed to start. (Event ID 7001)
  • The SMB 1.x MiniRedirector service depends on the SMB MiniRedirector Wrapper and Engine service which failed to start because of the following error: The dependency service or group failed to start. (Event ID 7001)
  • The SMB MiniRedirector Wrapper and Engine service depends on the Redirected Buffering Sub Sysytem service which failed to start because of the following error: SMB MiniRedirector Wrapper and Engine is not a valid Win32 application. (Event ID 7001)
  • The Redirected Buffering Sub Sysytem service failed to start due to the following error:  Redirected Buffering Sub Sysytem is not a valid Win32 application. (Event ID 7000)
  • The following boot-start or system-start driver(s) failed to load: CSC rdbss  (Event ID 7026)

As a real IT expert, I tried 5 restarts before trying anything else ;)

So… to resolve this unfortunate issue, I had to use the notorious System File Checker tool (SFC.exe) .

This poorly documented windows  utility will scan all protected system files and replaces incorrect (corrupted, changed or missing) versions with correct Microsoft versions and running this from the command prompt is much easier than booting off the DVD into repair mode.

Once you have an administrator command prompt open (click Start, click All Programs, click Accessories, right-click Command Prompt, and then click Run as administrator), you can run the utility by using the following syntax:

SFC [/SCANNOW] [/VERIFYONLY] [/SCANFILE=<file>] [/VERIFYFILE=<file>]

[/OFFWINDIR=<offline windows directory> /OFFBOOTDIR=<offline boot directory>]

The most useful command is just to scan immediately, which will scan and attempt to repair any files that are changed or corrupted using this command:

sfc /scannow

The scanning replaced the corrupted system file rdbss.sys and I was back to domain browsing business right after :)

Note: If SFC shouts he can’t repair the corrupted files, than you will have to drill down to the CBS.log to find what is corrupted and replace it yourself

 

 

____________________________

By the way, Marissa Mayer promised that Chrome Browser will be leaving Beta (while GMail is still in Beta…) and it just did yesterday and that Google Search Wiki would soon have a toggle button that allow people to turn it off (“early Q1.”) – I can’t wait… :)

→ 2 CommentsTags: Conspiracy · Tools