Documentation
.env files

Environment Variable Files

.env files are treated specially by Airbase when running airbase deploy

The environment variable files are loaded and merged in this order (highest-to-lowest priority):

  • .env.${environment}
  • .env
  • .env.local

Configuring variables for an environment

💡

Remember that the production environment (with no suffix) is called the default environment.

When using a command line interface to create a preview environment (for example: preview-new-feature):

Create an env file for the corresponding environment (if necessary)

The env file suffix should match the environment name, for example:

  • preview-new-feature -> .env.preview-new-feature
  • development -> .env.development
  • staging -> .env.staging
  • default -> .env.default (production)
# .env.preview-new-feature
EXAMPLE_PARAMETER=preview-new-feature-1234567890abcdef

Deploy application to Airbase normally

airbase deploy preview-new-feature

Using GitLab CI/CD

When using the Airbase GitLab CI integration and the provided pipeline template, the ENV variable is automatically injected into .env.

To customise the environment variables for each environment from GitLab CI environments:

  1. In the GitLab Console, visit CI/CD Settings > Variables
  2. Then add a new variable and configure it appropriately.
  3. Set the Environment scope to the desired environment (e.g. development, review/*, staging, production, etc.)

Screenshot of GitLab CI / CD Environment Variables

The Environment scope will be matched on the environment parameter in the .gitlab-ci.yml file (see below)

review:
...
  environment:
    name: review/$CI_COMMIT_REF_SLUG
...
 
deploy:
...
  environment:
    name: production
...

Follow the instructions here to set up GitLab CI/CD for your project.

Reserved Environment Variables

Some environment variable names are reserved for internal use by the Airbase platform and the underlying infrastructure (opens in a new tab).

List of Reserved Environment Variables
  • _HANDLER
  • _X_AMZN_TRACE_ID
  • AWS_DEFAULT_REGION
  • AWS_REGION
  • AWS_EXECUTION_ENV
  • AWS_LAMBDA_FUNCTION_NAME
  • AWS_LAMBDA_FUNCTION_MEMORY_SIZE
  • AWS_LAMBDA_FUNCTION_VERSION
  • AWS_LAMBDA_INITIALIZATION_TYPE
  • AWS_LAMBDA_LOG_GROUP_NAME
  • AWS_LAMBDA_LOG_STREAM_NAME
  • AWS_ACCESS_KEY
  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • AWS_SESSION_TOKEN
  • AWS_LAMBDA_RUNTIME_API
  • LAMBDA_TASK_ROOT
  • LAMBDA_RUNTIME_DIR

Suggested Workaround

It's possible to overcome this limitation by renaming or adding a custom prefix to the name of the environment variable.

Here's an example of how a prefix could be added to the front of these reserved variables:

CUSTOM_AWS_REGION=ap-southeast-1
CUSTOM_AWS_ACCESS_KEY_ID=abcde
CUSTOM_AWS_SECRET_ACCESS_KEY=abcde

Then these can be loaded during instantiation of the application (e.g. in the AWS SDK, or other libraries), like this:

let client = new S3Client({
  region: process.env.CUSTOM_AWS_REGION,
  credentials: {
    accessKeyId: process.env.CUSTOM_AWS_ACCESS_KEY_ID,
    secretAccessKey: process.env.CUSTOM_AWS_SECRET_ACCESS_KEY,
  },
});