Skip to content
Latchkey

serverless invoke: Usage & Common CI Errors

Invoke a deployed (or local) Serverless function and see its output.

serverless invoke calls a function - either the deployed Lambda or a local emulation - with an optional payload. In CI it is a quick smoke test that a function works after deploy.

What it does

serverless invoke --function <name> invokes the deployed function for a stage and prints the response and logs. serverless invoke local --function <name> runs the handler locally without deploying. You pass an event with --data (inline JSON) or --path (a file).

Common usage

Terminal
# Invoke a deployed function with inline JSON
serverless invoke --function api --stage prod --data '{"ping":true}'

# Invoke with a payload file and show logs
sls invoke --function api --path event.json --log

# Run the handler locally (no deploy)
serverless invoke local --function api --path event.json

Common error in CI: function not found / wrong stage

invoke fails with "Function \"api\" doesn’t exist in this Service" or a deployed invoke returns nothing because it targeted the wrong stage. Fix: confirm the function key matches the one under functions: in serverless.yml, and pass the same --stage/--region you deployed to (a remote invoke against an undeployed stage finds nothing). Use invoke local for pre-deploy unit-style checks and remote invoke only after a successful deploy of that stage.

Key options

OptionPurpose
--function NAMEFunction to invoke
--data / -d JSONInline event payload
--path / -p FILEEvent payload from a file
--log / -lPrint the invocation logs
localInvoke locally instead of remote

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →