mirror of
https://github.com/serverless/serverless.git
synced 2025-12-08 19:46:03 +00:00
2.1 KiB
2.1 KiB
Read this on the main serverless docs site
Cloudflare Workers - Invoke
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 functionName
In the following example, you could run:
serverless invoke --function helloWorld
# serverless.yml
...
functions:
helloWorld:
# What the script will be called on Cloudflare
worker: hello
# 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
Options
--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.
Provided lifecycle events
invoke:invoke
Examples
Cloudflare Workers
serverless invoke --function functionName
This 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.
Function invocation with data
serverless invoke --function functionName