The options for getting the boolean.
Optional
defaultValue?: booleanThe default value to return if the environment variable is not set.
Optional
errorMessage?: stringOptional error message to throw if the environment variable is not set and no default value is provided.
Optional
extendedParsing?: booleanWhether to extend the parsing of the boolean value to include common string representations.
The following values are considered true
:
"true"
"1"
"yes"
"on"
"y"
The following values are considered false
:
"false"
"0"
"no"
"off"
"n"
The key of the environment variable.
import { getBooleanFromEnv } from '@aws-lambda-powertools/commons/utils/env';
const myEnvVar = getBooleanFromEnv({
key: 'MY_ENV_VAR',
errorMessage: 'MY_ENV_VAR is required for this function',
});
By default, the value is trimmed before being converted to a boolean and always required.
You can also provide a default value, which will be returned if the environment variable is not set instead of throwing an error.
import { getBooleanFromEnv } from '@aws-lambda-powertools/commons/utils/env';
const myEnvVar = getBooleanFromEnv({
key: 'MY_ENV_VAR',
defaultValue: true,
});
By default, the value is parsed as a boolean. You can also provide an option to extend the parsing of the boolean value to include common string representations.
import { getBooleanFromEnv } from '@aws-lambda-powertools/commons/utils/env';
const myEnvVar = getBooleanFromEnv({
key: 'MY_ENV_VAR',
defaultValue: true,
extendedParsing: true,
});
The following values are considered true
:
"true"
"1"
"yes"
"on"
"y"
The following values are considered false
:
"false"
"0"
"no"
"off"
"n"
Get a boolean from the environment variables.