Using SmartClient and Smart GWT with Amazon Web Services

Setting up one-click deployment to Amazon Elastic Beanstalk

Setting up a one-click Amazon Elastic Beanstalk environment is faster and simpler than setting up a custom Linux EC2 environment (see below), and automatically provides you with capacity provisioning, load balancing, auto-scaling, and application health monitoring.

Step 1

Set up an account:

A few things that the Amazon Getting Started Guide leaves out include:

  • You must sign up for EC2 and Beanstalk specifically. This isn’t a standard part of signing up for an Amazon Web Services (AWS) account. Logging into the AWS console and selecting the EC2 tab and Beanstalk tab will provide links to the sign-up pages.
  • You must provide a payment method the first time you sign up for a service.
  • You must provide a phone number, receive a phone call, and enter the PIN provided in the console into the phone to finalize the subscription to your first service.
  • There may be a short delay between finalizing your subscription and it being ready for use. Amazon sends an email when the account is available.

Step 2

Set up Eclipse JEE version for local testing. To test on your local machine as you develop your application using Jetty:

  1. Create or import a project.
  2. Select the project in the Project Explorer.
  3. Click Run > Run As > Run on Server.
  4. Select Basic > J2EE Preview.
  5. Click Finish.

Step 3

Set up Eclipse JEE version for one-click EC2 deployment. To upload and deploy your application on EC2:

  1. Install the AWS EC2 Eclipse plug-in: http://aws.amazon.com/eclipse/#4
  2. If you have not already, register your AWS account for AWS Elastic Beanstalk (see http://aws.amazon.com/elasticbeanstalk/#pricing for how using beanstalk will affect your costs)
  3. Define a new AWS Elastic Beanstalk web application (see the “Hello World” section in http://blog.teamextension.com/getting-started-with-aws-elastic-beanstalk-179)

Note: Stopping an EC2 instance created by Elastic Beanstalk will cause a new EC2 instance to be started; you must stop the Beanstalk application from the Servers tab.

The EC2 environment has built-in monitoring capabilities that you can leverage to determine loads on your environment. These are helpful for capacity planning, so that you can expand and contract your resources to balance between cost and application responsiveness. 

Setting up a custom Linux EC2 environment

Setting up a custom Linux EC2 environment requires a bit more work than setting up a one-click Amazon Elastic Beanstalk environment (see above), but affords you more control over the environment.

Step 1

If you haven't already, set up an account: http://docs.amazonwebservices.com/AWSEC2/latest/GettingStartedGuide. See the comments above about what the Amazon Getting Started Guide leaves out.

Step 2

Launch the Bitnami Tomcat stack AMI

This AMI provides an already-installed and -configured Apache web server, Tomcat servlet container, MySQL database server, and Java JDK. To launch the Bitnami Tomcat stack AMI, point your browser to one of these URIs:

Provide the details in the AMI launch wizard. For information on what these options mean, see the documentation at http://docs.amazonwebservices.com/AWSEC2/2010-11-15/GettingStartedGuide/index.html?LaunchInstance.html. Make sure to open port 22 (SSH) on your server.

Step 3

Connect to the instance:

  1. In the EC2 tab in the AMI console, click the Instances link in the menu on the left.
  2. Right-click the Ubuntu AMI and choose Connect from the pop-up menu.
  3. Follow the instructions that appear for making an SSH connection to the server. Note: If you are using PuTTY to connect, see http://clouddb.info/2009/05/17/a-quick-overview-of-putty-and-ssh-for-aws-newbies for instructions on generating a PPK file from the PEM file you downloaded earlier.
  4. Once you have established an SSH connection, use the username “bitnami” to log in.

Step 4

Customizing your instance:

  1. Immediately remove the entry for “manager” in the tomcat-users.xml file and replace it with your own credentials:

    sudo vi /opt/bitnami/apache-tomcat/conf/tomcat-users.xml
    
  2. You can connect to the Tomcat server on your instance using the AMI’s public DNS (ec2-#########-###-compute-1.amazonaws.com). You can use this interface to load WAR files for deployment, or you can use other SSH tools to upload the necessary files directly.
  3. Create the database in your MySQL server for your application:

    sudo /opt/bitnami/mysql/bin/mysql -u root
    mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword');
    mysql> CREATE DATABASE yourdatabase;
    mysql> CREATE USER 'username'@'localhost' IDENTIFIED BY 'yourpassword';
    mysql> GRANT ALL ON yourdatabase.* TO 'username'@'localhost';
    

Note: Avoid using “bitnami” for database names and users. Customize the above settings to match your application’s needs. At the least, update root’s password so that it is not left to the default specified by the Bitnami stack.

Step 5

Deploy an application to the server.

  1. Set your application’s database configuration to: username: “username” / password: “yourpassword” / URL “jdbc:mysql://localhost:3306/yourdatabase
  2. Download SmartClient or Smart GWT---http://www.smartclient.com/product/download.jsp
  3. Extract the content of the download into your project. See http://www.smartclient.com/docs/8.0/docs/SmartClient_Quick_Start_Guide.pdf or  http://www.smartclient.com/releases/SmartGWT_Quick_Start_Guide.pdf for more information on this process.
  4. Generate a WAR file of your application. Note that you can slim down your WAR file by removing the skins your application doesn’t use. (The 13 skins provided with the full version of SmartClient, combined, add up to over 56MB.)
  5. Point your web browser to the public DNS for your server (ec2_############-_compute-1.amazonaws.com).
  6. Click Access my Application and then Tomcat Manager.
  7. Log in with the credentials you created earlier and use the WAR file to deploy section to upload and deploy your application.If you'd prefer to use SFTP to upload your WAR, upload it to /opt/bitnami/apache-tomcat/webapps.

Note: Naming the WAR file that you upload to your instance ROOT.war (case-sensitive) will replace the default Bitnami application with your application at your instance's public DNS.