forked from serverless/serverless
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request serverless#5258 from pinkerton/master
Add support for Cloudflare Workers
- Loading branch information
Showing
33 changed files
with
1,506 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<!-- | ||
title: Serverless - Cloudflare Workers Documentation | ||
menuText: Cloudflare Workers | ||
layout: Doc | ||
--> | ||
|
||
<!-- DOCS-SITE-LINK:START automatically generated --> | ||
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/) | ||
<!-- DOCS-SITE-LINK:END --> | ||
|
||
# Cloudflare Provider Documentation | ||
|
||
Welcome to the Serverless Cloudflare Workers documentation! | ||
|
||
If you have any questions, [search the forums](https://forum.serverless.com?utm_source=framework-docs) or [start your own thread](https://forum.serverless.com?utm_source=framework-docs) | ||
|
||
<div class="docsSections"> | ||
<div class="docsSection"> | ||
<div class="docsSectionHeader"> | ||
<a href="./guide/"> | ||
<img src="https://s3-us-west-2.amazonaws.com/assets.site.serverless.com/docs/cloudflare/guide.png" alt="Serverless Framework Cloudflare Workers Guide" width="250" draggable="false"/> | ||
</a> | ||
</div> | ||
<div class="test"> | ||
<ul> | ||
<li><a href="./guide/intro.md">Intro</a></li> | ||
<li><a href="./guide/quick-start.md">Quickstart</a></li> | ||
<li><a href="./guide/installation.md">Installation</a></li> | ||
<li><a href="./guide/services.md">Services</a></li> | ||
<li><a href="./guide/functions.md">Functions</a></li> | ||
<li><a href="./guide/events.md">Events</a></li> | ||
<li><a href="./guide/deploying.md">Deploying</a></li> | ||
<li><a href="./guide/debugging.md">Debugging</a></li> | ||
<li><a href="./guide/workflow.md">Workflow</a></li> | ||
</ul> | ||
</div> | ||
</div> | ||
|
||
<div class="docsSection"> | ||
<div class="docsSectionHeader"> | ||
<a href="./cli-reference/"> | ||
<img src="https://s3-us-west-2.amazonaws.com/assets.site.serverless.com/docs/cloudflare/cli.png" alt="Serverless Framework Cloudflare Workers CLI Reference" width="250" draggable="false"/> | ||
</a> | ||
</div> | ||
<div> | ||
<ul> | ||
<li><a href="./cli-reference/create.md">Create</a></li> | ||
<li><a href="./cli-reference/deploy.md">Deploy</a></li> | ||
<li><a href="./cli-reference/invoke.md">Invoke</a></li> | ||
<li><a href="./cli-reference/remove.md">Remove</a></li> | ||
<li><a href="./cli-reference/plugin-list.md">Plugin List</a></li> | ||
<li><a href="./cli-reference/plugin-search.md">Plugin Search</a></li> | ||
<li><a href="./cli-reference/plugin-install.md">Plugin Install</a></li> | ||
<li><a href="./cli-reference/plugin-uninstall.md">Plugin Uninstall</a></li> | ||
</ul> | ||
</div> | ||
</div> | ||
|
||
<div class="docsSection"> | ||
<div class="docsSectionHeader"> | ||
<a href="./events/"> | ||
<img src="https://s3-us-west-2.amazonaws.com/assets.site.serverless.com/docs/cloudflare/events.png" alt="Serverless Framework Cloudflare Workers Events Reference" width="250" draggable="false"/> | ||
</a> | ||
</div> | ||
<div> | ||
<ul> | ||
<li><a href="./events/http.md">HTTP Events</a></li> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!-- | ||
title: Serverless - Cloudflare Workers - CLI Reference | ||
menuText: CLI Reference | ||
layout: Doc | ||
--> | ||
|
||
<!-- DOCS-SITE-LINK:START automatically generated --> | ||
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/cli-reference/) | ||
<!-- DOCS-SITE-LINK:END --> | ||
|
||
# Serverless Cloudflare Workers CLI Reference | ||
|
||
Welcome to the Serverless Cloudflare Workers CLI Reference! Please select a section on the left to get started. | ||
|
||
If you have questions, join the [chat in gitter](https://gitter.im/serverless/serverless) or [post over on the forums](http://forum.serverless.com/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<!-- | ||
title: Serverless Framework Commands - Cloudflare Workers - Create | ||
menuText: create | ||
menuOrder: 1 | ||
description: Creates a new Service in your current working directory | ||
layout: Doc | ||
--> | ||
|
||
<!-- DOCS-SITE-LINK:START automatically generated --> | ||
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/cli-reference/create) | ||
<!-- DOCS-SITE-LINK:END --> | ||
|
||
|
||
# Cloudflare Workers - Create | ||
Creates a new Serverless service in the current working directory based on the provided template. | ||
|
||
**Create service in current working directory:** | ||
|
||
```bash | ||
serverless create --template cloudflare-workers | ||
``` | ||
|
||
Or for Enterprise Cloudflare accounts: | ||
|
||
```bash | ||
serverless create --template cloudflare-workers-enterprise | ||
``` | ||
|
||
**Create service in new folder:** | ||
|
||
```bash | ||
serverless create --template cloudflare-workers --path my-service | ||
``` | ||
|
||
Or for Enterprise Cloudflare accounts: | ||
|
||
```bash | ||
serverless create --template cloudflare-workers-enterprise --path my-service | ||
``` | ||
|
||
## Options | ||
- `--template` or `-t` The name of one of the available templates. Required if --template-url and --template-path are not present. | ||
- `--template-url` or `-u` The name of one of the available templates. Required if --template and --template-path are not present. | ||
- `--template-path` The local path of your template. Required if --template and --template-url are not present. | ||
- `--path` or `-p` The path where the service should be created. | ||
- `--name` or `-n` the name of the service in `serverless.yml`. | ||
## Provided lifecycle events | ||
- `create:create` | ||
## Available Templates for Cloudflare Workers | ||
To see a list of available templates run `serverless create --help` | ||
These are the current available templates for Cloudflare Workers: | ||
|
||
- cloudflare-workers | ||
- cloudflare-workers-enterprise | ||
|
||
## Examples | ||
### Creating a new service | ||
```bash | ||
serverless create --template cloudflare-workers --name my-special-service | ||
``` | ||
|
||
This example will generate scaffolding for a service with `Cloudflare` as a provider. The scaffolding will be generated in the current working directory. | ||
|
||
### Creating a named service in a (new) directory | ||
```bash | ||
serverless create --template cloudflare-workers --path my-new-service | ||
``` | ||
|
||
This example will generate scaffolding for a service with `Cloudflare` as a provider. The scaffolding will be generated in the `my-new-service` directory. This directory will be created if not present. Otherwise, Serverless will use the already present directory. | ||
Additionally, Serverless will rename the service according to the path you provide. In this example, the service will be renamed to `my-new-service`. | ||
|
||
### Creating a new service using a local template | ||
```bash | ||
serverless create --template-path path/to/my/template/folder --path path/to/my/service --name my-new-service | ||
``` | ||
This will copy the `path/to/my/template/folder` folder into `path/to/my/service` and rename the service to `my-new-service`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<!-- | ||
title: Serverless Framework Commands - Cloudflare Workers - Deploy | ||
menuText: deploy | ||
menuOrder: 2 | ||
description: Deploy your service to the specified provider | ||
layout: Doc | ||
--> | ||
|
||
<!-- DOCS-SITE-LINK:START automatically generated --> | ||
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/cli-reference/deploy) | ||
<!-- DOCS-SITE-LINK:END --> | ||
|
||
|
||
# Cloudflare Workers - Deploy | ||
In order to be able to deploy any Cloudflare Workers, You will need to set your Global API key from Cloudflare as an environmental variable named `CLOUDFLARE_AUTH_KEY`, and your Cloudflare account email as an environmental variable named `CLOUDFLARE_AUTH_EMAIL`. You can get your Global API key from your [Cloudflare profile](https://dash.cloudflare.com/profile) page. You will also need to set `accountId` and `zoneId` in `serverless.yml` under `service.config`. The first part of the path when you open [Cloudflare dashboard](https://dash.cloudflare.com/) as a logged in user is your `accountId`, e.g. `dash.cloudflare.com/{accountId}`. And the `zoneId` can be found from the overview tab after selecting the desired zone from the [Cloudflare dashboard](https://dash.cloudflare.com/). | ||
|
||
Environmental variables are variables that live inside your terminal. | ||
|
||
For Mac and Linux users, you can set environmental variables like this: | ||
|
||
```bash | ||
export CLOUDFLARE_AUTH_KEY=YOUR_API_KEY_HERE | ||
export CLOUDFLARE_AUTH_EMAIL=YOUR_CLOUDFLARE_EMAIL | ||
``` | ||
|
||
And for Windows (CMD) users, you can set environmental variables like this: | ||
|
||
```bash | ||
set CLOUDFLARE_AUTH_KEY=YOUR_API_KEY_HERE | ||
set CLOUDFLARE_AUTH_EMAIL=YOUR_CLOUDFLARE_EMAIL | ||
``` | ||
|
||
You’ll need to redefine your environmental variables after each time you close your terminal. | ||
|
||
The `serverless deploy` command deploys your entire service via the Cloudflare Workers API. Run this command when you have made service changes (i.e., you edited `serverless.yml`). | ||
Use `serverless deploy -f my-function` when you have made code changes and you want to quickly upload your updated code to Cloudflare. | ||
|
||
```bash | ||
serverless deploy | ||
``` | ||
|
||
This is the simplest deployment usage possible. With this command, Serverless will deploy your service to Cloudflare. | ||
|
||
## Options | ||
- `--verbose` or `-v`: Shows all stack events during deployment, and display any Stack Output. | ||
- `--function` or `-f`: Invokes `deploy function` (see above). Convenience shortcut | ||
|
||
## Provided lifecycle events | ||
- `deploy:deploy` | ||
- `deploy:function:deploy` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<!-- | ||
title: Serverless Framework Commands - Fn - Invoke | ||
menuText: invoke | ||
menuOrder: 3 | ||
description: Invoke an Fn Function using the Serverless Framework | ||
layout: Doc | ||
--> | ||
|
||
<!-- DOCS-SITE-LINK:START automatically generated --> | ||
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/fn/cli-reference/invoke) | ||
<!-- DOCS-SITE-LINK:END --> | ||
|
||
# Fn - Invoke | ||
|
||
Invokes deployed function. It allows to send event data to the function, read logs and display other important information of the function invocation. | ||
|
||
```bash | ||
serverless invoke --function functionName | ||
``` | ||
|
||
## Options | ||
- `--function` or `-f` The name of the function in your service that you want to invoke. **Required**. | ||
- `--data` or `-d` String data to be passed as an event to your function. By default data is read from standard input. | ||
- `--path` or `-p` The 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. | ||
- `--log` or `-l` If set to `true`, it will output logging data of the invocation. Default is `false`. | ||
|
||
## Provided lifecycle events | ||
- `invoke:invoke` | ||
|
||
## Examples | ||
|
||
### Fn | ||
|
||
```bash | ||
serverless invoke --function functionName | ||
``` | ||
|
||
This example will invoke your deployed function on the configured Fn Api Url | ||
endpoint. This will output the result of the invocation in your terminal. | ||
|
||
#### Function invocation with data | ||
|
||
```bash | ||
serverless invoke --function functionName --data '{"name": "Bernie"}' | ||
``` | ||
|
||
#### Function invocation with logging | ||
|
||
```bash | ||
serverless invoke --function functionName --log | ||
``` | ||
|
||
Just like the first example, but will also outputs logging information about your invocation. | ||
|
||
#### Function invocation with data passing | ||
|
||
```bash | ||
serverless invoke --function functionName --path lib/data.json | ||
``` | ||
|
||
This example will pass the json data in the `lib/data.json` file (relative to the root of the service) while invoking | ||
the specified/deployed function. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<!-- | ||
title: Serverless Framework Commands - Cloudflare Workers - Plugin Install | ||
menuText: Plugin Install | ||
menuOrder: 7 | ||
description: Install a Serverless plugin | ||
layout: Doc | ||
--> | ||
|
||
<!-- DOCS-SITE-LINK:START automatically generated --> | ||
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/cli-reference/plugin-install) | ||
<!-- DOCS-SITE-LINK:END --> | ||
|
||
# Plugin Install | ||
|
||
Install a Serverless plugin and add it to the services `plugins` array. By default, a latest version is installed. | ||
If you want a specific version, you can specify `<pluginname>@<version>` as name option. | ||
|
||
**Note:** You might want to change the order of the plugin in the services `plugins` array. | ||
|
||
```bash | ||
serverless plugin install --name pluginName | ||
``` | ||
|
||
## Options | ||
- `--name` or `-n` The plugins name. **Required**. | ||
|
||
## Provided lifecycle events | ||
- `plugin:install:install` | ||
|
||
## Examples | ||
|
||
### Install the `serverless-webpack` plugin | ||
|
||
```bash | ||
serverless plugin install --name serverless-webpack | ||
``` | ||
|
||
### Install a specific version | ||
|
||
```bash | ||
serverless plugin install --name [email protected] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!-- | ||
title: Serverless Framework Commands - Cloudflare Workers - Plugin List | ||
menuText: Plugin List | ||
menuOrder: 5 | ||
description: List all available Serverless plugins | ||
layout: Doc | ||
--> | ||
|
||
<!-- DOCS-SITE-LINK:START automatically generated --> | ||
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/cli-reference/plugin-list) | ||
<!-- DOCS-SITE-LINK:END --> | ||
|
||
# Plugin List | ||
|
||
List all available plugins on the terminal. Connected to the [Serverless plugin registry](https://github.com/serverless/plugins). | ||
|
||
```bash | ||
serverless plugin list | ||
``` | ||
|
||
## Options | ||
- *None* | ||
|
||
## Provided lifecycle events | ||
- `plugin:list:list` |
Oops, something went wrong.