Channels ▼

Deployment with Amazon's Elastic Beanstalk

First Steps

To use Elastic Beanstalk, you need to do a few things. First, you must sign up for the service. Elastic Beanstalk, like all other AWS offerings, requires an account. It isn't free, although there are free entry models available for new accounts. The good news with respect to pricing is that Elastic Beanstalk doesn't cost you anything beyond what Amazon charges for the individual underlying products. Thus, with Elastic Beanstalk, you pay only for the services you consume when you consume them. For instance, a basic, low-traffic Elastic Beanstalk stack costs roughly $35/month. This price includes EC2 resources, load balancing, S3 storage, and bandwidth.

Elastic Beanstalk is primarily built to work with Java Web applications — that is, by design, Elastic Beanstalk requires war files as the deployment artifact. Thus, in order for your Web application to work with this service, you must be able to package it as a standard war file, which is easy to do with any Java-based Web framework. In contrast to Google's App Engine, Elastic Beanstalk's Java environment is 100% standard — you can run anything on it that would otherwise run on a local JVM (this is distinctly different from GAE, which limits what Java libraries can run on its environment). It should be noted that other frameworks, such as Ruby on Rails or even Python's Django, can also be packaged as war files, provided you make use of JRuby or Jython.

Amazon's choice of container is Tomcat, version 6 or 7. Moreover, you can pick either instance to run on a 32-bit architecture or 64-bit. You are also given the ability to fine tune the settings of Tomcat: You can tweak the container instance's heap size and pass in other specific JVM flags (provided you need them). What's more, you have total access to Tomcat's logs.

Next, provided your Web application persists data, you'll need to figure out where you'd like that data to reside. As I noted in my previous article, Data Persistence in the Cloud with Amazon Web Services, AWS offers a host of options, ranging from rolling your own EC2 image and installing a data store on it (such as MySQL, MongoDB, etc.), to using Amazon's SimpleDB, or for those requiring traditional RDBMS functionality, Amazon's RDS (which is a veritable RDBMS as a PaaS!). Either way, you'll need to have this aspect figured out before configuring your Elastic Beanstalk stack. This is one element of Elastic Beanstalk that isn't abstracted away for you — you must write your application to use any one of these services and Amazon will handle the rest for you.

Provided you've signed up for Elastic Beanstalk, have a war file ready for deployment, and figured out where you'll persist any data, you're ready to begin!

Firing Up Your PaaS

If you sign into the AWS Web-based management console, you should see an Elastic Beanstalk tab on the top left. Click it and you'll be presented with the option of deploying your own war or even launching a sample application provided by Amazon.

If you have a war file to deploy and pick the "Upload your own application" option, you'll next be presented with a dialog box that prompts you to give your application a name along with a description. You'll also have the opportunity to select which version and architecture you'd like for Tomcat. It is here that you can upload a war file, too.

Next, you'll have the option of creating a unique URL to your Elastic Beanstalk application.

Finally, you'll be given an opportunity to select which type of EC2 instance you'd like to initially fire up. With Elastic Beanstalk, you always have one EC2 instance running, and as your application receives more traffic, other instances will be spawned as needed.

This dialog is also where you can set a URI (off of the root path of your application) that Amazon will monitor to ascertain application availability; moreover, you can also provide an email address for alerts. Incidentally, this process leverages AWS's SNS, or Simple Notification Service product.

Once you've reviewed your settings and confirmed they're correct, your application will launch. Be patient — launching takes a few minutes.

Your Elastic Beanstalk application's dashboard has a lot going on; however, two important items require an explanation. Even though your application is up and running, you're technically not done setting it up — or rather, Amazon has made some intelligent defaults, but you'll definitely want to see and understand them.

Consequently, on the far right of the dashboard, you'll see an "Actions" pull-down menu. You should click it and select the "Edit/Load Configuration" option. Here, you'll begin to see the power of Elastic Beanstalk.

Clicking the "Edit/Load Configuration" option of the "Actions" pull-down yields a new dialog box with several tabs. If you click the "Container" tab, you'll see where you can increase (or decrease) the heap size allocated to your instance of Tomcat. What's more, there are other options including custom JVM arguments and custom environmental parameters that can be set.

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.