Invokes a deployed function. It allows you to send an event to a deployed function, which can be useful for testing. Cloudflare Workers only support GET requests for now. The optional headers field allows you to specify headers that will be sent to your Worker along with your request.
serverless invoke --function functionNameIn the following example, you could run:
serverless invoke --function helloWorld# serverless.yml
...
functions:
helloWorld:
# What the script will be called on Cloudflare (this property value must match the function name one line above)
name: helloWorld
# The name of the script on your machine, omitting the .js file extension
script: helloWorld
events:
- http:
url: example.com/hello/user
# Defines the method used by serverless when the `invoke` command is used. Cloudflare Workers only support GET requests for now
method: GET
headers:
greeting: hi--functionor-fThe name of the function in your service that you want to invoke. Required.--dataor-dString data to be passed as an event to your function. By default data is read from standard input.--pathor-pThe path to a json file with input data to be passed to the invoked function. This path is relative to the root directory of the service.
invoke:invoke
serverless invoke --function functionNameThis example will invoke your deployed function on the configured Cloudflare Workers API URL endpoint. This will output the result of the request in your terminal.
serverless invoke --function functionName