Oracle Blog

Blog for Bobby

Automating the Beanstalk Environment

In my last blog, I showed a simple way
to get a list of all the configuration options available in an
Amazon Elastic Beanstalk environment. These are the options for which
no explicit SDK method exists. In this blog, I'll give an example of their use to start up a Beanstalk environment with non-default settings
in one step. Using the AWS console, this is normally a two-step process. Note: the AWS command-line tools offer similar capabilities, but using the
SDK yields better automation. For instance, after the environment is started, I call a method that waits until the environment is green and all the
instances are started.

Before getting to the code, here's a note about how I'm using the credentials. It can be useful to create a separate key pair for each
developer or project or however you compartmentalize your work. The AWS key and secret key are tied to an individual account, but commonly are
shared within an organization (see the identity faq for more info). You can generate multiple
key pairs, however, and can use different pairs for different developers; or use a different key pair for dev vs testing vs production.

By using different key pairs to separate sets of environments, you can perform queries that use the key pair as a filter and thus only act on the
environments, instances, etc, that you want. In this example, the code that waits on the Beanstalk environment to come up assumes that there is only
one environment per key/secret-key/key-pair combination. To generate more key pairs, click the "Key Pairs" link on the EC2 tab in the
AWS console.

The BeanstalkStarter class will start up an environment
using the 32 bit Linux OS with Tomcat 7. As of this writing, the solution stack names and AMI IDs in the Beanstalk console are as follows:

Solution Stack

AMI

32bit Amazon Linux running Tomcat 7

ami-23de1f4a

64bit Amazon Linux running Tomcat 7

ami-6dde1f04

32bit Amazon Linux running Tomcat 6

ami-39de1f50

64bit Amazon Linux running Tomcat 6

ami-79de1f10

The configuration option for the AMI ID has namespace aws:autoscaling:launchconfiguration
and option name ImageId. If you've created your own custom AMI, use your value instead.

The rest of the information for this entry is in comments in the source code. See the code for all the information. In order to focus on setting
environment configuration settings, this example starts up a new environment for an existing application. You could do the same thing for
creating a new application however.