Wednesday Sep 07, 2011

Querying Amazon Elastic Beanstalk Settings with the AWS SDK

Amazon's Elastic Beanstalk simplifies the tasks of getting a web application deployed in a managed environment. The Java SDK that Amazon provides is easy to use for creating/updating Beanstalk environments. There are accessor methods for the most-used configuration settings, such as setEnvironmentName and setApplicationName.

However, many other configuration settings are not so clear. The SDK uses the generic ConfigurationOptionSetting class for most of a Beanstalk environment's information. This class wraps a namespace, option name, and the option's value. Many of the namespace and option name combinations can be found in the various API references, but there's a simpler way to find them all: ask the environment itself.

The attached BeanstalkConfigQuery class performs a query that lists all the current configuration option settings for your environment. Here are a couple lines of output showing the minimum size of my autoscale group and my AWS access key (which has not yet been set). Spacing was added for readability:

    {Namespace: aws:autoscaling:asg, OptionName: MinSize, Value: 1, }
    {Namespace: aws:elasticbeanstalk:application:environment,
        OptionName: AWS_ACCESS_KEY_ID, Value: , }
Using that information, you can easily create an UpdateEnvironmentRequest object to update a running environment:
        ConfigurationOptionSetting minCOS = new ConfigurationOptionSetting(
            "aws:autoscaling:asg", "MinSize", "3");
        ConfigurationOptionSetting awsKeyCOS = new ConfigurationOptionSetting(
            "aws:elasticbeanstalk:application:environment",
            "AWS_ACCESS_KEY_ID", "my_aws_key_text");
        UpdateEnvironmentRequest updateRequest = new UpdateEnvironmentRequest()
            .withEnvironmentName("my_env")
            .withOptionSettings(minCOS, awsKeyCOS);
        beanstalkClient.updateEnvironment(updateRequest);

The BeanstalkConfigQuery class also outputs all the configuration option descriptions, which shows more information about each of the options that you can set. See the comments in the class file for more information, but here are the two descriptions that match the settings listed above. Total, there are close to 50 of these listed when I run against my Beanstalk environment.

    {Namespace: aws:autoscaling:asg, Name: MinSize, DefaultValue: 1,
        ChangeSeverity: NoInterruption, UserDefined: false,
        ValueType: Scalar, ValueOptions: null, MinValue: 1,
        MaxValue: 10000, MaxLength: null, Regex: null, }
    {Namespace: aws:elasticbeanstalk:application:environment,
        Name: AWS_ACCESS_KEY_ID, DefaultValue: ,
        ChangeSeverity: RestartApplicationServer, UserDefined: false,
        ValueType: Scalar, ValueOptions: null, MinValue: null,
        MaxValue: null, MaxLength: 200,
        Regex: {Pattern: ^\S*$, Label: nospaces, }, }

With this information available, the Beanstalk AWS SDK is straightforward to use. In a future post, I'll show an example of programmatically setting up an environment using options like the above. That saves you the step of having to start the environment, wait for it to come up, and then separately update the environment to include the desired settings.

About

Whatever part of GlassFish or the Java EE world that catches my attention. (Also, go Red Sox.)

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today