Options
All
  • Public
  • Public/Protected
  • All
Menu

Functions that operate on Serverless event objects.

Index

Functions

expectParams

  • expectParams<T, U>(requiredParams: string[], handler: ServerlessFunctionSignature<T, U>, options?: ExpectParamsOptions): ServerlessFunctionSignature<T, U>
  • This is a higher-order function that wraps a given Serverless entry point handler and verifies that each of the HTTP parameters in the list requiredParams is set. If any required parameters are missing, this function will generate an appropriate error response and send that instead of running the code in handler. options is a set of optional configuration values; for now, this is just the moreInfo field, which adds a link to the relevant documentation for the returned error if set.

    Usage:

    const params = ['param1', 'param2'];

    exports.handler = expectParams(params, (context, event, callback) => {
    console.log('Only gets invoked if the params are provided');
    callback(null, { success: true });
    });

    Type parameters

    • T: EnvironmentVariables = {}

    • U = {}

    Parameters

    • requiredParams: string[]

      The list of required HTTP parameters.

    • handler: ServerlessFunctionSignature<T, U>

      A Serverless entry point to wrap.

    • options: ExpectParamsOptions = {}

      Optional configuration parameters.

    Returns ServerlessFunctionSignature<T, U>

    A Serverless entry point suitable for use as a Function's exports.handler.

Generated using TypeDoc