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

      Parameters

      • options: GetStringFromEnvOptions

        The options for getting the string.

        • OptionaldefaultValue?: string

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

          ""
          
        • 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 string

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

      const myEnvVar = getStringFromEnv({
      key: 'MY_ENV_VAR',
      errorMessage: 'MY_ENV_VAR is required for this function',
      });

      By default, the value is trimmed 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 { getStringFromEnv } from '@aws-lambda-powertools/commons/utils/env';

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