Updated on 2023-11-22 GMT+08:00

Invoke

Invoke a deployed function. You can send event data, read logs, and view other important information about function calls.
serverless invoke --function functionName

Options

  • --function or -f: The name of the function that you want to invoke. Required
  • --data or -d: Data you want to pass into the function.
  • --path or -p: The path to a JSON file which contains the input data to be transferred to the invoked function. This path is relative to the root directory of the service.

Examples

  • Simple function invocation
    serverless invoke --function functionName

    In this example the deployed function will be invoked and the result of the invocation will be displayed in the terminal.

  • Function invocation with data
    serverless invoke --function functionName --data '{"name": "Bob"}'

    In this example, the function will be invoked with the provided data and the result will be displayed in the terminal.

  • Function invocation with passed data
    serverless invoke --function functionName --path lib/event.json

    In this example, the JSON data in the lib/event.json file will be passed (relative to the root of the service) while invoking the specified or deployed function.

    Example of event.json
    {
        "key": "value"
    }