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
# 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.jsonCommon 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
| Option | Purpose |
|---|---|
| --function NAME | Function to invoke |
| --data / -d JSON | Inline event payload |
| --path / -p FILE | Event payload from a file |
| --log / -l | Print the invocation logs |
| local | Invoke locally instead of remote |