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

      Truthy values are: 1, y, yes, t, true, on.

      Parameters

      • options: GetBooleanFromEnvOptions

        The options for getting the truthy 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"
          
        • key: string

          The key of the environment variable.

      Returns boolean

      import { getTruthyBooleanFromEnv } from '@aws-lambda-powertools/commons/utils/env';

      const myEnvVar = getTruthyBooleanFromEnv({
      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 { getTruthyBooleanFromEnv } from '@aws-lambda-powertools/commons/utils/env';

      const myEnvVar = getTruthyBooleanFromEnv({
      key: 'MY_ENV_VAR',
      defaultValue: true,
      });