The options for getting the string.
Optional
defaultValue?: stringOptional 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.
The key of the environment variable.
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.
Get a string from the environment variables.