API Reference
    Preparing search index...
    • Get a boolean from the environment variables.

      Parameters

      • options: GetBooleanFromEnvOptions

        The options for getting the boolean.

        • OptionaldefaultValue?: boolean

          The default value to return if the environment variable is not set.

          undefined
          
        • OptionalerrorMessage?: string

          Optional error message to throw if the environment variable is not set and no default value is provided.

          "Environment variable <key> is required"
          
        • OptionalextendedParsing?: boolean

          Whether 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"
          false
          
        • key: string

          The key of the environment variable.

      Returns boolean

      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"