AWS Elastic Beanstalk
Developer Guide (API Version 2010-12-01)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.Did this page help you?  Yes | No |  Tell us about it...

Using Custom Environment Properties with AWS Elastic Beanstalk

You can use the AWS Management Console or the AWS Toolkit for Eclipse to set environment properties that AWS Elastic Beanstalk passes to your server instances. Environment properties are properties specific to your application environment and are not actual (shell) environment variables. More specifically, PARAM1, PARAM2, etc. are system properties passed into the JVM at startup using the -D flag, and you can use them to pass database connection strings, security credentials, or other information that you don't want to hard-code into your application. Storing this information in environment properties can help increase the portability and scalability of your application. You do not need to recompile your source code when you move between environments. You can acquire them with System.getProperty(name).

Using Custom Environment Properties with AWS Toolkit for Eclipse

The following example sets the JDBC_CONNECTION_STRING and PARAM1 environment properties in the AWS Toolkit for Eclipse. After you set these properties, they become available to your AWS Elastic Beanstalk application as system properties called JDBC_CONNECTION_STRING and PARAM1, respectively.

The procedure for setting other environment properties is the same. You can use PARAM1 through PARAM5 for any purpose you choose, but you cannot rename the properties.

To set environment properties for your AWS Elastic Beanstalk application

  1. In the AWS Toolkit for Eclipse, expand the AWS Elastic Beanstalk node and your application node, and then double-click your AWS Elastic Beanstalk environment in the AWS Explorer.

  2. Click the Configuration tab.

  3. Under Container, navigate to the Environment Properties.

  4. In the JDBC_CONNECTION_STRING text box, type a connection string. For example, the following JDBC connection string would connect to a MySQL database instance on port 3306 of localhost, with a username of "me" and a password of "mypassword":

    jdbc:mysql://localhost:3306/mydatabase?user=me&password=mypassword

    This will be accessible to your AWS Elastic Beanstalk application via a system property called JDBC_CONNECTION_STRING.

  5. In the PARAM1 text box, enter a string. For example:

    My test parameter.

    This will be accessible to your AWS Elastic Beanstalk application via an system property called PARAM1.

Using Custom Environment Properties with AWS Management Console

The following example sets the JDBC_CONNECTION_STRING and PARAM1 environment properties in the AWS Toolkit for Eclipse. After you set these properties, they become available to your AWS Elastic Beanstalk application as system properties called JDBC_CONNECTION_STRING and PARAM1, respectively.

The procedure for setting other environment properties is the same. You can use PARAM1 through PARAM5 for any purpose you choose, but you cannot rename the properties.

To set environment properties for your AWS Elastic Beanstalk application

  1. Open the AWS Elastic Beanstalk console at https://console.aws.amazon.com/elasticbeanstalk/.

  2. Select your application from the drop-down list at the top of the AWS Elastic Beanstalk page.

  3. On the AWS Elastic Beanstalk console, in the Environments list for your application, click the Actions arrow, and then click Edit/Load Configuration.

  4. In the Edit Configuration window, click the Container tab.

  5. Scroll down to the Environment Properties section.

  6. In the JDBC_CONNECTION_STRING text box, type a connection string. For example, the following JDBC connection string would connect to a MySQL database instance on port 3306 of localhost, with a username of "me" and a password of "mypassword":

    jdbc:mysql://localhost:3306/mydatabase?user=me&password=mypassword

    This will be accessible to your AWS Elastic Beanstalk application via a system property called JDBC_CONNECTION_STRING.

  7. In the PARAM1 text box, enter a string. For example:

    My test parameter.

    This will be accessible to your AWS Elastic Beanstalk application via an system property called PARAM1.

  8. Click Apply Changes.

    AWS Elastic Beanstalk will update your environment. This might take several minutes.

Accessing Custom Environment Properties

After you set your environment properties for your AWS Elastic Beanstalk application, you can access the environment properties from your code. For example, the following code snippet shows how to access the AWS Elastic Beanstalk environment properties using JavaScript in a JavaServer Page (JSP):

<p>
    The JDBC_CONNECTION_STRING environment property is:
    <%= System.getProperty("JDBC_CONNECTION_STRING") %>
</p>

<p>
    The PARAM1 environment property is:
    <%= System.getProperty("PARAM1") %>
    </p>