serverless invoke Command Reference
Invoke a deployed Lambda function with a test payload.
serverless invoke calls a function in your deployed service with a chosen payload and prints the response. In CI it is a lightweight post-deploy smoke test.
What it does
serverless invoke triggers a deployed function and returns its response and logs. With the local plugin it can run the handler locally instead. The remote form is the natural post-deploy health check.
Common flags and usage
- --function / -f NAME: the function to invoke (required)
- --stage STAGE: target stage
- --data / -d JSON: inline JSON payload
- --path / -p FILE: read the payload from a file
- --log / -l: include function logs in the output
- serverless invoke local -f NAME: run the handler locally without deploying
Example
- name: Post-deploy smoke test
env:
AWS_REGION: us-east-1
run: |
npx serverless invoke --stage prod --function health \
--data '{"ping":true}' --logIn CI
Run serverless invoke after a deploy to confirm the function responds correctly, asserting on the JSON output to fail the pipeline on a bad deploy. Use --path to keep large payloads in a fixture file, and --log to capture function logs for debugging in the job output.
Key takeaways
- serverless invoke calls a deployed function and returns its response.
- Use it as a post-deploy smoke test and assert on the JSON output.
- serverless invoke local runs the handler without deploying, for fast checks.