

# Environment variables and other software settings
Environment variables and software settings

The **Configure updates, monitoring, and logging** configuration page lets you configure the software on the Amazon Elastic Compute Cloud (Amazon EC2) instances that run your application. You can configure environment variables, AWS X-Ray debugging, instance log storing and streaming, and platform-specific settings.

**Topics**
+ [

## Configure platform-specific settings
](#environments-cfg-softwaresettings-specific)
+ [

## Configuring environment properties (environment variables)
](#environments-cfg-softwaresettings-console)
+ [

## Software setting namespaces
](#environments-cfg-softwaresettings-configfiles)
+ [

## Accessing environment properties
](#environments-cfg-softwaresettings-accessing)
+ [

# Configuring AWS X-Ray debugging
](environment-configuration-debugging.md)
+ [

# Viewing your Elastic Beanstalk environment logs
](environments-cfg-logging.md)

## Configure platform-specific settings


In addition to the standard set of options available for all environments, most Elastic Beanstalk platforms let you specify language-specific or framework-specific settings. These appear in the **Platform software** section of the **Configure updates, monitoring, and logging** page, and can take the following forms.
+ **Preset environment properties** – The Ruby platform uses environment properties for framework settings, such as `RACK_ENV` and `BUNDLE_WITHOUT`.
+ **Placeholder environment properties** – The Tomcat platform defines an environment property named `JDBC_CONNECTION_STRING` that is not set to any value. This type of setting was more common on older platform versions.
+ **Configuration options** – Most platforms define [configuration options](command-options.md) in platform-specific or shared namespaces, such as `aws:elasticbeanstalk:xray` or `aws:elasticbeanstalk:container:python`.

**To configure platform-specific settings in the Elastic Beanstalk console**

1. Open the [Elastic Beanstalk console](https://console.aws.amazon.com/elasticbeanstalk), and in the **Regions** list, select your AWS Region.

1. In the navigation pane, choose **Environments**, and then choose the name of your environment from the list.

1. In the navigation pane, choose **Configuration**.

1. In the **Updates, monitoring, and logging** configuration category, choose **Edit**.

1. Under **Platform software**, make necessary option setting changes.

1. To save the changes choose **Apply** at the bottom of the page.

For information about platform-specific options, and about getting environment property values in your code, see the platform topic for your language or framework:
+ Docker – [Configuring Elastic Beanstalk Docker environments](create_deploy_docker.container.console.md)
+ Go – [Using the Elastic Beanstalk Go platform](go-environment.md)
+ Java SE – [Using the Elastic Beanstalk Java SE platform](java-se-platform.md)
+ Tomcat – [Using the Elastic Beanstalk Tomcat platform](java-tomcat-platform.md)
+ .NET Core on Linux – [Using the Elastic Beanstalk .NET core on Linux platform](dotnet-linux-platform.md)
+ .NET – [Using the Elastic Beanstalk .NET Windows platform](create_deploy_NET.container.console.md)
+ Node.js – [Using the Elastic Beanstalk Node.js platform](create_deploy_nodejs.container.md)
+ PHP – [Using the Elastic Beanstalk PHP platform](create_deploy_PHP.container.md)
+ Python – [Using the Elastic Beanstalk Python platform](create-deploy-python-container.md)
+ Ruby – [Using the Elastic Beanstalk Ruby platform](create_deploy_Ruby.container.md)

## Configuring environment properties (environment variables)


You can use **environment properties**, (also known as **environment variables**), to pass endpoints, debug settings, and other information to your application. Environment variables help you run your application in multiple environments for different purposes, such as development, testing, staging, and production.

In addition, when you [add a database to your environment](using-features.managing.db.md), Elastic Beanstalk sets environment variables, such as `RDS_HOSTNAME`, that you can read in your application code to construct a connection object or string.

**To configure environment variables in the Elastic Beanstalk console**

1. Open the [Elastic Beanstalk console](https://console.aws.amazon.com/elasticbeanstalk), and in the **Regions** list, select your AWS Region.

1. In the navigation pane, choose **Environments**, and then choose the name of your environment from the list.

1. In the navigation pane, choose **Configuration**.

1. In the **Updates, monitoring, and logging** configuration category, choose **Edit**.

1. Scroll down to **Runtime environment variables**.

1. Select **Add environment variable**.

1. For **Source** select **Plain text**.
**Note**  
The **Secrets Manager** and **SSM Parameter Store** values in the drop-down are for configuring environment variables as secrets to store sensitive data, such as credentials and API keys. For more information, see [Using Elastic Beanstalk with AWS Secrets Manager and AWS Systems Manager Parameter Store](AWSHowTo.secrets.md). 

1. Enter the **Environment variable name** and **Environment variable value** pairs.

1. If you need to add more variables repeat **Step 6** through **Step 8**.

1. To save the changes choose **Apply** at the bottom of the page.

**Environment property limits**
+ **Keys** can contain any alphanumeric characters and the following symbols: `_ . : / + \ - @`

  The symbols listed are valid for environment property keys, but might not be valid for environment variable names on your environment's platform. For compatibility with all platforms, limit environment properties to the following pattern: `[A-Z_][A-Z0-9_]*`
+ **Values** can contain any alphanumeric characters, white space, and the following symbols: `_ . : / = + \ - @ ' "`
**Note**  
Some characters in environment property values must be escaped. Use the backslash character (`\`) to represent some special characters and control characters. The following list includes examples for representing some characters that need to be escaped:  
backslash (`\`) — to represent use `\\`
single quote (`'`) — to represent use `\'`
double quote (`"`) — to represent use `\"`
+ **Keys** and **values** are case sensitive.
+ The combined size of all environment properties cannot exceed 4,096 bytes when stored as strings with the format *key*=*value*.

## Software setting namespaces


You can use a [configuration file](ebextensions.md) to set configuration options and perform other instance configuration tasks during deployments. Configuration options can be [platform specific](command-options-specific.md) or apply to [all platforms](command-options-general.md) in the Elastic Beanstalk service as a whole. Configuration options are organized into *namespaces*.

You can use Elastic Beanstalk [configuration files](ebextensions.md) to set environment properties and configuration options in your source code. Use the [`aws:elasticbeanstalk:application:environment` namespace](command-options-general.md#command-options-general-elasticbeanstalkapplicationenvironment) to define environment properties.

**Example .ebextensions/options.config**  

```
option_settings:
  aws:elasticbeanstalk:application:environment:
    API_ENDPOINT: www.example.com/api
```

If you use configuration files or CloudFormation templates to create [custom resources](environment-resources.md), you can use an CloudFormation function to get information about the resource and assign it to an environment property dynamically during deployment. The following example from the [elastic-beanstalk-samples](https://github.com/awsdocs/elastic-beanstalk-samples/) GitHub repository uses the [Ref function](ebextensions-functions.md) to get the ARN of an Amazon SNS topic that it creates, and assigns it to an environment property named `NOTIFICATION_TOPIC`.

**Notes**  
If you use an CloudFormation function to define an environment property, the Elastic Beanstalk console displays the value of the property before the function is evaluated. You can use the [`get-config` platform script](custom-platforms-scripts.md) to confirm the values of environment properties that are available to your application. 
The [Multicontainer Docker](create_deploy_docker_ecs.md) platform doesn't use CloudFormation to create container resources. As a result, this platform doesn't support defining environment properties using CloudFormation functions.

**Example .Ebextensions/[sns-topic.config](https://github.com/awsdocs/elastic-beanstalk-samples/tree/main/configuration-files/aws-provided/resource-configuration/sns-topic.config)**  

```
Resources:
  NotificationTopic:
    Type: AWS::SNS::Topic

option_settings:
  aws:elasticbeanstalk:application:environment:
    NOTIFICATION_TOPIC: '`{"Ref" : "NotificationTopic"}`'
```

You can also use this feature to propagate information from [CloudFormation pseudo parameters](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/pseudo-parameter-reference.html). This example gets the current region and assigns it to a property named `AWS_REGION`.

**Example .Ebextensions/[env-regionname.config](https://github.com/awsdocs/elastic-beanstalk-samples/tree/main/configuration-files/aws-provided/instance-configuration/env-regionname.config)**  

```
option_settings:
  aws:elasticbeanstalk:application:environment:
    AWS_REGION: '`{"Ref" : "AWS::Region"}`'
```

Most Elastic Beanstalk platforms define additional namespaces with options for configuring software that runs on the instance, such as the reverse proxy that relays requests to your application. For more information about the namespaces available for your platform, see the following:
+ Go – [Go configuration namespace](go-environment.md#go-namespaces)
+ Java SE – [Java SE configuration namespace](java-se-platform.md#java-se-namespaces)
+ Tomcat – [Tomcat configuration namespaces](java-tomcat-platform.md#java-tomcat-namespaces)
+ .NET Core on Linux – [.NET Core on Linux configuration namespace](dotnet-linux-platform.md#dotnet-linux-namespace)
+ .NET – [The aws:elasticbeanstalk:container:dotnet:apppool namespace](create_deploy_NET.container.console.md#dotnet-namespaces)
+ Node.js – [Node.js configuration namespace](create_deploy_nodejs.container.md#nodejs-namespaces)
+ PHP – [Namespaces for configuration](create_deploy_PHP.container.md#php-namespaces)
+ Python – [Python configuration namespaces](create-deploy-python-container.md#python-namespaces)
+ Ruby – [Ruby configuration namespaces](create_deploy_Ruby.container.md#ruby-namespaces)

Elastic Beanstalk provides many configuration options for customizing your environment. In addition to configuration files, you can also set configuration options using the console, saved configurations, the EB CLI, or the AWS CLI. See [Configuration options](command-options.md) for more information.

## Accessing environment properties


In most cases, you access environment properties in your application code like an environment variable. In general, however, environment properties are passed only to the application and can't be viewed by connecting an instance in your environment and running `env`.
+ [Go](go-environment.md#go-options-properties) – `os.Getenv`

  ```
  endpoint := os.Getenv("API_ENDPOINT")
  ```
+ [Java SE](java-se-platform.md#java-se-options-properties) – `System.getenv`

  ```
  String endpoint = System.getenv("API_ENDPOINT");
  ```
+ [Tomcat](java-tomcat-platform.md#java-tomcat-options-properties) – `System.getProperty` and `System.getenv` 

  Tomcat platform versions released on or after [March 26, 2025](https://docs.aws.amazon.com/elasticbeanstalk/latest/relnotes/release-2025-03-26-windows.html), can also use `System.getenv` to access plaintext environment variables. You can continue to use `System.getProperty` to access plaintext environment variables. However, [environment variables stored as secrets](AWSHowTo.secrets.env-vars.md) are only available using `System.getenv`.

  ```
  String endpoint = System.getProperty("API_ENDPOINT");
  ```

  ```
  String endpoint = System.getenv("API_ENDPOINT");
  ```
**Important**  
The addition of `System.getenv` access for environment variables in Tomcat platform versions released on or after [March 26, 2025](https://docs.aws.amazon.com/elasticbeanstalk/latest/relnotes/release-2025-03-26-windows.html) may cause unexpected behavior in applications that give environment variables precedence over Java system properties or when explicitly switching from `System.getProperty` to `System.getenv`. For more information and recommended actions, see [Using the Elastic Beanstalk Tomcat platform](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/java-tomcat-platform.html).
+ [.NET Core on Linux](dotnet-linux-platform.md#dotnet-linux-options-properties) – `Environment.GetEnvironmentVariable`

  ```
  string endpoint = Environment.GetEnvironmentVariable("API_ENDPOINT");
  ```
+ [.NET](create_deploy_NET.container.console.md#dotnet-console-properties) – `appConfig`

  ```
  NameValueCollection appConfig = ConfigurationManager.AppSettings;
  string endpoint = appConfig["API_ENDPOINT"];
  ```
+ [Node.js](create_deploy_nodejs.container.md#nodejs-platform-console-envprops) – `process.env`

  ```
  var endpoint = process.env.API_ENDPOINT
  ```
+ [PHP](create_deploy_PHP.container.md#php-console-properties) – `$_SERVER`

  ```
  $endpoint = $_SERVER['API_ENDPOINT'];
  ```
+ [Python](create-deploy-python-container.md#create-deploy-python-custom-container-envprop) – `os.environ`

  ```
  import os
  endpoint = os.environ['API_ENDPOINT']
  ```
+ [Ruby](create_deploy_Ruby.container.md#create_deploy_Ruby.env.console.ruby.envprops) – `ENV`

  ```
  endpoint = ENV['API_ENDPOINT']
  ```

Outside of application code, such as in a script that runs during deployment, you can access environment properties with the [`get-config` platform script](custom-platforms-scripts.md). See the [elastic-beanstalk-samples](https://github.com/awsdocs/elastic-beanstalk-samples/search?utf8=%E2%9C%93&q=get-config) GitHub repository for example configurations that use `get-config`.

# Configuring AWS X-Ray debugging
Debugging

You can use the AWS Elastic Beanstalk console or a configuration file to run the AWS X-Ray daemon on the instances in your environment. X-Ray is an AWS service that gathers data about the requests that your application serves, and uses it to construct a service map that you can use to identify issues with your application and opportunities for optimization.

**Note**  
Some regions don't offer X-Ray. If you create an environment in one of these regions, you can't run the X-Ray daemon on the instances in your environment.  
For information about the AWS services offered in each Region, see [Region Table](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/).

![\[The service map for a web API application that uses Amazon DynamoDB to store data\]](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/images/scorekeep-servicemap.png)


X-Ray provides an SDK that you can use to instrument your application code, and a daemon application that relays debugging information from the SDK to the X-Ray API.

**Supported platforms**

You can use the X-Ray SDK with the following Elastic Beanstalk platforms:
+ **Go** - version 2.9.1 and later
+ **Java 8** - version 2.3.0 and later
+ **Java 8 with Tomcat 8** - version 2.4.0 and later
+ **Node.js** - version 3.2.0 and later
+ **Windows Server** - all platform versions released on or after December 18th, 2016
+ **Python** - version 2.5.0 and later

On supported platforms, you can use a configuration option to run the X-Ray daemon on the instances in your environment. You can enable the daemon in the [Elastic Beanstalk console](#environment-configuration-debugging-console) or by using a [configuration file](#environment-configuration-debugging-namespace).

To upload data to X-Ray, the X-Ray daemon requires IAM permissions in the **AWSXrayWriteOnlyAccess** managed policy. These permissions are included in [the Elastic Beanstalk instance profile](concepts-roles-instance.md). If you don't use the default instance profile, see [Giving the Daemon Permission to Send Data to X-Ray](https://docs.aws.amazon.com/xray/latest/devguide/xray-daemon.html#xray-daemon-permissions) in the *AWS X-Ray Developer Guide*.

Debugging with X-Ray requires the use of the X-Ray SDK. See the [Getting Started with AWS X-Ray](https://docs.aws.amazon.com/xray/latest/devguide/xray-gettingstarted.html) in the *AWS X-Ray Developer Guide* for instructions and sample applications.

If you use a platform version that doesn't include the daemon, you can still run it with a script in a configuration file. For more information, see [ Downloading and Running the X-Ray Daemon Manually (Advanced)](https://docs.aws.amazon.com/xray/latest/devguide/xray-daemon-beanstalk.html#xray-daemon-beanstalk-manual) in the *AWS X-Ray Developer Guide*.

**Topics**
+ [

## Configuring debugging
](#environment-configuration-debugging-console)
+ [

## The aws:elasticbeanstalk:xray namespace
](#environment-configuration-debugging-namespace)

## Configuring debugging


You can enable the X-Ray daemon on a running environment in the Elastic Beanstalk console.

**To enable debugging in the Elastic Beanstalk console**

1. Open the [Elastic Beanstalk console](https://console.aws.amazon.com/elasticbeanstalk), and in the **Regions** list, select your AWS Region.

1. In the navigation pane, choose **Environments**, and then choose the name of your environment from the list.

1. In the navigation pane, choose **Configuration**.

1. In the **Updates, monitoring, and logging** configuration category, choose **Edit**.

1. In the **Amazon X-Ray** section, select **Activated**.

1. To save the changes choose **Apply** at the bottom of the page.

You can also enable this option during environment creation. For more information, see [The create new environment wizard](environments-create-wizard.md).

## The aws:elasticbeanstalk:xray namespace


You can use the `XRayEnabled` option in the `aws:elasticbeanstalk:xray` namespace to enable debugging.

To enable debugging automatically when you deploy your application, set the option in a [configuration file](ebextensions.md) in your source code, as follows.

**Example .ebextensions/debugging.config**  

```
option_settings:
  aws:elasticbeanstalk:xray:
    XRayEnabled: true
```

# Viewing your Elastic Beanstalk environment logs
Log viewing

AWS Elastic Beanstalk provides two ways to regularly view logs from the Amazon EC2 instances that run your application:
+ Configure your Elastic Beanstalk environment to upload rotated instance logs to the environment's Amazon S3 bucket.
+ Configure the environment to stream instance logs to Amazon CloudWatch Logs.

When you configure instance log streaming to CloudWatch Logs, Elastic Beanstalk creates CloudWatch Logs log groups for proxy and deployment logs on the Amazon EC2 instances, and transfers these log files to CloudWatch Logs in real time. For more information about instance logs, see [Viewing logs from Amazon EC2 instances in your Elastic Beanstalk environment](using-features.logging.md).

In addition to instance logs, if you enable [enhanced health](health-enhanced.md) for your environment, you can configure the environment to stream health information to CloudWatch Logs. When the environment's health status changes, Elastic Beanstalk adds a record to a health log group, with the new status and a description of the cause of the change. For information about environment health streaming, see [Streaming Elastic Beanstalk environment health information to Amazon CloudWatch Logs](AWSHowTo.cloudwatchlogs.envhealth.md).

## Configuring instance log viewing


To view instance logs, you can enable instance log rotation and log streaming in the Elastic Beanstalk console.

**To configure instance log rotation and log streaming in the Elastic Beanstalk console**

1. Open the [Elastic Beanstalk console](https://console.aws.amazon.com/elasticbeanstalk), and in the **Regions** list, select your AWS Region.

1. In the navigation pane, choose **Environments**, and then choose the name of your environment from the list.

1. In the navigation pane, choose **Configuration**.

1. In the **Updates, monitoring, and logging** configuration category, choose **Edit**.

1. In the **S3 log storage** section, select **Activated** beneath **Rotate logs** to enable uploading rotated logs to Amazon S3.

1. in the **Instance log streaming to CloudWatch Logs** section, configure the following settings:
   + **Log streaming** – Select **Activated** to enable log streaming.
   + **Retention** – Specify the number of days to retain logs in CloudWatch Logs.
   + **Lifecycle** – Set to **Delete logs upon termination** to delete logs from CloudWatch Logs immediately if the environment is terminated, instead of waiting for them to expire.

1. To save the changes choose **Apply** at the bottom of the page.

After you enable log streaming, you can return to the **Software** configuration category or page and find the **Log Groups** link. Click this link to see your instance logs in the CloudWatch console.

## Configuring environment health log viewing


To view environment health logs, you can enable environment health log streaming in the Elastic Beanstalk console.

**To configure environment health log streaming in the Elastic Beanstalk console**

1. Open the [Elastic Beanstalk console](https://console.aws.amazon.com/elasticbeanstalk), and in the **Regions** list, select your AWS Region.

1. In the navigation pane, choose **Environments**, and then choose the name of your environment from the list.

1. In the navigation pane, choose **Configuration**.

1. In the **Updates, monitoring, and logging** configuration category, choose **Edit**.

1. Go to the **Monitoring** section.

1. Under **Health event streaming to CloudWatch Logs**, configure the following settings:
   + **Log streaming** – Choose to **Activated** to enable log streaming.
   + **Retention** – Specify the number of days to retain logs in CloudWatch Logs.
   + **Lifecycle** – Set to **Delete logs upon termination** to delete logs from CloudWatch Logs immediately if the environment is terminated, instead of waiting for them to expire.

1. To save the changes choose **Apply** at the bottom of the page.

## Log viewing namespaces


The following namespaces contain settings for log viewing:
+ [`aws:elasticbeanstalk:hostmanager`](command-options-general.md#command-options-general-elasticbeanstalkhostmanager) – Configure uploading rotated logs to Amazon S3.
+ [`aws:elasticbeanstalk:cloudwatch:logs`](command-options-general.md#command-options-general-cloudwatchlogs) – Configure instance log streaming to CloudWatch.
+ [`aws:elasticbeanstalk:cloudwatch:logs:health`](command-options-general.md#command-options-general-cloudwatchlogs-health) – Configure environment health streaming to CloudWatch.