mirror of
https://github.com/serverless/serverless.git
synced 2025-12-08 19:46:03 +00:00
Merge branch 'master' into 2116-consistent-errors-missing-config
This commit is contained in:
commit
1726daef2e
31
CHANGELOG.md
31
CHANGELOG.md
@ -1,3 +1,26 @@
|
||||
# 1.32.0 (17.09.2018)
|
||||
- [Update quick-start.md](https://github.com/serverless/serverless/pull/5290)
|
||||
- [Backend state item generation and multi-region support](https://github.com/serverless/serverless/pull/5265)
|
||||
|
||||
## Meta
|
||||
- [Comparison since last release](https://github.com/serverless/serverless/compare/v1.31.0...v1.32.0)
|
||||
|
||||
|
||||
# 1.31.0 (11.09.2018)
|
||||
- [Add support for Cloudflare Workers](https://github.com/serverless/serverless/pull/5258)
|
||||
- [docs: Fix mismatch in AWS Metrics](https://github.com/serverless/serverless/pull/5276)
|
||||
- [Add new template for AWS Alexa Typescript](https://github.com/serverless/serverless/pull/5266)
|
||||
- [Remove `/tmp/node-dependencies*`](https://github.com/serverless/serverless/pull/5079)
|
||||
- [Adds FilterPolicy to SNS event](https://github.com/serverless/serverless/pull/5229)
|
||||
- [Update API Gateway Default Request Templates](https://github.com/serverless/serverless/pull/5222)
|
||||
- [Update serverless.yml.md](https://github.com/serverless/serverless/pull/5236)
|
||||
- [Fix for #3069 - Failing to handle schedule event body params](https://github.com/serverless/serverless/pull/5268)
|
||||
- [Remove redundant link to same docs page](https://github.com/serverless/serverless/pull/5243)
|
||||
|
||||
## Meta
|
||||
- [Comparison since last release](https://github.com/serverless/serverless/compare/v1.30.3...v1.31.0)
|
||||
|
||||
|
||||
# 1.30.3 (28.08.2018)
|
||||
- [Fix CORS race condition](https://github.com/serverless/serverless/pull/5256)
|
||||
|
||||
@ -22,6 +45,7 @@
|
||||
## Meta
|
||||
- [Comparison since last release](https://github.com/serverless/serverless/compare/v1.30.0...v1.30.1)
|
||||
|
||||
|
||||
# 1.30.0 (09.08.2018)
|
||||
- [Added support for multiple access keys for multiple tenants](https://github.com/serverless/serverless/pull/5189)
|
||||
- [Fixed a publishing bug when having more than 100 resources](https://github.com/serverless/serverless/pull/5189)
|
||||
@ -37,6 +61,7 @@
|
||||
## Meta
|
||||
- [Comparison since last release](https://github.com/serverless/serverless/compare/v1.29.2...v1.30.0)
|
||||
|
||||
|
||||
# 1.29.2 (29.07.2018)
|
||||
- [Fixed a bug when using APIG lambda integration with Serverless Dashboard](https://github.com/serverless/serverless/pull/5174)
|
||||
- [Fixed a bug by transforming env var to string when setting num value](https://github.com/serverless/serverless/pull/5166)
|
||||
@ -44,12 +69,14 @@
|
||||
## Meta
|
||||
- [Comparison since last release](https://github.com/serverless/serverless/compare/v1.29.1...v1.29.2)
|
||||
|
||||
|
||||
# 1.29.1 (28.07.2018)
|
||||
- [Fixed a bug when using APIG root path with Serverless Dashboard](https://github.com/serverless/serverless/pull/5170)
|
||||
|
||||
## Meta
|
||||
- [Comparison since last release](https://github.com/serverless/serverless/compare/v1.29.0...v1.29.1)
|
||||
|
||||
|
||||
# 1.29.0 (26.07.2018)
|
||||
- [Fixes issue with Node 10.7.0](https://github.com/serverless/serverless/issues/5133)
|
||||
- [Serverless Dashboard Updates: Subscriptions, Resources, Deploys and Refresh Tokens](https://github.com/serverless/serverless/pull/5127)
|
||||
@ -59,6 +86,7 @@
|
||||
## Meta
|
||||
- [Comparison since last release](https://github.com/serverless/serverless/compare/v1.28.0...v1.29.0)
|
||||
|
||||
|
||||
# 1.28.0 (04.07.2018)
|
||||
- [Add SQS event integration](https://github.com/serverless/serverless/pull/5074)
|
||||
- [Integration with the Serverless Dashboard](https://github.com/serverless/serverless/pull/5043)
|
||||
@ -76,6 +104,7 @@
|
||||
## Meta
|
||||
- [Comparison since last release](https://github.com/serverless/serverless/compare/v1.27.0...v1.28.0)
|
||||
|
||||
|
||||
# 1.27.0 (02.05.2018)
|
||||
- [Add maxAge option for CORS](https://github.com/serverless/serverless/pull/4639)
|
||||
- [Add fn integration](https://github.com/serverless/serverless/pull/4934)
|
||||
@ -103,6 +132,7 @@
|
||||
## Meta
|
||||
- [Comparison since last release](https://github.com/serverless/serverless/compare/v1.26.0...v1.26.1)
|
||||
|
||||
|
||||
# 1.26.0 (29.01.2018)
|
||||
- [AWS Go support](https://github.com/serverless/serverless/pull/4669)
|
||||
- [Support for using an existing ApiGateway and Resources](https://github.com/serverless/serverless/pull/4247)
|
||||
@ -190,7 +220,6 @@
|
||||
- [Fixed a bug with Kinesis events](https://github.com/serverless/serverless/pull/4084)
|
||||
- [Fixed a bug with packaging](https://github.com/serverless/serverless/pull/4189)
|
||||
|
||||
|
||||
## Meta
|
||||
- [Comparison since last release](https://github.com/serverless/serverless/compare/v1.21.1...v1.22.0)
|
||||
|
||||
|
||||
@ -337,7 +337,9 @@ This table is generated from https://github.com/serverless/plugins/blob/master/p
|
||||
This table is generated from https://github.com/serverless/examples/blob/master/community-examples.json please make additions there
|
||||
-->
|
||||
| Project Name | Author |
|
||||
| :----------- | :----: |
|
||||
|:-------------|:------:|
|
||||
| **[Serverless Pipeline](https://github.com/msfidelis/serverless-pipeline)** <br/> Simple CI/CD Pipeline to Serverless Projects on AWS using Codepipeline, Codebuild and Terraform | [msfidelis](http://github.com/msfidelis) |
|
||||
| **[Jwtauthorizr](https://github.com/serverlessbuch/jwtAuthorizr)** <br/> Custom JWT Authorizer Lambda function for Amazon API Gateway with Bearer JWT | [serverlessbuch](http://github.com/serverlessbuch) |
|
||||
| **[AWS Demo Java Spring Cloud Function Serverless](https://github.com/mbsambangi/aws-java-spring-cloud-function-demo)** <br/> If Java is your choice of programming language-Spring Cloud Function,Serverless Framework makes a great technology stack. It boosts developer productivity by decoupling from Vendor specific FaaS API, and deployment activities. | [mbsambangi](http://github.com/mbsambangi) |
|
||||
| **[Serverless Architecture Boilerplate](https://github.com/msfidelis/serverless-architecture-boilerplate)** <br/> Boilerplate to organize and deploy big projects using Serverless and CloudFormation on AWS | [msfidelis](http://github.com/msfidelis) |
|
||||
| **[Bablebot](https://github.com/abiglobalhealth/babelbot)** <br/> Lambda + API Gateway: Zero-to-chatbot in <10 lines of JS. Built-in integrations for Messenger, Telegram, Kik, Line, Twilio, Skype, and Wechat. Or roll your own! | [abiglobalhealth](http://github.com/abiglobalhealth) |
|
||||
@ -403,6 +405,7 @@ This table is generated from https://github.com/serverless/examples/blob/master/
|
||||
| **[AWS Cognito Custom User Pool Example](https://github.com/bsdkurt/aws-node-custom-user-pool)** <br/> Example CloudFormation custom resource backed by a lambda using Cognito User Pools | [bsdkurt](http://github.com/bsdkurt) |
|
||||
| **[Serverless Lambda Protobuf Responses](https://github.com/theburningmonk/lambda-protobuf-demo)** <br/> Demo using API Gateway and Lambda with Protocol Buffer | [theburningmonk](http://github.com/theburningmonk) |
|
||||
| **[Serverless Telegram Bot](https://github.com/jonatasbaldin/serverless-telegram-bot)** <br/> This example demonstrates how to setup an echo Telegram Bot using the Serverless Framework ⚡🤖 | [jonatasbaldin](http://github.com/jonatasbaldin) |
|
||||
| **[Serverless Line Bot](https://github.com/jiyeonseo/azure-line-bot-example)** <br/> Echo Line bot using Azure Function with Node.js | [jiyeonseo](http://github.com/jiyeonseo) |
|
||||
| **[Serverless Dashboard For Atom Editor](https://github.com/horike37/serverless-dashboard-for-atom)** <br/> Atom editor package which allows you to deploy and visualize your serverless services with Serverless Framework on your editor. | [horike37](http://github.com/horike37) |
|
||||
| **[Serverless Lambda Vpc Nat Redis](https://github.com/ittus/aws-lambda-vpc-nat-examples)** <br/> Demo using API Gateway and Lambda with VPC and NAT to access Internet and AWS Resource | [ittus](http://github.com/ittus) |
|
||||
| **[Serverless Gitlab CI](https://github.com/bvincent1/serverless-gitlab-ci)** <br/> Simple Gitlab CI template for automatic testing and deployments | [bvincent1](http://github.com/bvincent1) |
|
||||
|
||||
@ -8,7 +8,7 @@ More info about our release process can be found in the [`RELEASE_PROCESS.md`](.
|
||||
|
||||
- [ ] Look through all open issues and PRs (if any) of that milestone and close them / move them to another
|
||||
milestone if still open
|
||||
- [ ] Look through all closed issues and PRs of that milestone to see what has changed. Run `./scripts/prs-since-last tag` or if you want to run against a specific tag `./scripts/prs-since-last tag v1.20.0` to get a list of all merged PR's since a specific tag
|
||||
- [ ] Look through all closed issues and PRs of that milestone to see what has changed. Run `./scripts/prs-since-last-tag` or if you want to run against a specific tag `./scripts/prs-since-last-tag v1.20.0` to get a list of all merged PR's since a specific tag
|
||||
- [ ] Close milestone on GitHub
|
||||
- [ ] Create a new draft release in GitHub
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ services:
|
||||
aws-clojurescript-gradle:
|
||||
image: pgoudreau/docker-maven-node
|
||||
volumes:
|
||||
- ./tmp/serverless-integration-test-aws-clojurescript-gradle:/app
|
||||
- ./tmp/serverless-integration-test-aws-clojurescript-gradle:/app
|
||||
aws-nodejs:
|
||||
image: node:5.11.1
|
||||
volumes:
|
||||
@ -85,6 +85,10 @@ services:
|
||||
image: node:6.10.3
|
||||
volumes:
|
||||
- ./tmp/serverless-integration-test-aws-nodejs-typescript:/app
|
||||
aws-alexa-typescript:
|
||||
image: node:6.10.3
|
||||
volumes:
|
||||
- ./tmp/serverless-integration-test-aws-alexa-typescript:/app
|
||||
aws-nodejs-ecma-script:
|
||||
image: node:6.10.3
|
||||
volumes:
|
||||
@ -109,7 +113,3 @@ services:
|
||||
image: maven:3-jdk-8
|
||||
volumes:
|
||||
- ./tmp/serverless-integration-test-spotinst-java8:/app
|
||||
webtasks-nodejs:
|
||||
image: node:6.10.3
|
||||
volumes:
|
||||
- ./tmp/serverless-integration-test-webtasks-nodejs:/app
|
||||
|
||||
@ -12,7 +12,7 @@ menuItems:
|
||||
- {menuText: "- OpenWhisk", path: /framework/docs/providers/openwhisk/}
|
||||
- {menuText: "- Kubeless" , path: /framework/docs/providers/kubeless/}
|
||||
- {menuText: "- Spotinst" , path: /framework/docs/providers/spotinst/}
|
||||
- {menuText: "- Webtasks" , path: /framework/docs/providers/webtasks/}
|
||||
- {menuText: "- Cloudflare" , path: /framework/docs/providers/cloudflare/}
|
||||
-->
|
||||
|
||||
<!-- DOCS-SITE-LINK:START automatically generated -->
|
||||
@ -127,21 +127,6 @@ Already using AWS or another cloud provider? Read on.
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="docsSection">
|
||||
<div class="docsSectionHeader">
|
||||
<a href="./providers/webtasks/">
|
||||
<img src="https://s3-us-west-2.amazonaws.com/assets.site.serverless.com/docs/webtask-small-grayscale.png" width="250" draggable="false"/>
|
||||
</a>
|
||||
</div>
|
||||
<div>
|
||||
<ul>
|
||||
<li><a href="./providers/webtasks/guide/quick-start">Webtasks QuickStart</a></li>
|
||||
<li><a href="./providers/webtasks/guide">Guide</a></li>
|
||||
<li><a href="./providers/webtasks/cli-reference">CLI Reference</a></li>
|
||||
<li><a href="./providers/webtasks/events">Events</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="docsSection">
|
||||
<div class="docsSectionHeader">
|
||||
<a href="./providers/fn/">
|
||||
@ -157,4 +142,19 @@ Already using AWS or another cloud provider? Read on.
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="docsSection">
|
||||
<div class="docsSectionHeader">
|
||||
<a href="./providers/cloudflare/">
|
||||
<img src="https://s3-us-west-2.amazonaws.com/assets.site.serverless.com/docs/cloudflare/cf-logo-v-dark-gray.png" width="250" draggable="false"/>
|
||||
</a>
|
||||
</div>
|
||||
<div>
|
||||
<ul>
|
||||
<li><a href="./providers/cloudflare/guide/quick-start">Cloudflare Workers QuickStart</a></li>
|
||||
<li><a href="./providers/cloudflare/guide">Guide</a></li>
|
||||
<li><a href="./providers/cloudflare/cli-reference">CLI Reference</a></li>
|
||||
<li><a href="./providers/cloudflare/events">Events</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -11,7 +11,6 @@ menuItems:
|
||||
- {menuText: Google Functions Guide, path: /framework/docs/providers/google/guide/quick-start}
|
||||
- {menuText: Kubeless Guide, path: /framework/docs/providers/kubeless/guide/quick-start}
|
||||
- {menuText: Spotinst Guide, path: /framework/docs/providers/spotinst/guide/quick-start}
|
||||
- {menuText: Webtasks Guide, path: /framework/docs/providers/webtasks/guide/quick-start}
|
||||
-->
|
||||
|
||||
# Getting Started with Serverless
|
||||
@ -92,16 +91,6 @@ Next up, it's time to choose where you'd like your serverless service to run.
|
||||
<a href="/framework/docs/providers/spotinst/guide/quick-start">Spotinst<br/>Quick Start Guide</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="docsSection">
|
||||
<div class="docsSectionHeader">
|
||||
<a href="/framework/docs/providers/webtasks/guide/quick-start">
|
||||
<img src=" https://s3-us-west-2.amazonaws.com/assets.site.serverless.com/docs/webtask-small-grayscale.png" width="250" draggable="false"/>
|
||||
</a>
|
||||
</div>
|
||||
<div style="text-align:center;">
|
||||
<a href="/framework/docs/providers/webtasks/guide/quick-start">Webtasks<br/>Quick Start Guide</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="docsSection">
|
||||
<div class="docsSectionHeader">
|
||||
<a href="/framework/docs/providers/fn/guide/quick-start">
|
||||
@ -112,4 +101,14 @@ Next up, it's time to choose where you'd like your serverless service to run.
|
||||
<a href="/framework/docs/providers/fn/guide/quick-start">Fn<br/>Quick Start Guide</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="docsSection">
|
||||
<div class="docsSectionHeader">
|
||||
<a href="/framework/docs/providers/cloudflare/guide/quick-start">
|
||||
<img src="https://s3-us-west-2.amazonaws.com/assets.site.serverless.com/docs/cloudflare/cf-logo-v-dark-gray.png" width="250" draggable="false"/>
|
||||
</a>
|
||||
</div>
|
||||
<div style="text-align:center;">
|
||||
<a href="/framework/docs/providers/cloudflare/guide/quick-start">Cloudflare Workers<br/>Quick Start Guide</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -73,16 +73,6 @@ Under the hood, the serverless framework is deploying your code to a cloud provi
|
||||
<a href="./spotinst/">Spotinst Docs</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="docsSection">
|
||||
<div class="docsSectionHeader">
|
||||
<a href="./webtasks/">
|
||||
<img src="https://s3-us-west-2.amazonaws.com/assets.site.serverless.com/docs/webtask-small-grayscale.png" width="250" draggable="false"/>
|
||||
</a>
|
||||
</div>
|
||||
<div style="text-align:center;">
|
||||
<a href="./webtasks/">Auth0 Webtasks Docs</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="docsSection">
|
||||
<div class="docsSectionHeader">
|
||||
<a href="./fn/">
|
||||
|
||||
@ -52,6 +52,7 @@ Most commonly used templates:
|
||||
- aws-clojure-gradle
|
||||
- aws-nodejs
|
||||
- aws-nodejs-typescript
|
||||
- aws-alexa-typescript
|
||||
- aws-nodejs-ecma-script
|
||||
- aws-python
|
||||
- aws-python3
|
||||
|
||||
@ -28,6 +28,7 @@ serverless invoke local --function functionName
|
||||
- `--raw` Pass data as a raw string even if it is JSON. If not set, JSON data are parsed and passed as an object.
|
||||
- `--contextPath` or `-x`, The path to a json file holding input context to be passed to the invoked function. This path is relative to the root directory of the service.
|
||||
- `--context` or `-c`, String data to be passed as a context to your function. Same like with `--data`, context included in `--contextPath` will overwrite the context you passed with `--context` flag.
|
||||
* `--env` or `-e` String representing an environment variable to set when invoking your function, in the form `<name>=<value>`. Can be repeated for more than one environment variable.
|
||||
|
||||
## Environment
|
||||
|
||||
@ -94,6 +95,16 @@ serverless invoke local --function functionName --contextPath lib/context.json
|
||||
```
|
||||
This example will pass the json context in the `lib/context.json` file (relative to the root of the service) while invoking the specified/deployed function.
|
||||
|
||||
### Local function invocation, setting environment variables
|
||||
|
||||
```bash
|
||||
serverless invoke local -f functionName -e VAR1=value1
|
||||
|
||||
# Or more than one variable
|
||||
|
||||
serverless invoke local -f functionName -e VAR1=value1 -e VAR2=value2
|
||||
```
|
||||
|
||||
### Limitations
|
||||
|
||||
Currently, `invoke local` only supports the NodeJs, Python & Java runtimes.
|
||||
|
||||
@ -23,7 +23,7 @@ serverless metrics
|
||||
- `--function` or `-f` The function you want to fetch the metrics for.
|
||||
- `--stage` or `-s` The stage you want to view the function metrics for. If not provided, the plugin will use the default stage listed in `serverless.yml`. If that doesn't exist either it'll just fetch the metrics from the `dev` stage.
|
||||
- `--region` or `-r` The region you want to view the function metrics for. If not provided, the plugin will use the default region listed in `serverless.yml`. If that doesn't exist either it'll just fetch the metrics from the `us-east-1` region.
|
||||
- `--startTime` A specific unit in time to start fetching metrics from (ie: `2010-10-20`, `1469705761`, `30m` (30 minutes ago), `2h` (2 days ago) or `3d` (3 days ago)). Date formats should be written in ISO 8601. Defaults to 24h ago.
|
||||
- `--startTime` A specific unit in time to start fetching metrics from (ie: `2010-10-20`, `1469705761`, `30m` (30 minutes ago), `2h` (2 hours ago) or `3d` (3 days ago)). Date formats should be written in ISO 8601. Defaults to 24h ago.
|
||||
- `--endTime` A specific unit in time to end fetching metrics from (ie: `2010-10-21` or `1469705761`). Date formats should be written in ISO 8601. Defaults to now.
|
||||
|
||||
## Examples
|
||||
|
||||
@ -602,7 +602,7 @@ Both templates give you access to the following properties you can access with t
|
||||
- principalId
|
||||
- stage
|
||||
- headers
|
||||
- query
|
||||
- queryStringParameters
|
||||
- path
|
||||
- identity
|
||||
- stageVariables
|
||||
|
||||
@ -95,3 +95,20 @@ functions:
|
||||
topicName: aggregate
|
||||
displayName: Data aggregation pipeline
|
||||
```
|
||||
|
||||
## Setting a filter policy
|
||||
|
||||
This event definition creates an SNS topic which subscription uses a filter policy. The filter policy filters out messages that don't have attribute key `pet` with value `dog` or `cat`.
|
||||
|
||||
```yml
|
||||
functions:
|
||||
pets:
|
||||
handler: pets.handler
|
||||
events:
|
||||
- sns:
|
||||
topicName: pets
|
||||
filterPolicy:
|
||||
pet:
|
||||
- dog
|
||||
- cat
|
||||
```
|
||||
|
||||
@ -18,6 +18,8 @@ The ARN for the queue can be specified as a string, the reference to the ARN of
|
||||
|
||||
**Note:** The `sqs` event will hook up your existing SQS Queue to a Lambda function. Serverless won't create a new queue for you.
|
||||
|
||||
**IMPORTANT:** AWS is [not supporting FIFO queue](https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html) to trigger Lambda function so your queue(s) **must be** a standard queue.
|
||||
|
||||
```yml
|
||||
functions:
|
||||
compute:
|
||||
|
||||
@ -15,7 +15,7 @@ Make sure `serverless` is installed. [See installation guide](../../../guide/ins
|
||||
|
||||
Once installed the Serverless CLI can be called with `serverless` or the shorthand `sls` command.
|
||||
|
||||
If `sls` command retuns an error in PowerShell, please user `serverless` command.
|
||||
If `sls` command retuns an error in PowerShell, please use `serverless` command.
|
||||
|
||||
```
|
||||
$ sls
|
||||
|
||||
@ -20,7 +20,7 @@ layout: Doc
|
||||
|
||||
Check out the following links for tutorial walkthroughs:
|
||||
|
||||
- [Build an Node.js REST API](/blog/serverless-express-rest-api/)
|
||||
- [Build a Node.js REST API](/blog/serverless-express-rest-api/)
|
||||
- [Deploy a GraphQL endpoint](/blog/make-serverless-graphql-api-using-lambda-dynamodb/)
|
||||
|
||||
Or follow the steps below for creating & deploying a simple service and learning some simple Serverless commands.
|
||||
@ -76,5 +76,3 @@ If at any point, you no longer need your service, you can run the following comm
|
||||
```bash
|
||||
serverless remove
|
||||
```
|
||||
|
||||
Check out the [Serverless Framework Guide](./README.md) for more information.
|
||||
|
||||
@ -25,9 +25,9 @@ frameworkVersion: ">=1.0.0 <2.0.0"
|
||||
|
||||
provider:
|
||||
name: aws
|
||||
runtime: nodejs6.10
|
||||
stage: dev # Set the default stage used. Default is dev
|
||||
region: us-east-1 # Overwrite the default region used. Default is us-east-1
|
||||
runtime: nodejs8.10
|
||||
stage: ${opt:stage, 'dev'} # Set the default stage used. Default is dev
|
||||
region: ${opt:region, 'us-east-1'} # Overwrite the default region used. Default is us-east-1
|
||||
stackName: custom-stack-name # Use a custom name for the CloudFormation stack
|
||||
apiName: custom-api-name # Use a custom name for the API Gateway API
|
||||
profile: production # The default profile to use with this service
|
||||
|
||||
@ -54,6 +54,7 @@ Here are the available runtimes for AWS Lambda:
|
||||
* aws-clojure-gradle
|
||||
* aws-nodejs
|
||||
* aws-nodejs-typescript
|
||||
* aws-alexa-typescript
|
||||
* aws-nodejs-ecma-script
|
||||
* aws-python
|
||||
* aws-python3
|
||||
|
||||
@ -33,15 +33,15 @@ You can define your own variable syntax (regex) if it conflicts with CloudFormat
|
||||
|
||||
## Current variable sources:
|
||||
|
||||
- [environment variables](https://serverless.com/framework/docs/providers/aws/guide/variables#referencing-environment-variables)
|
||||
- [CLI options](https://serverless.com/framework/docs/providers/aws/guide/variables#referencing-cli-options)
|
||||
- [other properties defined in `serverless.yml`](https://serverless.com/framework/docs/providers/aws/guide/variables#reference-properties-in-serverlessyml)
|
||||
- [external YAML/JSON files](https://serverless.com/framework/docs/providers/aws/guide/variables#reference-variables-in-other-files)
|
||||
- [variables from S3](https://serverless.com/framework/docs/providers/aws/guide/variables#referencing-s3-objects)
|
||||
- [variables from AWS SSM Parameter Store](https://serverless.com/framework/docs/providers/aws/guide/variables#reference-variables-using-the-ssm-parameter-store)
|
||||
- [CloudFormation stack outputs](https://serverless.com/framework/docs/providers/aws/guide/variables#reference-cloudformation-outputs)
|
||||
- [properties exported from Javascript files (sync or async)](https://serverless.com/framework/docs/providers/aws/guide/variables#reference-variables-in-javascript-files)
|
||||
- [Pseudo Parameters Reference](https://serverless.com/framework/docs/providers/aws/guide/variables#referencing-Pseudo-Parameters-Reference)
|
||||
- [environment variables](#referencing-environment-variables)
|
||||
- [CLI options](#referencing-cli-options)
|
||||
- [other properties defined in `serverless.yml`](#reference-properties-in-serverlessyml)
|
||||
- [external YAML/JSON files](#reference-variables-in-other-files)
|
||||
- [variables from S3](#referencing-s3-objects)
|
||||
- [variables from AWS SSM Parameter Store](#reference-variables-using-the-ssm-parameter-store)
|
||||
- [CloudFormation stack outputs](#reference-cloudformation-outputs)
|
||||
- [properties exported from Javascript files (sync or async)](#reference-variables-in-javascript-files)
|
||||
- [Pseudo Parameters Reference](#referencing-Pseudo-Parameters-Reference)
|
||||
|
||||
## Recursively reference properties
|
||||
|
||||
|
||||
71
docs/providers/cloudflare/README.md
Normal file
71
docs/providers/cloudflare/README.md
Normal file
@ -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>
|
||||
15
docs/providers/cloudflare/cli-reference/README.md
Normal file
15
docs/providers/cloudflare/cli-reference/README.md
Normal file
@ -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/).
|
||||
76
docs/providers/cloudflare/cli-reference/create.md
Normal file
76
docs/providers/cloudflare/cli-reference/create.md
Normal file
@ -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`.
|
||||
50
docs/providers/cloudflare/cli-reference/deploy.md
Normal file
50
docs/providers/cloudflare/cli-reference/deploy.md
Normal file
@ -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`
|
||||
65
docs/providers/cloudflare/cli-reference/invoke.md
Normal file
65
docs/providers/cloudflare/cli-reference/invoke.md
Normal file
@ -0,0 +1,65 @@
|
||||
<!--
|
||||
title: Serverless Framework Commands - Cloudflare Workers - Invoke
|
||||
menuText: invoke
|
||||
menuOrder: 3
|
||||
description: Invoke a Cloudflare Workers 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/cloudflare-workers/cli-reference/invoke)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
|
||||
# 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.
|
||||
|
||||
```bash
|
||||
serverless invoke --function functionName
|
||||
```
|
||||
|
||||
In the following example, you could run:
|
||||
|
||||
```bash
|
||||
serverless invoke --function helloWorld
|
||||
```
|
||||
|
||||
```yml
|
||||
# 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
|
||||
* `--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.
|
||||
|
||||
## Provided lifecycle events
|
||||
- `invoke:invoke`
|
||||
|
||||
## Examples
|
||||
|
||||
### Cloudflare Workers
|
||||
```bash
|
||||
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
|
||||
```bash
|
||||
serverless invoke --function functionName
|
||||
```
|
||||
42
docs/providers/cloudflare/cli-reference/plugin-install.md
Normal file
42
docs/providers/cloudflare/cli-reference/plugin-install.md
Normal file
@ -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 serverless-webpack@3.0.0-rc.2
|
||||
```
|
||||
25
docs/providers/cloudflare/cli-reference/plugin-list.md
Normal file
25
docs/providers/cloudflare/cli-reference/plugin-list.md
Normal file
@ -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`
|
||||
33
docs/providers/cloudflare/cli-reference/plugin-search.md
Normal file
33
docs/providers/cloudflare/cli-reference/plugin-search.md
Normal file
@ -0,0 +1,33 @@
|
||||
<!--
|
||||
title: Serverless Framework Commands - Cloudflare Workers - Plugin Search
|
||||
menuText: Plugin Search
|
||||
menuOrder: 6
|
||||
description: Search through 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-search)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
# Plugin Search
|
||||
|
||||
Search for a specific plugin based on a search query. Connected to the [Serverless plugin registry](https://github.com/serverless/plugins).
|
||||
|
||||
```bash
|
||||
serverless plugin search --query query
|
||||
```
|
||||
|
||||
## Options
|
||||
- `--query` or `-q` The query you want to use for your search. **Required**.
|
||||
|
||||
## Provided lifecycle events
|
||||
- `plugin:search:search`
|
||||
|
||||
## Examples
|
||||
|
||||
### Search for a `sqs` plugin
|
||||
|
||||
```bash
|
||||
serverless plugin search --query sqs
|
||||
```
|
||||
33
docs/providers/cloudflare/cli-reference/plugin-uninstall.md
Normal file
33
docs/providers/cloudflare/cli-reference/plugin-uninstall.md
Normal file
@ -0,0 +1,33 @@
|
||||
<!--
|
||||
title: Serverless Framework Commands - Cloudflare Workers - Plugin Uninstall
|
||||
menuText: Plugin Uninstall
|
||||
menuOrder: 8
|
||||
description: Uninstall 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-uninstall)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
# Plugin Uninstall
|
||||
|
||||
Uninstall a Serverless plugin and remove it from the services `plugins` array.
|
||||
|
||||
```bash
|
||||
serverless plugin uninstall --name pluginName
|
||||
```
|
||||
|
||||
## Options
|
||||
- `--name` or `-n` The plugins name. **Required**.
|
||||
|
||||
## Provided lifecycle events
|
||||
- `plugin:uninstall:uninstall`
|
||||
|
||||
## Examples
|
||||
|
||||
### Remove the `serverless-webpack` plugin
|
||||
|
||||
```bash
|
||||
serverless plugin uninstall --name serverless-webpack
|
||||
```
|
||||
21
docs/providers/cloudflare/cli-reference/remove.md
Normal file
21
docs/providers/cloudflare/cli-reference/remove.md
Normal file
@ -0,0 +1,21 @@
|
||||
<!--
|
||||
title: Serverless Framework Commands - Cloudflare Workers - Remove
|
||||
menuText: remove
|
||||
menuOrder: 4
|
||||
description: Remove a deployed Service and all of its Cloudflare Worker Functions and Services.
|
||||
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/remove)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
# Cloudflare Workers - Remove
|
||||
The `serverless remove` command will remove the deployed service, defined in your current working directory, from the provider.
|
||||
|
||||
```bash
|
||||
serverless remove
|
||||
```
|
||||
It will remove the Cloudflare Worker functions from the Cloudflare.
|
||||
## Provided lifecycle events
|
||||
- `remove:remove`
|
||||
18
docs/providers/cloudflare/events/README.md
Normal file
18
docs/providers/cloudflare/events/README.md
Normal file
@ -0,0 +1,18 @@
|
||||
<!--
|
||||
title: Serverless - Cloudflare Workers - Events
|
||||
menuText: Cloudflare Workers Events
|
||||
layout: Doc
|
||||
-->
|
||||
|
||||
<!-- DOCS-SITE-LINK:START automatically generated -->
|
||||
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/events/)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
# Serverless Cloudflare Workers Events
|
||||
|
||||
Welcome to the Serverless Cloudflare Workers Events Glossary!
|
||||
|
||||
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/)
|
||||
|
||||
37
docs/providers/cloudflare/events/http.md
Normal file
37
docs/providers/cloudflare/events/http.md
Normal file
@ -0,0 +1,37 @@
|
||||
<!--
|
||||
title: Serverless Framework - Cloudflare Workers Events - HTTP Events
|
||||
menuText: HTTP Events
|
||||
menuOrder: 1
|
||||
description: HTTP Events in Cloudflare Workers
|
||||
layout: Doc
|
||||
-->
|
||||
|
||||
<!-- DOCS-SITE-LINK:START automatically generated -->
|
||||
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/events/http)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
|
||||
# Cloudflare Workers - HTTP Events
|
||||
The only type of event that is supported in Cloudflare Workers is HTTP events, so defining events in your `serverless.yml` is optional. Defined events in your `serverless.yml` are only used by the `serverless invoke` command, which can be useful for testing your Functions.
|
||||
|
||||
## Serverless Yml
|
||||
When creating a service your serverless yml will define which endpoint is used for your function when you run the [`serverless invoke`](../cli-reference/invoke.md) command.
|
||||
|
||||
```yml
|
||||
# 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
|
||||
method: GET
|
||||
headers:
|
||||
greeting: hi
|
||||
```
|
||||
|
||||
The events section in the yml above makes it so that the Function helloWorld will be used for request to the `example.com/hello/user` endpoint. This configuration would send a GET request with a header called `greeting` that has a value of `hi` to the `example.com/hello/user` endpoint when you run `serverless invoke -f helloWorld`.
|
||||
17
docs/providers/cloudflare/guide/README.md
Normal file
17
docs/providers/cloudflare/guide/README.md
Normal file
@ -0,0 +1,17 @@
|
||||
<!--
|
||||
title: Serverless - Cloudflare Workers
|
||||
menuText: Guide
|
||||
layout: Doc
|
||||
-->
|
||||
|
||||
<!-- DOCS-SITE-LINK:START automatically generated -->
|
||||
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/guide/)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
# Serverless Cloudflare Workers Guide
|
||||
|
||||
Welcome to the Serverless Cloudflare Workers Guide!
|
||||
|
||||
Get started with the **[Introduction to the Serverless framework](./intro.md)**
|
||||
|
||||
If you have questions, join the [chat in gitter](https://gitter.im/serverless/serverless) or [post over on the forums](http://forum.serverless.com/)
|
||||
62
docs/providers/cloudflare/guide/debugging.md
Normal file
62
docs/providers/cloudflare/guide/debugging.md
Normal file
@ -0,0 +1,62 @@
|
||||
<!--
|
||||
title: Serverless Framework - Cloudflare Workers Guide - Debugging
|
||||
menuText: Debugging
|
||||
menuOrder: 8
|
||||
description: Recommendations and best practices for debugging Cloudflare Workers with 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/cloudflare/guide/debugging)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
# Cloudflare Workers - Debugging
|
||||
How can we debug errors in our Cloudflare Workers functions?
|
||||
|
||||
Let's imagine that we have deployed the following code as a Cloudflare Worker function using Serverless:
|
||||
|
||||
```javascript
|
||||
addEventListener('fetch', event => {
|
||||
event.respondWith(handleRequest(event.request))
|
||||
})
|
||||
async function handleRequest(request) {
|
||||
const answer = request.headers.get("greeting") || "hello"
|
||||
return new Response(answer + " world")
|
||||
}
|
||||
|
||||
```
|
||||
And its corresponding Serverless yml file:
|
||||
|
||||
```yml
|
||||
# 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
|
||||
```
|
||||
|
||||
Let's invoke correctly that function
|
||||
|
||||
```bash
|
||||
serverless invoke --function helloWorld
|
||||
|
||||
# Output
|
||||
hi world
|
||||
```
|
||||
|
||||
|
||||
If we were to call the above function without any headers, you would get `hello world` back instead of `hi world`, so we know that our worker is properly reading the greeting header.
|
||||
|
||||
## Cloudflare Workers Playground
|
||||
|
||||
Cloudflare Workers also have a [Playground](https://cloudflareworkers.com/#) you can use to modify a Cloudflare Worker and see the results live on the same screen. The Cloudflare Workers Playground is another great way to debug your worker.
|
||||
115
docs/providers/cloudflare/guide/deploying.md
Normal file
115
docs/providers/cloudflare/guide/deploying.md
Normal file
@ -0,0 +1,115 @@
|
||||
<!--
|
||||
title: Serverless Framework - Cloudflare Workers Guide - Deploying
|
||||
menuText: Deploying
|
||||
menuOrder: 7
|
||||
description: How to deploy your Cloudflare Workers functions and their required infrastructure
|
||||
layout: Doc
|
||||
-->
|
||||
|
||||
<!-- DOCS-SITE-LINK:START automatically generated -->
|
||||
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/guide/deploying)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
# Cloudflare Workers - Deploying
|
||||
The Serverless Framework was designed to provision your Cloudflare Workers Functions and Events. It does this via a couple of methods designed for different types of deployments.
|
||||
|
||||
## prerequisites
|
||||
|
||||
In order to deploy your Cloudflare Worker, you need to set your Cloudflare email as an environmental variable called `CLOUDFLARE_AUTH_EMAIL`, and your Cloudflare Global API Key as an environmental variable called `CLOUDFLARE_AUTH_KEY`. 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.
|
||||
|
||||
|
||||
|
||||
## Deploy All
|
||||
This is the main method for doing deployments with the Serverless Framework:
|
||||
|
||||
```bash
|
||||
serverless deploy
|
||||
```
|
||||
|
||||
Use this method when you have updated your Function, Event or Resource configuration in `serverless.yml` and you want to deploy that change (or multiple changes at the same time) to your Cloudflare Worker. If you've made changes to any of your routes since last deploying, the Serverless Framework will update them on the server for you.
|
||||
|
||||
### How It Works
|
||||
The Serverless Framework reads in `serverless.yml` and uses it to provision your Functions.
|
||||
|
||||
For each defined Function in your `serverless.yml` file, the Framework will create a Cloudflare Workers script. This means that only enterprise customers can declare more than one Function, but anyone can use [webpack](https://developers.cloudflare.com/workers/writing-workers/using-npm-modules/) to package their application into a single script.
|
||||
|
||||
For example, let's take the following example `serverless.yml` file:
|
||||
|
||||
```yml
|
||||
# serverless.yml
|
||||
|
||||
service:
|
||||
name: hello-world
|
||||
config:
|
||||
accountId: CLOUDFLARE_ACCOUNT_ID
|
||||
zoneId: CLOUDFLARE_ZONE_ID
|
||||
workers:
|
||||
hello:
|
||||
routes:
|
||||
- example.com/hello/*
|
||||
foo_script:
|
||||
routes:
|
||||
- example.com/foo/*
|
||||
|
||||
provider:
|
||||
name: cloudflare
|
||||
|
||||
plugins:
|
||||
- serverless-cloudflare-workers
|
||||
|
||||
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 are optional to declare and only affect the `serverless invoke` command
|
||||
events:
|
||||
- http:
|
||||
url: example.com/hello/user
|
||||
method: GET
|
||||
headers:
|
||||
greeting: hi
|
||||
|
||||
|
||||
# Only Enterprise accounts would be allowed to add this second function
|
||||
foo:
|
||||
worker: foo_script
|
||||
script: bar
|
||||
events:
|
||||
- http:
|
||||
url: example.com/foo/bar
|
||||
method: GET
|
||||
```
|
||||
|
||||
After deploying that file, you’ll be able to hit the specified top-level routes of your zone, `example.com/hello/*` and `example.com/foo/*`, and any endpoints that resolve to these routes, like `example.com/hello/user` and `example.com/foo/bar`.
|
||||
|
||||
## Deploy Function
|
||||
This deployment method updates or deploys a single function. It performs the platform API call to deploy your package without the other resources. It is much faster than re-deploying your whole service each time.
|
||||
|
||||
```bash
|
||||
serverless deploy --function myFunction
|
||||
```
|
||||
|
||||
If you've made changes to the routes corresponding to this Function since last deploying, the Serverless Framework will update them on the server for you.
|
||||
|
||||
### Tips
|
||||
Check out the [deploy command docs](../cli-reference/deploy.md) for all details and options.
|
||||
40
docs/providers/cloudflare/guide/events.md
Normal file
40
docs/providers/cloudflare/guide/events.md
Normal file
@ -0,0 +1,40 @@
|
||||
<!--
|
||||
title: Serverless Framework - Clouldflare Workers Guide - Events
|
||||
menuText: Events
|
||||
menuOrder: 6
|
||||
description: Configuring Cloudflare Workers Events in 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/cloudflare/guide/events)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
|
||||
# Cloudflare Workers - Events
|
||||
Simply put, events are the things that trigger your functions to run. Currently, they are optional to define and are only used by the `serverless invoke` command, which can be useful for testing your Functions.
|
||||
|
||||
If you are using Cloudflare Workers as your provider, all `events` in the service are HTTP Events, because that is the only event that Cloudflare Workers currently support.
|
||||
|
||||
```yml
|
||||
# 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
|
||||
```
|
||||
|
||||
Then [`serverless invoke -f helloWorld`](../cli-reference/invoke.md) will make a GET request to `example.com/hello/user` with a header called `greeting` that has a value of `hi`.
|
||||
|
||||
[View the Cloudflare Workers events section for more information on HTTP events](../events).
|
||||
119
docs/providers/cloudflare/guide/functions.md
Normal file
119
docs/providers/cloudflare/guide/functions.md
Normal file
@ -0,0 +1,119 @@
|
||||
<!--
|
||||
title: Serverless Framework - Cloudflare Workers Guide - Functions
|
||||
menuText: Functions
|
||||
menuOrder: 5
|
||||
description: How to configure Cloudflare Workers functions in 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/cloudflare/guide/functions)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
# Cloudflare Workers - Functions
|
||||
|
||||
If you are using Cloudflare as a provider, all *functions* inside the service are Cloudflare Workers.
|
||||
|
||||
## Configuration
|
||||
|
||||
All of the Cloudflare Workers in your serverless service can be found in `serverless.yml` under the `functions` property.
|
||||
|
||||
```yml
|
||||
# serverless.yml
|
||||
|
||||
service:
|
||||
name: hello-world
|
||||
config:
|
||||
accountId: CLOUDFLARE_ACCOUNT_ID
|
||||
zoneId: CLOUDFLARE_ZONE_ID
|
||||
workers:
|
||||
hello:
|
||||
routes:
|
||||
- example.com/hello/*
|
||||
|
||||
provider:
|
||||
name: cloudflare
|
||||
|
||||
plugins:
|
||||
- serverless-cloudflare-workers
|
||||
|
||||
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 are only relevant to the `serverless invoke` command and don’t affect deployment in any way
|
||||
events:
|
||||
- http:
|
||||
url: example.com/hello/user
|
||||
method: GET
|
||||
headers:
|
||||
someKey: someValue
|
||||
```
|
||||
|
||||
The `script` property points to the file containing your Cloudflare Worker.
|
||||
|
||||
```javascript
|
||||
// helloWorld.js
|
||||
|
||||
addEventListener('fetch', event => {
|
||||
event.respondWith(handleRequest(event.request))
|
||||
})
|
||||
|
||||
async function handleRequest(request) {
|
||||
return new Response("Hello world")
|
||||
}
|
||||
```
|
||||
|
||||
If you have an Enterprise Cloudflare account, you can add multiple Cloudflare Workers to your project.
|
||||
|
||||
```yml
|
||||
# serverless.yml
|
||||
|
||||
service:
|
||||
name: hello-world
|
||||
config:
|
||||
accountId: CLOUDFLARE_ACCOUNT_ID
|
||||
zoneId: CLOUDFLARE_ZONE_ID
|
||||
workers:
|
||||
hello:
|
||||
routes:
|
||||
- example.com/hello/*
|
||||
foo_script:
|
||||
routes:
|
||||
- example.com/foo/*
|
||||
|
||||
provider:
|
||||
name: cloudflare
|
||||
|
||||
plugins:
|
||||
- serverless-cloudflare-workers
|
||||
|
||||
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 are only relevant to the `serverless invoke` command and don’t affect deployment in any way
|
||||
events:
|
||||
- http:
|
||||
url: example.com/hello/user
|
||||
method: GET
|
||||
headers:
|
||||
someKey: someValue
|
||||
|
||||
|
||||
# Only Enterprise accounts would be allowed to add this second function and its corresponding route above
|
||||
foo:
|
||||
worker: foo_script
|
||||
script: bar
|
||||
events:
|
||||
- http:
|
||||
url: example.com/foo/bar
|
||||
method: GET
|
||||
```
|
||||
The `script` property is what the Cloudflare Worker will be called on Cloudflare’s data centers.
|
||||
|
||||
The `events` property is optional and is only relevant for using the `serverless invoke` command. Check out the [`events`](./events.md) guide for more information.
|
||||
57
docs/providers/cloudflare/guide/installation.md
Normal file
57
docs/providers/cloudflare/guide/installation.md
Normal file
@ -0,0 +1,57 @@
|
||||
<!--
|
||||
title: Serverless Framework - Cloudflare Workers Guide - Installing The Serverless Framework and Cloudflare Workers
|
||||
menuText: Installation
|
||||
menuOrder: 3
|
||||
description: How to install the Serverless Framework and start using it with Cloudflare Workers
|
||||
layout: Doc
|
||||
-->
|
||||
|
||||
<!-- DOCS-SITE-LINK:START automatically generated -->
|
||||
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/guide/installation)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
# Cloudflare Workers - Installation
|
||||
|
||||
## Installing Cloudflare Workers
|
||||
Cloudflare Workers don’t actually require any installation to run. However, 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.
|
||||
|
||||
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.
|
||||
|
||||
## Installing the Serverless Framework
|
||||
Next, install the Serverless Framework via [npm](https://npmjs.org) which was already installed when you installed Node.js.
|
||||
|
||||
Open up a terminal and type `npm install -g serverless` to install Serverless.
|
||||
|
||||
```bash
|
||||
npm install -g serverless
|
||||
```
|
||||
|
||||
Once the installation process is done you can verify that Serverless is installed successfully by running the following command in your terminal:
|
||||
|
||||
```bash
|
||||
serverless
|
||||
```
|
||||
|
||||
To see which version of serverless you have installed run:
|
||||
|
||||
```bash
|
||||
serverless --version
|
||||
```
|
||||
|
||||
Remember, you need at least version 1.31.0 to use Cloudflare Workers with Serverless.
|
||||
109
docs/providers/cloudflare/guide/intro.md
Normal file
109
docs/providers/cloudflare/guide/intro.md
Normal file
@ -0,0 +1,109 @@
|
||||
<!--
|
||||
title: Serverless Framework - Cloudflare Workers Guide - Introduction
|
||||
menuText: Intro
|
||||
menuOrder: 1
|
||||
description: An introduction to using Cloudflare Workers with 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/cloudflare/guide/intro)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
|
||||
# Cloudflare Workers - Introduction
|
||||
|
||||
The Serverless Framework helps you develop and deploy serverless applications using [Cloudflare Workers](https://www.cloudflare.com/products/cloudflare-workers/). It's a CLI that offers structure, automation, and best practices out-of-the-box, allowing you to focus on building sophisticated, event-driven, serverless architectures, comprised of [Functions](#functions) and [Events](#events). It lets you manage your Worker routing in a flat configuration file that you can keep in alongside the rest of your code in version control, and the Serverless Framework will intelligently manage your routes as they change.
|
||||
|
||||
The Serverless Framework is different than other application frameworks because:
|
||||
* It manages your code as well as your infrastructure
|
||||
* It supports multiple languages (Although Cloudflare Workers only supports Javascript for now)
|
||||
|
||||
## Core Concepts
|
||||
Here are the Serverless Framework's main concepts and how they pertain to Cloudflare Workers.
|
||||
|
||||
### Functions
|
||||
A Function is a Cloudflare Worker. It's an independent unit of deployment, like a microservice. It's merely code, deployed on Cloudflare’s 152+ PoPs (points of presence), that is most often written to perform a single job, such as:
|
||||
* *Performing A/B Testing*
|
||||
* *Custom routing based on user location, custom headers, etc.*
|
||||
* *Hosting webhook endpoints*
|
||||
|
||||
### Events
|
||||
Anything that triggers a Cloudflare Worker Event to execute is regarded by the Framework as an **Event**. The only event that triggers a Cloudflare Worker is an HTTP request. Since the only event that can trigger a Worker is an HTTP request, declaring events is optional, and only used to declare specific endpoints that can be called by [`serverless invoke`](../cli-reference/invoke.md). This is useful for defining specific hooks into your application for testing.
|
||||
|
||||
### Services
|
||||
A **Service** is the Serverless Framework's unit of organization. You can think of it as a project file, though you can have multiple services for a single application. It's where you define your Functions and the routes they will live on, all in one file entitled `serverless.yml`. Non-Enterprise Cloudflare accounts can only deploy one function (that can be deployed to multiple routes), while Enterprise Cloudflare accounts can deploy multiple functions at once:
|
||||
|
||||
```yml
|
||||
# serverless.yml
|
||||
|
||||
service:
|
||||
name: hello-world
|
||||
config:
|
||||
accountId: CLOUDFLARE_ACCOUNT_ID
|
||||
zoneId: CLOUDFLARE_ZONE_ID
|
||||
workers:
|
||||
hello:
|
||||
routes:
|
||||
- example.com/hello/*
|
||||
foo_script:
|
||||
routes:
|
||||
- example.com/foo/*
|
||||
|
||||
provider:
|
||||
name: cloudflare
|
||||
|
||||
plugins:
|
||||
- serverless-cloudflare-workers
|
||||
|
||||
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 are only relevant to the `serverless invoke` command and don’t affect deployment in any way
|
||||
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:
|
||||
someKey: someValue
|
||||
|
||||
|
||||
# Only Enterprise accounts would be allowed to add this second function and its corresponding route above
|
||||
foo:
|
||||
worker: foo_script
|
||||
script: bar
|
||||
events:
|
||||
- http:
|
||||
url: example.com/foo/bar
|
||||
method: GET
|
||||
```
|
||||
|
||||
You get your `accountId` by grabbing it from the URL when using the [Cloudflare dashboard](https://dash.cloudflare.com), and your `zoneId` from the `overview` tab after selecting the desired zone from the [Cloudflare dashboard](https://dash.cloudflare.com).
|
||||
|
||||
You will also 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.
|
||||
|
||||
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.
|
||||
|
||||
If you’re not an enterprise customer and you want to execute different code on multiple routes with only one funciton, we recommend writing code based off of our [conditional routing](https://developers.cloudflare.com/workers/recipes/conditional-routing/) template to check your route and execute different code accordingly. You can also write workers in separate files and compile it into one worker with [webpack](https://developers.cloudflare.com/workers/writing-workers/using-npm-modules/).
|
||||
|
||||
When you deploy with the Framework by running `serverless deploy`, everything in `serverless.yml` is deployed at once.
|
||||
106
docs/providers/cloudflare/guide/quick-start.md
Normal file
106
docs/providers/cloudflare/guide/quick-start.md
Normal file
@ -0,0 +1,106 @@
|
||||
<!--
|
||||
title: Serverless Framework - Workers Guide - Quick Start
|
||||
menuText: Quick Start
|
||||
menuOrder: 2
|
||||
description: Getting started with the Serverless Framework on Cloudflare Workers
|
||||
layout: Doc
|
||||
-->
|
||||
|
||||
<!-- DOCS-SITE-LINK:START automatically generated -->
|
||||
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/guide/quick-start)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
# Cloudflare Workers - Quickstart
|
||||
|
||||
## Pre-requisites
|
||||
Node.js `v6.5.0` or later.
|
||||
Serverless CLI `v1.31.0` or later. You can run `npm install -g serverless` to install it.
|
||||
|
||||
## Create a new service
|
||||
Create a new service using either the `cloudflare-workers` or `cloudflare-workers-enterprise` template, depending on your Cloudflare domain’s plan level, and specifying a unique name and an optional path for your service.
|
||||
|
||||
```bash
|
||||
# Create a new Serverless Service/Project
|
||||
$ serverless create --template cloudflare-workers --path new-project
|
||||
# Change into the newly created directory
|
||||
$ cd new-project
|
||||
# Install npm dependencies
|
||||
$ npm install
|
||||
```
|
||||
|
||||
Note: there are two templates for [Cloudflare Workers](https://www.cloudflare.com/products/cloudflare-workers/): `cloudflare-workers` and `cloudflare-workers-enterprise`. The enterprise template sets up a project that can natively deploy [multiple scripts](https://developers.cloudflare.com/workers/api/config-api-for-enterprise/), each with their own routes. It requires an enterprise Cloudflare account to use.
|
||||
|
||||
The `cloudflare-workers` template still supports [conditional routing](https://developers.cloudflare.com/workers/recipes/conditional-routing/) and multiple scripts if you use a tool like [webpack](https://developers.cloudflare.com/workers/writing-workers/using-npm-modules/).
|
||||
|
||||
## Deploy, test and diagnose your service
|
||||
|
||||
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.
|
||||
|
||||
1. **Deploy the Service**
|
||||
|
||||
Use this when you have made changes to your Functions, Events or Resources in `serverless.yml` or you simply want to deploy all changes within your Service at the same time. If you've made changes to your routes since last deploying, the Serverless Framework will update them on the server for you.
|
||||
|
||||
```bash
|
||||
serverless deploy
|
||||
```
|
||||
|
||||
2. **Deploy the Function**
|
||||
|
||||
Use this to quickly upload and overwrite your function code, allowing you to develop faster.
|
||||
|
||||
```bash
|
||||
serverless deploy -f hello
|
||||
```
|
||||
|
||||
3. **Invoke the Function**
|
||||
|
||||
Invokes the Function and returns results.
|
||||
|
||||
```bash
|
||||
serverless invoke --function helloWorld
|
||||
|
||||
Hello world
|
||||
```
|
||||
|
||||
Note that for `invoke`, your Function must have the `events` field populated in order for the `serverless` tool to know exactly which route to request. Defining the `headers` field is optional.
|
||||
|
||||
```yml
|
||||
# serverless.yml
|
||||
...
|
||||
foo:
|
||||
worker: foo_script
|
||||
script: bar
|
||||
events:
|
||||
- http:
|
||||
url: example.com/foo/bar
|
||||
# Defines the method used by serverless when the `invoke` command is used. Cloudflare Workers only support GET requests for now
|
||||
method: GET
|
||||
headers:
|
||||
someKey: someValue
|
||||
```
|
||||
|
||||
|
||||
## Cleanup
|
||||
If at any point, you no longer need your service, you can run the following command to remove the Functions, Events and Resources that were created.
|
||||
|
||||
```bash
|
||||
serverless remove
|
||||
```
|
||||
202
docs/providers/cloudflare/guide/services.md
Normal file
202
docs/providers/cloudflare/guide/services.md
Normal file
@ -0,0 +1,202 @@
|
||||
<!--
|
||||
title: Serverless Framework - Cloudflare Workers Guide - Services
|
||||
menuText: Services
|
||||
menuOrder: 4
|
||||
description: How to manage and configure Serverless services, which contain your Cloudflare Workers and their events.
|
||||
layout: Doc
|
||||
-->
|
||||
|
||||
<!-- DOCS-SITE-LINK:START automatically generated -->
|
||||
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/guide/services)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
# Cloudflare Workers - Services
|
||||
|
||||
A `service` is like a project. It's where you define your Cloudflare Workers and the `events` you test them with, all in a file called `serverless.yml`.
|
||||
|
||||
To get started building your first Serverless Framework project, create a `service`.
|
||||
|
||||
## Organization
|
||||
|
||||
In the beginning of an application created by a team with an Enterprise Cloudflare account, and for the lifespan of an application made by a team with a Non-Enterprise Cloudflare account, we recommend you use a single Service to define all of the Functions and Events for that project.
|
||||
|
||||
```bash
|
||||
myService/
|
||||
serverless.yml # Contains all functions and infrastructure resources
|
||||
```
|
||||
|
||||
However, as your application grows as an Enterprise Cloudflare user, you can break it out into multiple services. A lot of people organize their services by workflows or data models, and group the functions related to those workflows and data models together in the service.
|
||||
|
||||
```bash
|
||||
users/
|
||||
serverless.yml # Contains 4 functions that do Users CRUD operations and the Users database
|
||||
posts/
|
||||
serverless.yml # Contains 4 functions that do Posts CRUD operations and the Posts database
|
||||
comments/
|
||||
serverless.yml # Contains 4 functions that do Comments CRUD operations and the Comments database
|
||||
```
|
||||
|
||||
This makes sense since related functions usually use common infrastructure resources, and you want to keep those functions and resources together as a single unit of deployment, for better organization and separation of concerns.
|
||||
|
||||
## Creation
|
||||
|
||||
To create a service, use the `create` command. You can also pass in a path to create a directory and auto-name your service:
|
||||
|
||||
```bash
|
||||
# Create service with cloudflare-workers template in the folder ./my-service
|
||||
serverless create --template cloudflare-workers --path my-service
|
||||
```
|
||||
|
||||
Here are the available runtimes for Cloudflare Workers:
|
||||
|
||||
* cloudflare-workers
|
||||
* cloudflare-workers-enterprise
|
||||
|
||||
Check out the [create command docs](../cli-reference/create) for all the details and options.
|
||||
|
||||
## Contents
|
||||
|
||||
You'll see the following files in your working directory:
|
||||
|
||||
- `serverless.yml`
|
||||
- `helloWorld.js`
|
||||
|
||||
### serverless.yml
|
||||
|
||||
Each `service` configuration is managed in the `serverless.yml` file. The main responsibilities of this file are:
|
||||
|
||||
- Declare a Serverless service
|
||||
- Define one or more functions in the service
|
||||
- Define the provider the service will be deployed to
|
||||
- Define any custom plugins to be used
|
||||
- Define events that trigger each function to execute (e.g. HTTP requests)
|
||||
- Allow events listed in the `events` section to automatically create the resources required for the `serverless invoke` command
|
||||
|
||||
You can see the name of the service, the provider configuration and the first function inside the `functions` definition. Any further service configuration will be done in this file.
|
||||
|
||||
```yml
|
||||
# serverless.yml
|
||||
|
||||
service:
|
||||
name: hello-world
|
||||
config:
|
||||
accountId: CLOUDFLARE_ACCOUNT_ID
|
||||
zoneId: CLOUDFLARE_ZONE_ID
|
||||
workers:
|
||||
hello:
|
||||
routes:
|
||||
- example.com/hello/*
|
||||
foo_script:
|
||||
routes:
|
||||
- example.com/foo/*
|
||||
|
||||
provider:
|
||||
name: cloudflare
|
||||
|
||||
plugins:
|
||||
- serverless-cloudflare-workers
|
||||
|
||||
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 are only relevant to the `serverless invoke` command and don’t affect deployment in any way
|
||||
events:
|
||||
- http:
|
||||
url: example.com/hello/user
|
||||
method: GET
|
||||
headers:
|
||||
someKey: someValue
|
||||
|
||||
|
||||
# Only Enterprise accounts would be allowed to add this second function and its corresponding route above
|
||||
foo:
|
||||
worker: foo_script
|
||||
script: bar
|
||||
events:
|
||||
- http:
|
||||
url: example.com/foo/bar
|
||||
method: GET
|
||||
|
||||
```
|
||||
|
||||
### helloWorld.js
|
||||
|
||||
The `helloWorld.js` file contains a barebones Cloudflare Worker that returns ‘hello world’.
|
||||
|
||||
## Deployment
|
||||
|
||||
When you deploy a Service, all of the Functions, and Events in your `serverless.yml` are translated into calls to Cloudflare to create your Cloudflare Worker(s).
|
||||
|
||||
To deploy a service, first `cd` into the relevant service directory:
|
||||
|
||||
```bash
|
||||
cd my-service
|
||||
```
|
||||
|
||||
Then use the `deploy` command:
|
||||
|
||||
```bash
|
||||
serverless deploy
|
||||
```
|
||||
|
||||
Check out the [deployment guide](./deploying.md) to learn more about deployments and how they work. Or, check out the [deploy command docs](../cli-reference/deploy.md) for all the details and options.
|
||||
|
||||
## Removal
|
||||
|
||||
To easily remove your Service from Cloudflare’s data centers, you can use the `remove` command.
|
||||
|
||||
Run `serverless remove` to trigger the removal process.
|
||||
|
||||
Serverless will start the removal and informs you about it's process on the console. A success message is printed once the whole service is removed.
|
||||
|
||||
The removal process will only remove the service on your provider's infrastructure. The service directory will still remain on your local machine so you can still modify and (re)deploy it to another stage, region or provider later on.
|
||||
|
||||
## Version Pinning
|
||||
|
||||
The Serverless framework is usually installed globally via `npm install -g serverless`. This way you have the Serverless CLI available for all your services.
|
||||
|
||||
Installing tools globally has the downside that the version can't be pinned inside package.json. This can lead to issues if you upgrade Serverless, but your colleagues or CI system don't. You can use a feature in your serverless.yml without worrying that your CI system will deploy with an old version of Serverless.
|
||||
|
||||
### Pinning a Version
|
||||
|
||||
To configure version pinning define a `frameworkVersion` property in your serverless.yaml. Whenever you run a Serverless command from the CLI it checks if your current Serverless version is matching the `frameworkVersion` range. The CLI uses [Semantic Versioning](http://semver.org/) so you can pin it to an exact version or provide a range. In general we recommend to pin to an exact version to ensure everybody in your team has the exact same setup and no unexpected problems happen.
|
||||
|
||||
### Examples
|
||||
|
||||
#### Exact Version
|
||||
|
||||
```yml
|
||||
# serverless.yml
|
||||
|
||||
frameworkVersion: "=1.0.3"
|
||||
```
|
||||
|
||||
#### Version Range
|
||||
|
||||
```yml
|
||||
# serverless.yml
|
||||
|
||||
frameworkVersion: ">=1.0.0 <2.0.0"
|
||||
```
|
||||
|
||||
|
||||
## Installing Serverless in an existing service
|
||||
|
||||
If you already have a Serverless service, and would prefer to lock down the framework version using `package.json`, then you can install Serverless as follows:
|
||||
|
||||
```bash
|
||||
# from within a service
|
||||
npm install serverless --save-dev
|
||||
```
|
||||
|
||||
### Invoking Serverless locally
|
||||
|
||||
To execute the locally installed Serverless executable you have to reference the binary out of the node modules directory.
|
||||
|
||||
Example:
|
||||
```
|
||||
node ./node_modules/serverless/bin/serverless deploy
|
||||
```
|
||||
58
docs/providers/cloudflare/guide/workflow.md
Normal file
58
docs/providers/cloudflare/guide/workflow.md
Normal file
@ -0,0 +1,58 @@
|
||||
<!--
|
||||
title: Serverless Framework Guide - Cloudflare Workers - Workflow
|
||||
menuText: Workflow
|
||||
menuOrder: 9
|
||||
description: A guide and cheatsheet containing CLI commands and workflow recommendations.
|
||||
layout: Doc
|
||||
-->
|
||||
|
||||
<!-- DOCS-SITE-LINK:START automatically generated -->
|
||||
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/cloudflare/guide/workflow)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
|
||||
# Cloudflare Workers - Workflow
|
||||
Generally, Cloudflare Workers can be written locally, deployed with serverless, and tested with the [`serverless invoke`](../cli-reference/invoke.md) command. However, using the [Cloudflare Workers Playground](https://cloudflareworkers.com/#) can help you test and view your worker’s results live if you need more insight while developing your Cloudflare Worker.
|
||||
|
||||
Below is a list of general tips for developing Cloudflare Workers with Serverless.
|
||||
|
||||
### Development Workflow
|
||||
Write your functions
|
||||
Use `serverless deploy` only when you've made changes to `serverless.yml` and in CI/CD systems.
|
||||
Use `serverless deploy -f myFunction` to rapidly deploy changes when you are working on a specific Cloudflare Workers Function.
|
||||
Use `serverless invoke -f myFunction` to test your Cloudflare Workers Functions.
|
||||
### Larger Projects
|
||||
* For Non-Enterprise Cloudflare customers, combining multiple workers into one file or using [webpack](https://developers.cloudflare.com/workers/writing-workers/using-npm-modules/).
|
||||
* Keep the Functions and Resources in your Serverless Services to a minimum.
|
||||
## Cheat Sheet
|
||||
A handy list of commands to use when developing with the Serverless Framework.
|
||||
|
||||
##### Create A Service:
|
||||
Creates a new Service:
|
||||
|
||||
```bash
|
||||
serverless create -p [SERVICE NAME] -t cloudflare-workers
|
||||
```
|
||||
|
||||
##### Deploy All
|
||||
Use this when you have made changes to your Functions, Events or Resources in `serverless.yml` or you simply want to deploy all changes within your Service at the same time.
|
||||
|
||||
```bash
|
||||
serverless deploy
|
||||
```
|
||||
|
||||
|
||||
##### Deploy Function
|
||||
Use this to quickly overwrite your Cloudflare Workers Functions, allowing you to develop faster if you have an Enterprise account that supports deploying multiple functions.
|
||||
|
||||
```bash
|
||||
serverless deploy -f [FUNCTION NAME]
|
||||
```
|
||||
|
||||
|
||||
##### Invoke Function
|
||||
Invokes a Cloudflare Workers Function.
|
||||
|
||||
```bash
|
||||
serverless invoke -f [FUNCTION NAME]
|
||||
```
|
||||
@ -17,7 +17,7 @@ layout: Doc
|
||||
Invokes deployed function locally. It allows to send event data to the function, read logs and display other important information of the function invocation.
|
||||
|
||||
```bash
|
||||
serverless invoke -f functionName
|
||||
serverless invoke local -f functionName
|
||||
```
|
||||
|
||||
## Options
|
||||
@ -28,6 +28,7 @@ serverless invoke -f functionName
|
||||
* `--raw` Pass data as a raw string even if it is JSON. If not set, JSON data are parsed and passed as an object.
|
||||
* `--contextPath` or `-x`, The path to a json file holding input context to be passed to the invoked function. This path is relative to the root directory of the service.
|
||||
* `--context` or `-c`, String data to be passed as a context to your function. Same like with `--data`, context included in `--contextPath` will overwrite the context you passed with `--context` flag.
|
||||
* `--env` or `-e` String representing an environment variable to set when invoking your function, in the form `<name>=<value>`. Can be repeated for more than one environment variable.
|
||||
|
||||
> Keep in mind that if you pass both `--path` and `--data`, the data included in the `--path` file will overwrite the data you passed with the `--data` flag.
|
||||
|
||||
@ -54,3 +55,13 @@ serverless invoke local -f functionName -p path/to/file.json
|
||||
|
||||
serverless invoke local -f functionName -p path/to/file.yaml
|
||||
```
|
||||
|
||||
### Local function invocation, setting environment variables
|
||||
|
||||
```bash
|
||||
serverless invoke local -f functionName -e VAR1=value1
|
||||
|
||||
# Or more than one variable
|
||||
|
||||
serverless invoke local -f functionName -e VAR1=value1 -e VAR2=value2
|
||||
```
|
||||
|
||||
@ -25,6 +25,7 @@ __*Please note that only the JavaScript and Python runtimes are supported with t
|
||||
- `--function` or `-f` The name of the function in your service that you want to invoke locally. **Required**.
|
||||
- `--path` or `-p` The path to a json file holding input data to be passed to the invoked function. This path is relative to the root directory of the service. The json file should have event and context properties to hold your mocked event and context data.
|
||||
- `--data` or `-d` String data to be passed as an event to your function. Keep in mind that if you pass both `--path` and `--data`, the data included in the `--path` file will overwrite the data you passed with the `--data` flag.
|
||||
* `--env` or `-e` String representing an environment variable to set when invoking your function, in the form `<name>=<value>`. Can be repeated for more than one environment variable.
|
||||
|
||||
## Examples
|
||||
|
||||
@ -60,6 +61,16 @@ serverless invoke local --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.
|
||||
|
||||
### Local function invocation, setting environment variables
|
||||
|
||||
```bash
|
||||
serverless invoke local -f functionName -e VAR1=value1
|
||||
|
||||
# Or more than one variable
|
||||
|
||||
serverless invoke local -f functionName -e VAR1=value1 -e VAR2=value2
|
||||
```
|
||||
|
||||
### Limitations
|
||||
|
||||
Currently, `invoke local` only supports the NodeJs and Python runtimes.
|
||||
|
||||
@ -1,37 +0,0 @@
|
||||
<!--
|
||||
title: Serverless - Webtasks Documentation
|
||||
menuText: Webtasks
|
||||
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 -->
|
||||
|
||||
# Webtasks Provider Documentation
|
||||
|
||||
Welcome to the Serverless Webtasks documentation!
|
||||
|
||||
If you have questions specific to the Webtasks provider, please join our [Slack](http://chat.webtask.io).
|
||||
|
||||
For general Serverless Framework 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)
|
||||
|
||||
#### Quick Start
|
||||
|
||||
- <a href="./guide/intro.md">Intro</a>
|
||||
- <a href="./guide/quick-start.md">Quick Start</a>
|
||||
|
||||
#### CLI reference
|
||||
|
||||
- <a href="./cli-reference/config-credentials.md">Config Credentials</a>
|
||||
- <a href="./cli-reference/create.md">Create</a>
|
||||
- <a href="./cli-reference/deploy.md">Deploy</a>
|
||||
- <a href="./cli-reference/invoke.md">Invoke</a>
|
||||
- <a href="./cli-reference/logs.md">Logs</a>
|
||||
- <a href="./cli-reference/info.md">Info</a>
|
||||
- <a href="./cli-reference/remove.md">Remove</a>
|
||||
|
||||
#### Events
|
||||
|
||||
- <a href="./events/http.md">http event</a>
|
||||
- <a href="./events/schedule.md">Schedule event</a>
|
||||
@ -1,19 +0,0 @@
|
||||
<!--
|
||||
title: Serverless - Auth0 Webtasks - 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/webtasks/cli-reference/)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
# Serverless Auth0 Webtasks CLI Reference
|
||||
|
||||
Welcome to the Serverless Auth0 Webtasks CLI Reference!
|
||||
|
||||
Please select a section on the left to get started.
|
||||
|
||||
If you have questions specific to the Webtasks provider, please join our [Slack](http://chat.webtask.io). For general Serverless Framework questions, join the [chat in gitter](https://gitter.im/serverless/serverless) or [post over on the forums](http://forum.serverless.com/)
|
||||
|
||||
**Note:** A local profile is required to use Auth0 Webtasks with the Serverless Framework. Follow the steps in the [Quick Start](../quick-start.md) to get setup in less than a minute.
|
||||
@ -1,21 +0,0 @@
|
||||
<!--
|
||||
title: Serverless Framework Commands - Auth0 Webtasks - Config Credentials
|
||||
menuText: config credentials
|
||||
menuOrder: 1
|
||||
description: Configure Serverless credentials for Auth0 Webtasks with 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/webtasks/cli-reference/config-credentials)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
# Auth0 Webtasks - Config Credentials
|
||||
|
||||
Before you are able to use the Auth0 Webtasks platform with the Serverless Framework, you will need to setup a local profile. Fortunately, this takes less than a minute.
|
||||
|
||||
```bash
|
||||
serverless config credentials --provider webtasks
|
||||
```
|
||||
|
||||
You will be asked for a phone number or email. You'll immediately receive a verification code. Enter the verification code and your profile will be entirely setup and ready to use.
|
||||
@ -1,71 +0,0 @@
|
||||
<!--
|
||||
title: Serverless Framework Commands - Auth0 Webtasks - Create
|
||||
menuText: create
|
||||
menuOrder: 2
|
||||
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/webtasks/cli-reference/create)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
# Auth0 Webtasks - Create
|
||||
|
||||
Creates a new service in the current working directory based on the specified Auth0 Webtasks template.
|
||||
|
||||
**Create service in current working directory:**
|
||||
|
||||
```bash
|
||||
serverless create --template webtasks-nodejs
|
||||
```
|
||||
|
||||
**Create service in new folder:**
|
||||
|
||||
```bash
|
||||
serverless create --template webtasks-nodejs --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`.
|
||||
|
||||
## Available Templates
|
||||
|
||||
To see a list of available templates run `serverless create --help`
|
||||
|
||||
The only template available for use with the Auth0 Webtasks platform is:
|
||||
|
||||
- webtasks-nodejs
|
||||
|
||||
## Examples
|
||||
|
||||
### Creating a new service
|
||||
|
||||
```bash
|
||||
serverless create --template webtasks-nodejs --name my-special-service
|
||||
```
|
||||
|
||||
This example will generate scaffolding for a service with `webtasks` 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 webtasks-nodejs --path my-new-service
|
||||
```
|
||||
|
||||
This example will generate scaffolding for a service with `webtasks` 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`.
|
||||
@ -1,45 +0,0 @@
|
||||
<!--
|
||||
title: Serverless Framework Commands - Auth0 Webtasks - Deploy
|
||||
menuText: deploy
|
||||
menuOrder: 5
|
||||
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/webtasks/cli-reference/deploy)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
# Auth0 Webtasks - deploy
|
||||
|
||||
The `serverless deploy` command deploys either your entire service or a single Function of your service to the Auth0 Webtasks platform.
|
||||
|
||||
```bash
|
||||
serverless deploy
|
||||
```
|
||||
|
||||
## Options
|
||||
- `--stage` or `-s` The stage in your service that you want to deploy to. The default stage is 'dev'.
|
||||
- `--profile` or `-p` The Auth0 Webtasks profile to use when deploying your service. The 'serverless' profile is used by default.
|
||||
|
||||
## Examples
|
||||
|
||||
### Deploying an entire service
|
||||
|
||||
```bash
|
||||
serverless deploy
|
||||
```
|
||||
|
||||
This example will deploy all of the Functions specified in the service to the Auth0 Webtasks platform. If a given function was previously deployed, it will be re-deployed with the current version of the code.
|
||||
|
||||
All of the Functions will be deployed with the default 'dev' stage. Functions deployed to different stages are different webtasks on the Auth0 Webtasks platform and therefore have distinct URLs.
|
||||
|
||||
### Deploying a single function
|
||||
|
||||
```bash
|
||||
serverless deploy function -f main
|
||||
```
|
||||
|
||||
This example will deploy only the 'main' function to the Auth0 Webtasks platform. If the 'main' function was previously deployed, it will be re-deployed with the current version of the code.
|
||||
|
||||
The 'main' Function will be deployed with the default 'dev' stage.
|
||||
@ -1,46 +0,0 @@
|
||||
<!--
|
||||
title: Serverless Framework Commands - Auth0 Webtasks - Info
|
||||
menuText: info
|
||||
menuOrder: 12
|
||||
description: Display information about your deployed service and the Auth0 Webtasks Functions, Events.
|
||||
layout: Doc
|
||||
-->
|
||||
|
||||
<!-- DOCS-SITE-LINK:START automatically generated -->
|
||||
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/webtasks/cli-reference/info)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
# Auth0 Webtasks - Info
|
||||
|
||||
Displays information about the deployed service.
|
||||
|
||||
```bash
|
||||
serverless info
|
||||
```
|
||||
|
||||
## Options
|
||||
- `--stage` or `-s` The stage in your service you want to display information about. The default stage is 'dev'.
|
||||
- `--profile` or `-p` The Auth0 Webtasks profile to use when deploying your service. The 'serverless' profile is used by default.
|
||||
|
||||
## Provided lifecycle events
|
||||
- `info:info`
|
||||
|
||||
## Examples
|
||||
|
||||
### Getting info on a service
|
||||
|
||||
```bash
|
||||
serverless info
|
||||
```
|
||||
|
||||
This example will display information about the deployed service for the default 'dev' stage. It will list the endpoints with the URL for each webtask.
|
||||
|
||||
### Getting info on a given stage of the service
|
||||
|
||||
```bash
|
||||
serverless info --stage prod
|
||||
```
|
||||
|
||||
This example will display information about the deployed service for the 'prod' stage. It will list the endpoints with the URL for each webtask.
|
||||
|
||||
Functions deployed to different stages are different webtasks on the Auth0 Webtasks platform and therefore have distinct URLs.
|
||||
@ -1,63 +0,0 @@
|
||||
<!--
|
||||
title: Serverless Framework Commands - Auth0 Webtasks - Invoke
|
||||
menuText: invoke
|
||||
menuOrder: 8
|
||||
description: Invoke an Auth0 Webtask 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/webtasks/cli-reference/invoke)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
# Auth0 Webtasks - Invoke
|
||||
|
||||
Invokes a deployed Function. It allows you to send event data to the Function and returns the response.
|
||||
|
||||
```bash
|
||||
serverless invoke --function functionName
|
||||
```
|
||||
|
||||
## Options
|
||||
- `--function` or `-f` The name of the function in your service that you want to invoke. **Required**.
|
||||
- `--stage` or `-s` The stage in your service that you want to deploy to. The default stage is 'dev'.
|
||||
- `--profile` or `-p` The Auth0 Webtasks profile to use when deploying your service. The 'serverless' profile is used by default.
|
||||
- `--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.
|
||||
|
||||
## Provided lifecycle events
|
||||
- `invoke:invoke`
|
||||
|
||||
## Examples
|
||||
|
||||
### Invoking a Function
|
||||
|
||||
```bash
|
||||
serverless invoke --function main
|
||||
```
|
||||
|
||||
This example will invoke the 'main' function for the default 'dev' stage. The webtask will be invoked with an HTTP POST request by default. The command will return the HTTP status code and body of the response.
|
||||
|
||||
### Invoking a Function with data
|
||||
|
||||
```bash
|
||||
serverless invoke --function main --data '{"message":"Serverless + Webtasks!"}'
|
||||
```
|
||||
|
||||
This example will invoke the 'main' function for the default 'dev' stage. The webtask will be invoked with an HTTP POST and a request body that includes the JSON payload: `{"message":"Serverless + Webtasks!"}`.
|
||||
|
||||
### Invoking a Function with specific HTTP method
|
||||
|
||||
```bash
|
||||
serverless invoke --function main --data '{"method":"GET", "body":{"message":"Serverless + Webtasks!"}}'
|
||||
```
|
||||
|
||||
This example will invoke the 'main' function for the default 'dev' stage. The webtask will be invoked with an HTTP GET request and a request body that includes the JSON payload: `{"message":"Serverless + Webtasks!"}`.
|
||||
|
||||
### Invoking a Function with a request query string
|
||||
|
||||
```bash
|
||||
serverless invoke --function main --data '{"query":{"message":"Serverless + Webtasks!"}}'
|
||||
```
|
||||
|
||||
This example will invoke the 'main' function for the default 'dev' stage. The webtask will be invoked with an HTTP POST request and a request query string: `?message=Serverless%20%2B%20Webtasks!`.
|
||||
@ -1,25 +0,0 @@
|
||||
<!--
|
||||
title: Serverless Framework Commands - Auth0 Webtasks - Logs
|
||||
menuText: logs
|
||||
menuOrder: 10
|
||||
description: View logs of your Auth0 Webtask Function within your terminal 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/webtasks/cli-reference/logs)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
# Auth0 Webtasks - Logs
|
||||
|
||||
The `serverless logs` command will allow you to connect to the streaming real-time logs from your profile on the Auth0 Webtasks platform.
|
||||
|
||||
```bash
|
||||
serverless logs
|
||||
```
|
||||
|
||||
**Note:** The logs are streamed in real-time and not persisted. If none of your webtasks are currently executing, you will not see any log entries.
|
||||
|
||||
## Options
|
||||
|
||||
There are no options for this command.
|
||||
@ -1,46 +0,0 @@
|
||||
<!--
|
||||
title: Serverless Framework Commands - Auth0 Webtasks - Remove
|
||||
menuText: remove
|
||||
menuOrder: 15
|
||||
description: Remove a deployed Service and all of its Auth0 Webtask Functions, Events and Resources
|
||||
layout: Doc
|
||||
-->
|
||||
|
||||
<!-- DOCS-SITE-LINK:START automatically generated -->
|
||||
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/webtasks/cli-reference/remove)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
# Auth0 Webtasks - Remove
|
||||
|
||||
The `serverless remove` command will remove the deployed service, defined in your current working directory. All of the Functions deployed as webtasks on the Auth0 Webtasks platform will be removed.
|
||||
|
||||
```bash
|
||||
serverless remove
|
||||
```
|
||||
|
||||
## Options
|
||||
- `--stage` or `-s` The stage in your service that you want to deploy to. The default stage is 'dev'.
|
||||
- `--profile` or `-p` The Auth0 Webtasks profile to use when deploying your service. The 'serverless' profile is used by default.
|
||||
|
||||
## Provided lifecycle events
|
||||
- `remove:remove`
|
||||
|
||||
## Examples
|
||||
|
||||
### Removing the default 'dev' service
|
||||
|
||||
```bash
|
||||
serverless remove
|
||||
```
|
||||
|
||||
This example will remove the deployed service for the default 'dev' stage. None of the endpoints for the Functions in the 'deve' stage of the service will be available afterwards.
|
||||
|
||||
### Removing a given default stage of the service
|
||||
|
||||
```bash
|
||||
serverless info --stage prod
|
||||
```
|
||||
|
||||
This example will remove the deployed service for the 'prod' stage. None of the endpoints for the Functions in the 'prod' stage of the service will be available afterwards.
|
||||
|
||||
Functions deployed to different stages are different webtasks on the Auth0 Webtasks platform and therefore have distinct URLs.
|
||||
@ -1,19 +0,0 @@
|
||||
<!--
|
||||
title: Serverless - Auth0 Webtasks - Events
|
||||
menuText: Auth0 Webtasks Events
|
||||
layout: Doc
|
||||
-->
|
||||
|
||||
<!-- DOCS-SITE-LINK:START automatically generated -->
|
||||
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/webtasks/events/)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
# Serverless Auth0 Webtasks Events
|
||||
|
||||
Welcome to the Serverless Auth0 Webtasks Events Glossary.
|
||||
|
||||
Please select a section on the left to get started.
|
||||
|
||||
If you have questions specific to the Webtasks provider, please join our [Slack](http://chat.webtask.io). For general Serverless Framework questions, join the [chat in gitter](https://gitter.im/serverless/serverless) or [post over on the forums](http://forum.serverless.com/)
|
||||
|
||||
**Note:** A local profile is required to use Auth0 Webtasks with the Serverless Framework. Follow the steps in the [Quick Start](../quick-start.md) to get setup in less than a minute.
|
||||
@ -1,23 +0,0 @@
|
||||
<!--
|
||||
title: Serverless Framework - Auth0 Webtasks Events - API Gateway
|
||||
menuText: http
|
||||
menuOrder: 1
|
||||
description: Setting up HTTP events with Auth0 Webtasks via 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/webtasks/events/apigateway)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
# Http Event
|
||||
|
||||
By default Functions with Auth0 Webtasks are configured to respond to HTTP events. The URL of the webtask is determined by name of the function. Also, any HTTP method can be used to invoke the webtask. Therefore, configuring a Function when using Auth0 webtasks for an HTTP event is as simple as specifing the handler file that contains your code.
|
||||
|
||||
```yml
|
||||
functions:
|
||||
hello:
|
||||
handler: handlerFile
|
||||
```
|
||||
|
||||
**Note:** Auth0 Webtasks only supports a single handler per file. Therefore, you do not need to specify the `method` like with other Serverless providers.
|
||||
@ -1,37 +0,0 @@
|
||||
<!--
|
||||
title: Serverless Framework - Auth0 Webtasks Events - Scheduled & Recurring
|
||||
menuText: schedule
|
||||
menuOrder: 4
|
||||
description: Setting up Scheduled, Recurring, CRON Task Events with Auth0 Webtasks via 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/webtasks/events/schedule)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
# Schedule
|
||||
|
||||
The following config will attach a schedule event and causes the function `crawl` to be called every 2 hours. Auth0 Webtasks only support a single schedule per Function.
|
||||
|
||||
You can either use the `rate` or `cron` syntax.
|
||||
|
||||
```yml
|
||||
functions:
|
||||
crawl:
|
||||
handler: crawl
|
||||
events:
|
||||
- schedule: rate(2 hours)
|
||||
```
|
||||
|
||||
or with default cron syntax
|
||||
|
||||
```yml
|
||||
functions:
|
||||
crawl:
|
||||
handler: crawl
|
||||
events:
|
||||
- schedule: cron(0 0/2 * * *)
|
||||
```
|
||||
|
||||
**Note:** Auth0 Webtasks supports the 5 field crontab format. [CronTab.guru](http://crontab.guru/) is a useful site for calculating cron schedules.
|
||||
@ -1,19 +0,0 @@
|
||||
<!--
|
||||
title: Serverless - Auth0 Webtasks
|
||||
menuText: Guide
|
||||
layout: Doc
|
||||
-->
|
||||
|
||||
<!-- DOCS-SITE-LINK:START automatically generated -->
|
||||
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/webtasks/guide/)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
# Serverless Auth0 Webtasks Guide
|
||||
|
||||
Welcome to the Serverless Auth0 Webtasks Guide!
|
||||
|
||||
Get started with the **[Introduction to the framework](./intro.md)**
|
||||
|
||||
If you have questions specific to the Webtasks provider, please join our [Slack](http://chat.webtask.io). For general Serverless Framework questions, join the [chat in gitter](https://gitter.im/serverless/serverless) or [post over on the forums](http://forum.serverless.com/)
|
||||
|
||||
**Note:** A local profile is required to use Auth0 Webtasks with the Serverless Framework. Follow the steps in the [Quick Start](../quick-start.md) to get setup in less than a minute.
|
||||
@ -1,66 +0,0 @@
|
||||
<!--
|
||||
title: Serverless Framework - Auth0 Webtasks - Introduction
|
||||
menuText: Intro
|
||||
menuOrder: 1
|
||||
description: An introduction to using Auth0 Webtasks with 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/webtasks/guide/intro)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
# Auth0 Webtasks - Introduction
|
||||
|
||||
The Serverless Framework helps you develop and deploy serverless applications using Auth0 Webtasks. The Serverless CLI offers structure, automation and best practices out-of-the-box. And with Auth0 Webtasks it's simple and easy to deploy code in just seconds.
|
||||
|
||||
**Note:** A local profile is required to use Auth0 Webtasks with the Serverless Framework. Follow the steps in the [Quick Start](quick-start.md) to get setup in less than a minute.
|
||||
|
||||
## Core Concepts
|
||||
|
||||
Here are the Framework's main concepts and how they pertain to Auth0 Webtasks...
|
||||
|
||||
### Services
|
||||
|
||||
A **Service** is the Framework's unit of organization. You can think of it as a project file, though you can have multiple services for a single application.
|
||||
|
||||
The Auth0 Webtasks platform was designed to be simple and easy to use with minimal configuration. Therefore, services that uses Auth0 Webtasks are just a few lines of configuration in a single file, entitled `serverless.yml` (or `serverless.json` or `serverless.js`). It looks like this:
|
||||
|
||||
```yml
|
||||
# serverless.yml
|
||||
|
||||
service: users
|
||||
|
||||
provider:
|
||||
name: webtasks
|
||||
|
||||
functions:
|
||||
user:
|
||||
handler: handler
|
||||
|
||||
plugins:
|
||||
- '@webtask/serverless-webtasks'
|
||||
```
|
||||
|
||||
### Functions
|
||||
|
||||
A Function is an independent unit of deployment, like a microservice. It's merely code, deployed in the cloud, that is most often written to perform just a single job. When using Auth0 Webtasks, a Function is implemented as a webtask on the Auth0 Webtasks platform.
|
||||
|
||||
You can perform multiple jobs in your code, but we don't recommend doing that without good reason. Separation of concerns is best and the Framework is designed to help you easily develop and deploy Functions, as well as manage lots of them.
|
||||
|
||||
### Events
|
||||
|
||||
By default, a webtask is configured to respond to HTTP events. The Auth0 Webtasks platform also supports scheduled events, so that your code can be invoked at a regular interval.
|
||||
|
||||
### Plugins
|
||||
|
||||
You can overwrite or extend the functionality of the Serverless Framework using **Plugins**. Every `serverless.yml` can contain a `plugins:` property, which features multiple plugins.
|
||||
|
||||
In fact, the Auth0 Webtasks provider is itself a plugin and needs to be specified in the `serverless.yml` file.
|
||||
|
||||
```yml
|
||||
# serverless.yml
|
||||
|
||||
plugins:
|
||||
- '@webtask/serverless-webtasks'
|
||||
```
|
||||
@ -1,50 +0,0 @@
|
||||
<!--
|
||||
title: Serverless Framework - Auth0 Webtasks Guide - Quick Start
|
||||
menuText: Quick Start
|
||||
menuOrder: 2
|
||||
description: Get started with Auth0 Webtasks in 5 minutes or less
|
||||
layout: Doc
|
||||
-->
|
||||
|
||||
# Auth0 Webtasks - Quick Start
|
||||
|
||||
This guide is designed to help you get started as quick as possible.
|
||||
|
||||
## 1. Create a new service
|
||||
|
||||
1. Create a new service with the [`webtasks-nodejs`](https://github.com/serverless/serverless/tree/master/lib/plugins/create/templates/webtasks-nodejs) template
|
||||
|
||||
```bash
|
||||
serverless create --template webtasks-nodejs --path my-service
|
||||
```
|
||||
|
||||
2. Install the dependencies
|
||||
|
||||
```bash
|
||||
cd my-service
|
||||
npm install
|
||||
```
|
||||
|
||||
## 2. Set up the credentials
|
||||
|
||||
Run the [config crendentials command](../cli-reference/config-credentials.md) to create a local profile. You will be asked for a phone number or email. You'll immediately receive a verification code. Enter the verification code and your profile will be entirely setup and ready to use.
|
||||
|
||||
```bash
|
||||
serverless config credentials --provider webtasks
|
||||
```
|
||||
|
||||
## 4. Deploy
|
||||
|
||||
Run the [deploy command](../cli-reference/deploy.md)
|
||||
|
||||
```bash
|
||||
serverless deploy
|
||||
```
|
||||
|
||||
## 5. Invoke
|
||||
|
||||
Run the [invoke command](../cli-reference/invoke.md)
|
||||
|
||||
```bash
|
||||
serverless invoke --function main
|
||||
```
|
||||
@ -498,13 +498,12 @@ class PluginManager {
|
||||
.concat(Object.keys(command.commands));
|
||||
});
|
||||
|
||||
const servicePath = this.serverless.config.servicePath || 'x';
|
||||
return getServerlessConfigFile(servicePath)
|
||||
return getServerlessConfigFile(this.serverless.config.servicePath)
|
||||
.then((serverlessConfigFile) => {
|
||||
const serverlessConfigFileHash = crypto.createHash('sha256')
|
||||
.update(JSON.stringify(serverlessConfigFile)).digest('hex');
|
||||
cacheFile.validationHash = serverlessConfigFileHash;
|
||||
const cacheFilePath = getCacheFilePath(servicePath);
|
||||
const cacheFilePath = getCacheFilePath(this.serverless.config.servicePath);
|
||||
return writeFile(cacheFilePath, cacheFile);
|
||||
})
|
||||
.catch((e) => null); // eslint-disable-line
|
||||
|
||||
@ -1,11 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const platform = require('@serverless/platform-sdk');
|
||||
const BbPromise = require('bluebird');
|
||||
const getAccessKey = require('../../../../utils/getAccessKey');
|
||||
|
||||
module.exports = {
|
||||
createDeployment() {
|
||||
const serverlessStateFilePath = path.join(
|
||||
this.serverless.config.servicePath, '.serverless', 'serverless-state.json');
|
||||
const serverlessStateFileContent = JSON.parse(fs.readFileSync(serverlessStateFilePath, 'utf8'));
|
||||
|
||||
return getAccessKey(this.serverless.service.tenant).then(accessKey => {
|
||||
if (accessKey && this.serverless.service.app &&
|
||||
this.serverless.service.tenant &&
|
||||
@ -15,6 +21,9 @@ module.exports = {
|
||||
app: this.serverless.service.app,
|
||||
accessKey,
|
||||
serviceName: this.serverless.service.service,
|
||||
files: {
|
||||
'serverless-state.json': serverlessStateFileContent,
|
||||
},
|
||||
};
|
||||
return platform.createDeployment(deploymentData)
|
||||
.then((res) => {
|
||||
|
||||
@ -50,6 +50,7 @@ describe('createStack', () => {
|
||||
const createStackStub = sandbox
|
||||
.stub(awsDeploy.provider, 'request').resolves();
|
||||
sandbox.stub(awsDeploy, 'monitorStack').resolves();
|
||||
sandbox.stub(awsDeploy, 'createDeployment').resolves();
|
||||
|
||||
return awsDeploy.create().then(() => {
|
||||
expect(createStackStub.args[0][2].Tags)
|
||||
@ -66,6 +67,7 @@ describe('createStack', () => {
|
||||
const createStackStub = sandbox
|
||||
.stub(awsDeploy.provider, 'request').resolves();
|
||||
sandbox.stub(awsDeploy, 'monitorStack').resolves();
|
||||
sandbox.stub(awsDeploy, 'createDeployment').resolves();
|
||||
|
||||
return awsDeploy.create().then(() => {
|
||||
expect(createStackStub.args[0][2].RoleARN)
|
||||
@ -80,6 +82,7 @@ describe('createStack', () => {
|
||||
const createStackStub = sinon
|
||||
.stub(awsDeploy.provider, 'request').resolves();
|
||||
sinon.stub(awsDeploy, 'monitorStack').resolves();
|
||||
sinon.stub(awsDeploy, 'createDeployment').resolves();
|
||||
|
||||
return awsDeploy.create().then(() => {
|
||||
expect(createStackStub.args[0][2].NotificationARNs)
|
||||
|
||||
@ -35,6 +35,7 @@ describe('validateTemplate', () => {
|
||||
},
|
||||
};
|
||||
validateTemplateStub = sinon.stub(awsDeploy.provider, 'request');
|
||||
sinon.stub(awsDeploy, 'createDeployment').resolves();
|
||||
awsDeploy.serverless.cli = {
|
||||
log: sinon.spy(),
|
||||
};
|
||||
@ -42,6 +43,7 @@ describe('validateTemplate', () => {
|
||||
|
||||
afterEach(() => {
|
||||
awsDeploy.provider.request.restore();
|
||||
awsDeploy.createDeployment.restore();
|
||||
});
|
||||
|
||||
describe('#validateTemplate()', () => {
|
||||
|
||||
@ -2,7 +2,7 @@ import argparse
|
||||
import json
|
||||
import logging
|
||||
import sys
|
||||
from time import time
|
||||
from time import strftime, time
|
||||
from importlib import import_module
|
||||
|
||||
class FakeLambdaContext(object):
|
||||
@ -31,12 +31,19 @@ class FakeLambdaContext(object):
|
||||
|
||||
@property
|
||||
def memory_limit_in_mb(self):
|
||||
return 1024
|
||||
return '1024'
|
||||
|
||||
@property
|
||||
def aws_request_id(self):
|
||||
return '1234567890'
|
||||
|
||||
@property
|
||||
def log_group_name(self):
|
||||
return '/aws/lambda/' + self.name
|
||||
|
||||
@property
|
||||
def log_stream_name(self):
|
||||
return strftime('%Y/%m/%d') +'/[$' + self.version + ']58419525dade4d17a495dceeeed44708'
|
||||
|
||||
logging.basicConfig()
|
||||
|
||||
|
||||
51
lib/plugins/aws/lib/cloudformationSchema.js
Normal file
51
lib/plugins/aws/lib/cloudformationSchema.js
Normal file
@ -0,0 +1,51 @@
|
||||
'use strict';
|
||||
|
||||
const YAML = require('js-yaml');
|
||||
const _ = require('lodash');
|
||||
|
||||
const functionNames = [
|
||||
'And',
|
||||
'Base64',
|
||||
'Cidr',
|
||||
'Condition',
|
||||
'Equals',
|
||||
'FindInMap',
|
||||
'GetAtt',
|
||||
'GetAZs',
|
||||
'If',
|
||||
'ImportValue',
|
||||
'Join',
|
||||
'Not',
|
||||
'Or',
|
||||
'Ref',
|
||||
'Select',
|
||||
'Split',
|
||||
'Sub',
|
||||
];
|
||||
|
||||
const yamlType = (name, kind) => {
|
||||
const functionName = _.includes(['Ref', 'Condition'], name) ? name : `Fn::${name}`;
|
||||
return new YAML.Type(`!${name}`, {
|
||||
kind,
|
||||
construct: data => {
|
||||
if (name === 'GetAtt') {
|
||||
// special GetAtt dot syntax
|
||||
return { [functionName]: _.isString(data) ? _.split(data, '.', 2) : data };
|
||||
}
|
||||
return { [functionName]: data };
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const createSchema = () => {
|
||||
const types = _.flatten(
|
||||
_.map(functionNames, functionName =>
|
||||
_.map(['mapping', 'scalar', 'sequence'], kind => yamlType(functionName, kind))
|
||||
)
|
||||
);
|
||||
return YAML.Schema.create(types);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
schema: createSchema(),
|
||||
};
|
||||
20
lib/plugins/aws/lib/cloudformationSchema.test.js
Normal file
20
lib/plugins/aws/lib/cloudformationSchema.test.js
Normal file
@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
const expect = require('chai').expect;
|
||||
|
||||
const cloudformationSchema = require('./cloudformationSchema');
|
||||
|
||||
describe('#cloudformationSchame()', () => {
|
||||
describe('#schema()', () => {
|
||||
it('should contain schema', () => {
|
||||
expect(Object.keys(cloudformationSchema.schema)).to.be.eql([
|
||||
'include',
|
||||
'implicit',
|
||||
'explicit',
|
||||
'compiledImplicit',
|
||||
'compiledExplicit',
|
||||
'compiledTypeMap',
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -61,6 +61,20 @@ class AwsCompileScheduledEvents {
|
||||
}
|
||||
|
||||
if (Input && typeof Input === 'object') {
|
||||
if (_.has(Input, 'body') && typeof Input.body === 'string') {
|
||||
try {
|
||||
Input.body = JSON.parse(Input.body);
|
||||
} catch (error) {
|
||||
const errorMessage = [
|
||||
'The body of the schedule event associated with',
|
||||
` ${functionName} was passed as a string`,
|
||||
' but it failed to parse to a JSON object.',
|
||||
' Please check the docs for more info.',
|
||||
].join('');
|
||||
throw new this.serverless.classes
|
||||
.Error(errorMessage);
|
||||
}
|
||||
}
|
||||
Input = JSON.stringify(Input);
|
||||
}
|
||||
if (Input && typeof Input === 'string') {
|
||||
|
||||
@ -287,6 +287,46 @@ describe('AwsCompileScheduledEvents', () => {
|
||||
expect(() => awsCompileScheduledEvents.compileScheduledEvents()).to.throw(Error);
|
||||
});
|
||||
|
||||
it('should not throw an error when Input body is a valid JSON string', () => {
|
||||
awsCompileScheduledEvents.serverless.service.functions = {
|
||||
first: {
|
||||
events: [
|
||||
{
|
||||
schedule: {
|
||||
rate: 'rate(10 minutes)',
|
||||
enabled: false,
|
||||
input: {
|
||||
body: '{ "functionId": "..." }',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
expect(() => awsCompileScheduledEvents.compileScheduledEvents()).not.to.throw(Error);
|
||||
});
|
||||
|
||||
it('should throw an error when Input body is an invalid JSON string', () => {
|
||||
awsCompileScheduledEvents.serverless.service.functions = {
|
||||
first: {
|
||||
events: [
|
||||
{
|
||||
schedule: {
|
||||
rate: 'rate(10 minutes)',
|
||||
enabled: false,
|
||||
input: {
|
||||
body: 'an invalid input body',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
expect(() => awsCompileScheduledEvents.compileScheduledEvents()).to.throw(Error);
|
||||
});
|
||||
|
||||
it('should not create corresponding resources when scheduled events are not given', () => {
|
||||
awsCompileScheduledEvents.serverless.service.functions = {
|
||||
first: {
|
||||
|
||||
@ -105,10 +105,10 @@ class AwsCompileSNSEvents {
|
||||
'Fn::GetAtt': [lambdaLogicalId, 'Arn'],
|
||||
};
|
||||
|
||||
if (topicArn) {
|
||||
const subscriptionLogicalId = this.provider.naming
|
||||
.getLambdaSnsSubscriptionLogicalId(functionName, topicName);
|
||||
const subscriptionLogicalId = this.provider.naming
|
||||
.getLambdaSnsSubscriptionLogicalId(functionName, topicName);
|
||||
|
||||
if (topicArn) {
|
||||
_.merge(template.Resources, {
|
||||
[subscriptionLogicalId]: {
|
||||
Type: 'AWS::SNS::Subscription',
|
||||
@ -116,6 +116,7 @@ class AwsCompileSNSEvents {
|
||||
TopicArn: topicArn,
|
||||
Protocol: 'lambda',
|
||||
Endpoint: endpoint,
|
||||
FilterPolicy: event.sns.filterPolicy,
|
||||
},
|
||||
},
|
||||
});
|
||||
@ -134,6 +135,7 @@ class AwsCompileSNSEvents {
|
||||
],
|
||||
],
|
||||
};
|
||||
|
||||
const topicLogicalId = this.provider.naming
|
||||
.getTopicLogicalId(topicName);
|
||||
|
||||
@ -142,21 +144,38 @@ class AwsCompileSNSEvents {
|
||||
Protocol: 'lambda',
|
||||
};
|
||||
|
||||
if (topicLogicalId in template.Resources) {
|
||||
template.Resources[topicLogicalId]
|
||||
.Properties.Subscription.push(subscription);
|
||||
} else {
|
||||
if (!(topicLogicalId in template.Resources)) {
|
||||
_.merge(template.Resources, {
|
||||
[topicLogicalId]: {
|
||||
Type: 'AWS::SNS::Topic',
|
||||
Properties: {
|
||||
TopicName: topicName,
|
||||
DisplayName: displayName,
|
||||
Subscription: [subscription],
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (event.sns.filterPolicy) {
|
||||
_.merge(template.Resources, {
|
||||
[subscriptionLogicalId]: {
|
||||
Type: 'AWS::SNS::Subscription',
|
||||
Properties:
|
||||
_.merge(subscription, {
|
||||
TopicArn: {
|
||||
Ref: topicLogicalId,
|
||||
},
|
||||
FilterPolicy: event.sns.filterPolicy,
|
||||
}),
|
||||
},
|
||||
});
|
||||
} else {
|
||||
if (!template.Resources[topicLogicalId].Properties.Subscription) {
|
||||
template.Resources[topicLogicalId].Properties.Subscription = [];
|
||||
}
|
||||
template.Resources[topicLogicalId]
|
||||
.Properties.Subscription.push(subscription);
|
||||
}
|
||||
}
|
||||
|
||||
const lambdaPermissionLogicalId = this.provider.naming
|
||||
|
||||
@ -44,6 +44,9 @@ describe('AwsCompileSNSEvents', () => {
|
||||
sns: {
|
||||
topicName: 'Topic 1',
|
||||
displayName: 'Display name for topic 1',
|
||||
filterPolicy: {
|
||||
pet: ['dog', 'cat'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -67,6 +70,67 @@ describe('AwsCompileSNSEvents', () => {
|
||||
expect(awsCompileSNSEvents.serverless.service
|
||||
.provider.compiledCloudFormationTemplate.Resources.FirstLambdaPermissionTopic2SNS.Type
|
||||
).to.equal('AWS::Lambda::Permission');
|
||||
expect(awsCompileSNSEvents.serverless.service
|
||||
.provider.compiledCloudFormationTemplate.Resources.FirstSnsSubscriptionTopic1.Type
|
||||
).to.equal('AWS::SNS::Subscription');
|
||||
expect(awsCompileSNSEvents.serverless.service
|
||||
.provider.compiledCloudFormationTemplate
|
||||
.Resources.FirstSnsSubscriptionTopic1.Properties.FilterPolicy
|
||||
).to.eql({ pet: ['dog', 'cat'] });
|
||||
});
|
||||
|
||||
it('should create corresponding resources when topic is defined in resources', () => {
|
||||
awsCompileSNSEvents.serverless.service.functions = {
|
||||
first: {
|
||||
events: [
|
||||
{
|
||||
sns: {
|
||||
topicName: 'Topic 1',
|
||||
displayName: 'Display name for topic 1',
|
||||
filterPolicy: {
|
||||
pet: ['dog', 'cat'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
sns: 'Topic 2',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
Object.assign(awsCompileSNSEvents.serverless.service
|
||||
.provider.compiledCloudFormationTemplate.Resources, {
|
||||
SNSTopicTopic2: {
|
||||
Type: 'AWS::SNS::Topic',
|
||||
Properties: {
|
||||
TopicName: 'Topic 2',
|
||||
DisplayName: 'Display name for topic 2',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
awsCompileSNSEvents.compileSNSEvents();
|
||||
|
||||
expect(awsCompileSNSEvents.serverless.service
|
||||
.provider.compiledCloudFormationTemplate.Resources.SNSTopicTopic1.Type
|
||||
).to.equal('AWS::SNS::Topic');
|
||||
expect(awsCompileSNSEvents.serverless.service
|
||||
.provider.compiledCloudFormationTemplate.Resources.SNSTopicTopic2.Type
|
||||
).to.equal('AWS::SNS::Topic');
|
||||
expect(awsCompileSNSEvents.serverless.service
|
||||
.provider.compiledCloudFormationTemplate.Resources.FirstLambdaPermissionTopic1SNS.Type
|
||||
).to.equal('AWS::Lambda::Permission');
|
||||
expect(awsCompileSNSEvents.serverless.service
|
||||
.provider.compiledCloudFormationTemplate.Resources.FirstLambdaPermissionTopic2SNS.Type
|
||||
).to.equal('AWS::Lambda::Permission');
|
||||
expect(awsCompileSNSEvents.serverless.service
|
||||
.provider.compiledCloudFormationTemplate.Resources.FirstSnsSubscriptionTopic1.Type
|
||||
).to.equal('AWS::SNS::Subscription');
|
||||
expect(awsCompileSNSEvents.serverless.service
|
||||
.provider.compiledCloudFormationTemplate
|
||||
.Resources.FirstSnsSubscriptionTopic1.Properties.FilterPolicy
|
||||
).to.eql({ pet: ['dog', 'cat'] });
|
||||
});
|
||||
|
||||
it('should create single SNS topic when the same topic is referenced repeatedly', () => {
|
||||
@ -94,10 +158,6 @@ describe('AwsCompileSNSEvents', () => {
|
||||
expect(awsCompileSNSEvents.serverless.service
|
||||
.provider.compiledCloudFormationTemplate.Resources.SNSTopicTopic1.Type
|
||||
).to.equal('AWS::SNS::Topic');
|
||||
expect(awsCompileSNSEvents.serverless.service
|
||||
.provider.compiledCloudFormationTemplate.Resources.SNSTopicTopic1
|
||||
.Properties.Subscription.length
|
||||
).to.equal(2);
|
||||
expect(awsCompileSNSEvents.serverless.service
|
||||
.provider.compiledCloudFormationTemplate.Resources.FirstLambdaPermissionTopic1SNS.Type
|
||||
).to.equal('AWS::Lambda::Permission');
|
||||
@ -156,6 +216,10 @@ describe('AwsCompileSNSEvents', () => {
|
||||
expect(awsCompileSNSEvents.serverless.service
|
||||
.provider.compiledCloudFormationTemplate.Resources.FirstLambdaPermissionFooSNS.Type
|
||||
).to.equal('AWS::Lambda::Permission');
|
||||
expect(awsCompileSNSEvents.serverless.service
|
||||
.provider.compiledCloudFormationTemplate
|
||||
.Resources.FirstSnsSubscriptionFoo.Properties.FilterPolicy
|
||||
).to.equal(undefined);
|
||||
});
|
||||
|
||||
it('should create SNS topic when only arn is given as an object property', () => {
|
||||
@ -184,6 +248,22 @@ describe('AwsCompileSNSEvents', () => {
|
||||
).to.equal('AWS::Lambda::Permission');
|
||||
});
|
||||
|
||||
it('should throw an error when the arn an object and the value is not a string', () => {
|
||||
awsCompileSNSEvents.serverless.service.functions = {
|
||||
first: {
|
||||
events: [
|
||||
{
|
||||
sns: {
|
||||
arn: 123,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
expect(() => { awsCompileSNSEvents.compileSNSEvents(); }).to.throw(Error);
|
||||
});
|
||||
|
||||
it('should create SNS topic when arn and topicName are given as object properties', () => {
|
||||
awsCompileSNSEvents.serverless.service.functions = {
|
||||
first: {
|
||||
@ -210,5 +290,39 @@ describe('AwsCompileSNSEvents', () => {
|
||||
.provider.compiledCloudFormationTemplate.Resources.FirstLambdaPermissionBarSNS.Type
|
||||
).to.equal('AWS::Lambda::Permission');
|
||||
});
|
||||
|
||||
it('should create SNS topic when arn, topicName, and filterPolicy are given as object', () => {
|
||||
awsCompileSNSEvents.serverless.service.functions = {
|
||||
first: {
|
||||
events: [
|
||||
{
|
||||
sns: {
|
||||
topicName: 'bar',
|
||||
arn: 'arn:aws:sns:region:accountid:bar',
|
||||
filterPolicy: {
|
||||
pet: ['dog', 'cat'],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
awsCompileSNSEvents.compileSNSEvents();
|
||||
|
||||
expect(Object.keys(awsCompileSNSEvents.serverless.service
|
||||
.provider.compiledCloudFormationTemplate.Resources)
|
||||
).to.have.length(2);
|
||||
expect(awsCompileSNSEvents.serverless.service
|
||||
.provider.compiledCloudFormationTemplate.Resources.FirstSnsSubscriptionBar.Type
|
||||
).to.equal('AWS::SNS::Subscription');
|
||||
expect(awsCompileSNSEvents.serverless.service
|
||||
.provider.compiledCloudFormationTemplate
|
||||
.Resources.FirstSnsSubscriptionBar.Properties.FilterPolicy
|
||||
).to.eql({ pet: ['dog', 'cat'] });
|
||||
expect(awsCompileSNSEvents.serverless.service
|
||||
.provider.compiledCloudFormationTemplate.Resources.FirstLambdaPermissionBarSNS.Type
|
||||
).to.equal('AWS::Lambda::Permission');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -4,6 +4,7 @@ const BbPromise = require('bluebird');
|
||||
const path = require('path');
|
||||
const fse = require('fs-extra');
|
||||
const _ = require('lodash');
|
||||
const untildify = require('untildify');
|
||||
|
||||
const ServerlessError = require('../../classes/Error').ServerlessError;
|
||||
const userStats = require('../../utils/userStats');
|
||||
@ -18,6 +19,7 @@ const validTemplates = [
|
||||
'aws-clojurescript-gradle',
|
||||
'aws-nodejs',
|
||||
'aws-nodejs-typescript',
|
||||
'aws-alexa-typescript',
|
||||
'aws-nodejs-ecma-script',
|
||||
'aws-python',
|
||||
'aws-python3',
|
||||
@ -33,6 +35,8 @@ const validTemplates = [
|
||||
'aws-go',
|
||||
'aws-go-dep',
|
||||
'azure-nodejs',
|
||||
'cloudflare-workers',
|
||||
'cloudflare-workers-enterprise',
|
||||
'fn-nodejs',
|
||||
'fn-go',
|
||||
'google-nodejs',
|
||||
@ -47,7 +51,6 @@ const validTemplates = [
|
||||
'spotinst-python',
|
||||
'spotinst-ruby',
|
||||
'spotinst-java8',
|
||||
'webtasks-nodejs',
|
||||
'plugin',
|
||||
|
||||
// this template is used to streamline the onboarding process
|
||||
@ -128,12 +131,14 @@ class Create {
|
||||
});
|
||||
} else if ('template-path' in this.options) {
|
||||
// Copying template from a local directory
|
||||
const servicePath = this.options.path || path.join(process.cwd(), this.options.name);
|
||||
const servicePath = this.options.path
|
||||
? untildify(this.options.path)
|
||||
: path.join(process.cwd(), this.options.name);
|
||||
if (dirExistsSync(servicePath)) {
|
||||
const errorMessage = `A folder named "${servicePath}" already exists.`;
|
||||
throw new ServerlessError(errorMessage);
|
||||
}
|
||||
copyDirContentsSync(this.options['template-path'], servicePath, {
|
||||
copyDirContentsSync(untildify(this.options['template-path']), servicePath, {
|
||||
noLinks: true,
|
||||
});
|
||||
if (this.options.name) {
|
||||
|
||||
@ -185,6 +185,43 @@ describe('Create', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should generate scaffolding for "aws-alexa-typescript" template', () => {
|
||||
process.chdir(tmpDir);
|
||||
create.options.template = 'aws-alexa-typescript';
|
||||
|
||||
return create.create().then(() => {
|
||||
const dirContent = fs.readdirSync(tmpDir);
|
||||
expect(dirContent).to.include('serverless.yml');
|
||||
expect(dirContent).to.include('handler.ts');
|
||||
expect(dirContent).to.include('tsconfig.json');
|
||||
expect(dirContent).to.include('package.json');
|
||||
expect(dirContent).to.include('webpack.config.js');
|
||||
expect(dirContent).to.include('.gitignore');
|
||||
});
|
||||
});
|
||||
it('should generate scaffolding for "aws-alexa-typescript" ' +
|
||||
'template and override service name if user passed', () => {
|
||||
process.chdir(tmpDir);
|
||||
create.options.template = 'aws-alexa-typescript';
|
||||
create.options.name = 'my-awesome-service';
|
||||
|
||||
return create.create().then(() => {
|
||||
const dirContent = fs.readdirSync(tmpDir);
|
||||
expect(dirContent).to.include('serverless.yml');
|
||||
expect(dirContent).to.include('handler.ts');
|
||||
expect(dirContent).to.include('tsconfig.json');
|
||||
expect(dirContent).to.include('package.json');
|
||||
expect(dirContent).to.include('webpack.config.js');
|
||||
expect(dirContent).to.include('.gitignore');
|
||||
|
||||
// check if the service was renamed
|
||||
const serverlessYmlfileContent = fse
|
||||
.readFileSync(path.join(tmpDir, 'serverless.yml')).toString();
|
||||
expect((/service:\n {2}name: my-awesome-service/)
|
||||
.test(serverlessYmlfileContent)).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('should generate scaffolding for "aws-nodejs-ecma-script" template', () => {
|
||||
process.chdir(tmpDir);
|
||||
create.options.template = 'aws-nodejs-ecma-script';
|
||||
@ -599,19 +636,6 @@ describe('Create', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should generate scaffolding for "webtasks-nodejs" template', () => {
|
||||
process.chdir(tmpDir);
|
||||
create.options.template = 'webtasks-nodejs';
|
||||
|
||||
return create.create().then(() => {
|
||||
const dirContent = fs.readdirSync(tmpDir);
|
||||
expect(dirContent).to.include('package.json');
|
||||
expect(dirContent).to.include('serverless.yml');
|
||||
expect(dirContent).to.include('handler.js');
|
||||
expect(dirContent).to.include('.gitignore');
|
||||
});
|
||||
});
|
||||
|
||||
it('should generate scaffolding for "fn-nodejs" template', () => {
|
||||
process.chdir(tmpDir);
|
||||
create.options.template = 'fn-nodejs';
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
# package directories
|
||||
node_modules
|
||||
jspm_packages
|
||||
|
||||
# Serverless directories
|
||||
.serverless
|
||||
|
||||
# Webpack directories
|
||||
.webpack
|
||||
@ -0,0 +1,9 @@
|
||||
import * as Ask from 'ask-sdk';
|
||||
|
||||
export const alexa = Ask.SkillBuilders.custom()
|
||||
.addRequestHandlers({
|
||||
canHandle: handlerInput => true,
|
||||
handle: handlerInput =>
|
||||
handlerInput.responseBuilder.speak('Hello world!').getResponse()
|
||||
})
|
||||
.lambda();
|
||||
@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "aws-alexa-typescript",
|
||||
"version": "1.0.0",
|
||||
"description": "Alexa example using Typescript",
|
||||
"main": "handler.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"ask-sdk": "^2.0.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^8.0.57",
|
||||
"serverless-alexa-skills": "^0.1.0",
|
||||
"serverless-webpack": "^5.1.1",
|
||||
"source-map-support": "^0.5.6",
|
||||
"ts-loader": "^4.2.0",
|
||||
"typescript": "^2.9.2",
|
||||
"webpack": "^4.5.0"
|
||||
},
|
||||
"author":
|
||||
"The serverless webpack authors (https://github.com/elastic-coders/serverless-webpack)",
|
||||
"license": "MIT"
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
service:
|
||||
name: aws-alexa-typescript
|
||||
|
||||
plugins:
|
||||
- serverless-webpack
|
||||
- serverless-alexa-skills
|
||||
|
||||
provider:
|
||||
name: aws
|
||||
runtime: nodejs8.10
|
||||
|
||||
custom:
|
||||
alexa:
|
||||
# Step 1: Run `sls alexa auth` to authenticate
|
||||
# Step 2: Run `sls alexa create --name "Serverless Alexa Typescript" --locale en-GB --type custom` to create a new skill
|
||||
skills:
|
||||
# Step 3: Paste the skill id returned by the create command here:
|
||||
- id: amzn1.ask.skill.xxxx-xxxx-xxxx-xxxx-xxxx
|
||||
manifest:
|
||||
publishingInformation:
|
||||
locales:
|
||||
en-GB:
|
||||
name: Serverless Alexa Typescript
|
||||
apis:
|
||||
custom:
|
||||
endpoint:
|
||||
# Step 4: Do your first deploy of your Serverless stack
|
||||
# Step 5: Paste the ARN of your lambda here:
|
||||
uri: arn:aws:lambda:[region]:[account-id]:function:[function-name]
|
||||
# Step 6: Run `sls alexa update` to deploy the skill manifest
|
||||
# Step 7: Run `sls alexa build` to build the skill interaction model
|
||||
# Step 8: Enable the skill in the Alexa app to start testing.
|
||||
manifestVersion: '1.0'
|
||||
models:
|
||||
en-GB:
|
||||
interactionModel:
|
||||
languageModel:
|
||||
invocationName: serverless typescript
|
||||
intents:
|
||||
- name: HelloIntent
|
||||
samples:
|
||||
- 'hello'
|
||||
|
||||
functions:
|
||||
alexa:
|
||||
handler: handler.alexa
|
||||
events:
|
||||
- alexaSkill: ${self:custom.alexa.skills.0.id}
|
||||
@ -0,0 +1 @@
|
||||
require('source-map-support').install();
|
||||
@ -0,0 +1,13 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"sourceMap": true,
|
||||
"target": "es6",
|
||||
"lib": [
|
||||
"esnext"
|
||||
],
|
||||
"moduleResolution": "node"
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
const path = require('path');
|
||||
const slsw = require('serverless-webpack');
|
||||
|
||||
const entries = {};
|
||||
|
||||
Object.keys(slsw.lib.entries).forEach(
|
||||
key => (entries[key] = ['./source-map-install.js', slsw.lib.entries[key]])
|
||||
);
|
||||
|
||||
module.exports = {
|
||||
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
|
||||
entry: entries,
|
||||
devtool: 'source-map',
|
||||
resolve: {
|
||||
extensions: ['.js', '.jsx', '.json', '.ts', '.tsx'],
|
||||
},
|
||||
output: {
|
||||
libraryTarget: 'commonjs',
|
||||
path: path.join(__dirname, '.webpack'),
|
||||
filename: '[name].js',
|
||||
},
|
||||
target: 'node',
|
||||
module: {
|
||||
rules: [
|
||||
// all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
|
||||
{ test: /\.tsx?$/, loader: 'ts-loader' },
|
||||
],
|
||||
},
|
||||
};
|
||||
@ -1,13 +1,11 @@
|
||||
import { APIGatewayEvent, Callback, Context, Handler } from 'aws-lambda';
|
||||
import { APIGatewayProxyHandler } from 'aws-lambda';
|
||||
|
||||
export const hello: Handler = (event: APIGatewayEvent, context: Context, cb: Callback) => {
|
||||
const response = {
|
||||
export const hello: APIGatewayProxyHandler = async (event, context) => {
|
||||
return {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify({
|
||||
message: 'Go Serverless Webpack (Typescript) v1.0! Your function executed successfully!',
|
||||
input: event,
|
||||
}),
|
||||
};
|
||||
|
||||
cb(null, response);
|
||||
}
|
||||
|
||||
3
lib/plugins/create/templates/cloudflare-workers-enterprise/.gitignore
vendored
Normal file
3
lib/plugins/create/templates/cloudflare-workers-enterprise/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Serverless directories
|
||||
.serverless
|
||||
node_modules/
|
||||
@ -0,0 +1,7 @@
|
||||
addEventListener('fetch', event => {
|
||||
event.respondWith(handleRequest(event.request))
|
||||
})
|
||||
|
||||
async function handleRequest(request) {
|
||||
return new Response("Foo is not Bar")
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
addEventListener('fetch', event => {
|
||||
event.respondWith(handleRequest(event.request))
|
||||
})
|
||||
|
||||
async function handleRequest(request) {
|
||||
return new Response("Hello world")
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "cloudflare-workers-enterprise",
|
||||
"version": "1.0.0",
|
||||
"description": "Cloudflare serverless deployment for enterprise customers",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "cloudflare",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"serverless-cloudflare-workers": "0.1.1"
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
service:
|
||||
name: hello-world
|
||||
|
||||
provider:
|
||||
name: cloudflare
|
||||
config:
|
||||
accountId: CLOUDFLARE_ACCOUNT_ID
|
||||
zoneId: CLOUDFLARE_ZONE_ID
|
||||
workers:
|
||||
hello:
|
||||
routes:
|
||||
- example.com/hello/*
|
||||
foo_script:
|
||||
routes:
|
||||
- example.com/foo/*
|
||||
|
||||
plugins:
|
||||
- serverless-cloudflare-workers
|
||||
|
||||
functions:
|
||||
helloWorld:
|
||||
worker: hello
|
||||
script: helloWorld
|
||||
events:
|
||||
- http:
|
||||
url: example.com/hello/user
|
||||
method: GET
|
||||
headers:
|
||||
foo: bar
|
||||
x-client-data: value
|
||||
|
||||
foo:
|
||||
worker: foo_script
|
||||
script: bar
|
||||
events:
|
||||
- http:
|
||||
url: example.com/foo/bar
|
||||
method: GET
|
||||
headers:
|
||||
foo: bar
|
||||
x-client-data: value
|
||||
3
lib/plugins/create/templates/cloudflare-workers/.gitignore
vendored
Normal file
3
lib/plugins/create/templates/cloudflare-workers/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Serverless directories
|
||||
.serverless
|
||||
node_modules/
|
||||
@ -0,0 +1,7 @@
|
||||
addEventListener('fetch', event => {
|
||||
event.respondWith(handleRequest(event.request))
|
||||
})
|
||||
|
||||
async function handleRequest(request) {
|
||||
return new Response("Hello world")
|
||||
}
|
||||
14
lib/plugins/create/templates/cloudflare-workers/package.json
Normal file
14
lib/plugins/create/templates/cloudflare-workers/package.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "cloudflare-workers",
|
||||
"version": "1.0.0",
|
||||
"description": "Cloudflare serverless deployment for self-serve customers",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "cloudflare",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"serverless-cloudflare-workers": "0.1.1"
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
service:
|
||||
name: hello-world
|
||||
|
||||
provider:
|
||||
name: cloudflare
|
||||
config:
|
||||
accountId: CLOUDFLARE_ACCOUNT_ID
|
||||
zoneId: CLOUDFLARE_ZONE_ID
|
||||
workers:
|
||||
hello:
|
||||
routes:
|
||||
- example.com/hello/*
|
||||
|
||||
plugins:
|
||||
- serverless-cloudflare-workers
|
||||
|
||||
functions:
|
||||
helloWorld:
|
||||
worker: hello
|
||||
script: helloWorld # there must be a file called helloWorld.js
|
||||
events:
|
||||
- http:
|
||||
url: example.com/hello/user
|
||||
method: GET
|
||||
headers:
|
||||
foo: bar
|
||||
x-client-data: value
|
||||
@ -1,6 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (context, cb) => {
|
||||
const message = 'Go Serverless & Webtasks! Your function executed successfully!';
|
||||
cb(null, { message });
|
||||
};
|
||||
@ -1,13 +0,0 @@
|
||||
{
|
||||
"name": "webtasks-nodejs",
|
||||
"version": "1.0.0",
|
||||
"description": "Auth0 Webtasks NodeJS template for the Serverless Framework",
|
||||
"main": "handler.js",
|
||||
"keywords": [
|
||||
"serverless",
|
||||
"webtasks"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@webtask/serverless-webtasks": "^1.0.1"
|
||||
}
|
||||
}
|
||||
@ -1,29 +0,0 @@
|
||||
# Welcome to Serverless!
|
||||
#
|
||||
# This file is the main config file for your service.
|
||||
# It's very minimal at this point and uses default values.
|
||||
# You can always add more config options for more control.
|
||||
# We've included some commented out config examples here.
|
||||
# Just uncomment any of them to get that config option.
|
||||
#
|
||||
# For full config options, check the docs:
|
||||
# docs.serverless.com
|
||||
#
|
||||
# Happy Coding!
|
||||
|
||||
service:
|
||||
name: webtasks-nodejs # NOTE: update this with your service name
|
||||
|
||||
provider:
|
||||
name: webtasks
|
||||
|
||||
# you can define service wide environment variables here
|
||||
# environment:
|
||||
# variable1: value1
|
||||
|
||||
functions:
|
||||
main:
|
||||
handler: handler
|
||||
|
||||
plugins:
|
||||
- '@webtask/serverless-webtasks'
|
||||
@ -5,8 +5,9 @@ const _ = require('lodash');
|
||||
const userStats = require('../../utils/userStats');
|
||||
|
||||
class Invoke {
|
||||
constructor(serverless) {
|
||||
constructor(serverless, options) {
|
||||
this.serverless = serverless;
|
||||
this.options = options || {};
|
||||
|
||||
this.commands = {
|
||||
invoke: {
|
||||
@ -82,6 +83,10 @@ class Invoke {
|
||||
usage: 'Path to JSON or YAML file holding context data',
|
||||
shortcut: 'x',
|
||||
},
|
||||
env: {
|
||||
usage: 'Override environment variables. e.g. --env VAR1=val1 --env VAR2=val2',
|
||||
shortcut: 'e',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -115,6 +120,14 @@ class Invoke {
|
||||
|
||||
_.merge(process.env, defaultEnvVars);
|
||||
|
||||
// Turn zero or more --env options into an array
|
||||
// ...then split --env NAME=value and put into process.env.
|
||||
_.concat(this.options.env || [])
|
||||
.forEach(itm => {
|
||||
const splitItm = _.split(itm, '=');
|
||||
process.env[splitItm[0]] = splitItm[1] || '';
|
||||
});
|
||||
|
||||
return BbPromise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,6 +41,20 @@ describe('Invoke', () => {
|
||||
return expect(invoke.hooks['invoke:local:loadEnvVars']()).to.be.fulfilled
|
||||
.then(() => expect(process.env.IS_LOCAL).to.equal('true'));
|
||||
});
|
||||
|
||||
it('should accept a single env option', () => {
|
||||
invoke.options = { env: 'NAME=value' };
|
||||
expect(invoke.hooks['invoke:local:loadEnvVars']()).to.be.fulfilled
|
||||
.then(() => expect(process.env.NAME).to.equal('value'));
|
||||
});
|
||||
|
||||
it('should accept multiple env options', () => {
|
||||
invoke.options = { env: ['NAME1=val1', 'NAME2=val2'] };
|
||||
|
||||
expect(invoke.hooks['invoke:local:loadEnvVars']()).to.be.fulfilled
|
||||
.then(() => expect(process.env.NAME1).to.equal('val1'))
|
||||
.then(() => expect(process.env.NAME2).to.equal('val2'));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -222,6 +222,12 @@ function excludeNodeDevDependencies(servicePath) {
|
||||
|
||||
return exAndIn;
|
||||
})
|
||||
.then(() => {
|
||||
// cleanup
|
||||
fs.unlinkSync(nodeDevDepFile);
|
||||
fs.unlinkSync(nodeProdDepFile);
|
||||
return exAndIn;
|
||||
})
|
||||
.catch(() => exAndIn);
|
||||
} catch (e) {
|
||||
// fail silently
|
||||
|
||||
@ -4,10 +4,8 @@
|
||||
|
||||
const BbPromise = require('bluebird');
|
||||
const path = require('path');
|
||||
const _ = require('lodash');
|
||||
const fs = require('fs');
|
||||
const fsExtra = require('../../utils/fs/fse');
|
||||
const crypto = require('crypto');
|
||||
const platform = require('@serverless/platform-sdk');
|
||||
const getAccessKey = require('../../utils/getAccessKey');
|
||||
const userStats = require('../../utils/userStats');
|
||||
@ -34,286 +32,6 @@ class Platform {
|
||||
return null;
|
||||
}
|
||||
|
||||
getS3Type(s3Event) {
|
||||
const splittedS3Event = s3Event.split(':');
|
||||
if (splittedS3Event[1] === 'ReducedRedundancyLostObject') {
|
||||
return 'aws.s3.ReducedRedundancyLostObject';
|
||||
} else if (splittedS3Event[1] === 'ObjectCreated' || splittedS3Event[1] === 'ObjectRemoved') {
|
||||
if (splittedS3Event[2] === '*') {
|
||||
return `aws.s3.${splittedS3Event[1]}`;
|
||||
} else if (typeof splittedS3Event[2] === 'string') {
|
||||
return `aws.s3.${splittedS3Event[1]}.${splittedS3Event[2]}`;
|
||||
}
|
||||
}
|
||||
return `aws.s3.${splittedS3Event[1]}`;
|
||||
}
|
||||
|
||||
getFunctionData(fn) {
|
||||
const fnData = {
|
||||
functionId: this.serverless.service.getFunction(fn).name,
|
||||
details: {
|
||||
runtime: this.serverless.service.functions[fn].runtime,
|
||||
memory: this.serverless.service.functions[fn].memory,
|
||||
timeout: this.serverless.service.functions[fn].timeout,
|
||||
},
|
||||
package: {
|
||||
handler: this.serverless.service.functions[fn].handler,
|
||||
name: this.serverless.service.functions[fn].name,
|
||||
arn: `arn:aws:lambda:${this.serverless.service.provider.region}:${
|
||||
this.data.service.provider.accountId}:function:${
|
||||
this.serverless.service.getFunction(fn).name}`,
|
||||
},
|
||||
};
|
||||
return fnData;
|
||||
}
|
||||
|
||||
getServiceData() {
|
||||
const serviceData = {
|
||||
name: this.serverless.service.service,
|
||||
stage: this.serverless.processedInput.options.stage
|
||||
|| this.serverless.service.provider.stage,
|
||||
provider: {
|
||||
name: this.serverless.service.provider.name,
|
||||
region: this.serverless.service.provider.region,
|
||||
stage: this.serverless.service.provider.stage,
|
||||
accountId: this.serverless.service.provider.accountId,
|
||||
},
|
||||
pluginsData: this.serverless.service.pluginsData,
|
||||
readme: this.getReadme(),
|
||||
};
|
||||
if (this.serverless.service.serviceObject.description) {
|
||||
serviceData.description = this.serverless.service.serviceObject.description;
|
||||
}
|
||||
if (this.serverless.service.serviceObject.license) {
|
||||
serviceData.license = this.serverless.service.serviceObject.license;
|
||||
}
|
||||
if (this.serverless.service.serviceObject.bugs) {
|
||||
serviceData.bugs = this.serverless.service.serviceObject.bugs;
|
||||
}
|
||||
if (this.serverless.service.serviceObject.repository) {
|
||||
serviceData.repository = this.serverless.service.serviceObject.repository;
|
||||
}
|
||||
if (this.serverless.service.serviceObject.homepage) {
|
||||
serviceData.homepage = this.serverless.service.serviceObject.homepage;
|
||||
}
|
||||
return serviceData;
|
||||
}
|
||||
|
||||
getScheduledSubscription(event, fn) {
|
||||
const provider = this.data.service.provider;
|
||||
const subscription = {
|
||||
functionId: this.serverless.service.getFunction(fn).name,
|
||||
type: 'aws.cloudwatch.scheduled',
|
||||
details: {
|
||||
function: this.serverless.service.getFunction(fn).name,
|
||||
source: 'AWS::CloudWatch::Scheduled',
|
||||
},
|
||||
provider,
|
||||
permissions: {
|
||||
type: 'aws IAM',
|
||||
action: 'lambda:InvokeFunction',
|
||||
sourceAccount: 'Amazon',
|
||||
},
|
||||
};
|
||||
if (typeof event === 'string') {
|
||||
subscription.details.rate = event;
|
||||
subscription.details.name = null;
|
||||
subscription.details.description = null;
|
||||
} else if (typeof event === 'object') {
|
||||
subscription.details.rate = event.rate;
|
||||
subscription.details.name = event.name;
|
||||
subscription.details.description = event.description;
|
||||
}
|
||||
subscription.event = event;
|
||||
return subscription;
|
||||
}
|
||||
|
||||
getS3Subscription(event, fn) {
|
||||
const provider = this.data.service.provider;
|
||||
const subscription = {
|
||||
functionId: this.serverless.service.getFunction(fn).name,
|
||||
details: {
|
||||
function: this.serverless.service.getFunction(fn).name,
|
||||
},
|
||||
provider,
|
||||
permissions: {
|
||||
type: 'aws IAM',
|
||||
action: 'lambda:InvokeFunction',
|
||||
sourceAccount: 'Amazon',
|
||||
},
|
||||
};
|
||||
if (typeof event === 'string') {
|
||||
subscription.type = 'aws.s3.ObjectCreated';
|
||||
subscription.details.source = `AWS::S3::${event}`;
|
||||
subscription.details.bucket = event;
|
||||
subscription.details.event = 's3:ObjectCreated:*';
|
||||
subscription.details.rules = null;
|
||||
subscription.permissions.sourceArn = `arn:aws:s3:::${event}`;
|
||||
} else if (typeof event === 'object') {
|
||||
subscription.type = this.getS3Type(event.event);
|
||||
subscription.details.source = `AWS::S3::${event.bucket}`;
|
||||
subscription.details.bucket = event.bucket;
|
||||
subscription.details.event = event.event;
|
||||
subscription.details.rules = event.rules || null;
|
||||
subscription.permissions.sourceArn = `arn:aws:s3:::${event.bucket}`;
|
||||
}
|
||||
subscription.event = event;
|
||||
return subscription;
|
||||
}
|
||||
|
||||
getSnsSubscription(event, fn) {
|
||||
// todo existing topic arn
|
||||
const provider = this.data.service.provider;
|
||||
const subscription = {
|
||||
functionId: this.serverless.service.getFunction(fn).name,
|
||||
type: 'aws.sns',
|
||||
details: {
|
||||
function: this.serverless.service.getFunction(fn).name,
|
||||
},
|
||||
provider,
|
||||
permissions: {
|
||||
type: 'aws IAM',
|
||||
action: 'lambda:InvokeFunction',
|
||||
sourceAccount: 'Amazon',
|
||||
},
|
||||
};
|
||||
|
||||
if (typeof event === 'string') {
|
||||
subscription.details.source = `AWS::SNS::${event}`;
|
||||
subscription.details.topic = event;
|
||||
subscription.permissions.sourceArn = `arn:aws:sns:${this.provider.getRegion()
|
||||
}:${provider.accountId}:${event}`;
|
||||
} else if (typeof event === 'object') {
|
||||
subscription.details.source = `AWS::SNS::${event.topicName}`;
|
||||
subscription.details.topic = event.topicName;
|
||||
subscription.details.displayName = event.displayName;
|
||||
subscription.permissions.sourceArn = `arn:aws:sns:${this.provider.getRegion()
|
||||
}:${provider.accountId}:${event.topicName}`;
|
||||
}
|
||||
subscription.event = event;
|
||||
return subscription;
|
||||
}
|
||||
|
||||
getEGSubscription(event, fn) {
|
||||
const subscription = {
|
||||
functionId: this.serverless.service.getFunction(fn).name,
|
||||
type: event.eventType,
|
||||
details: {
|
||||
function: this.serverless.service.getFunction(fn).name,
|
||||
type: event.type,
|
||||
app: this.data.app,
|
||||
service: this.data.service.name,
|
||||
stage: this.serverless.service.provider.stage,
|
||||
path: event.path || '/',
|
||||
},
|
||||
provider: {
|
||||
name: 'Serverless',
|
||||
tenant: this.data.tenant,
|
||||
},
|
||||
properties: {
|
||||
name: event.eventType,
|
||||
service: this.data.service.name,
|
||||
stage: this.serverless.service.provider.stage,
|
||||
},
|
||||
};
|
||||
|
||||
if (event.type === 'sync') {
|
||||
subscription.details.source = 'Sls::EventGateway::http';
|
||||
} else if (event.type === 'async') {
|
||||
subscription.details.source = 'sls/eventgateway/com';
|
||||
}
|
||||
if (event.eventType === 'http.request') {
|
||||
subscription.details.method = event.method;
|
||||
}
|
||||
if (typeof event.cors === 'boolean' || typeof event.cors === 'object') {
|
||||
subscription.details.cors = event.cors;
|
||||
} else {
|
||||
subscription.details.cors = true;
|
||||
}
|
||||
subscription.event = event;
|
||||
return subscription;
|
||||
}
|
||||
|
||||
getApigSubscription(event, fn) {
|
||||
const apiId = this.serverless.service.deployment.apiId;
|
||||
const provider = this.data.service.provider;
|
||||
const subscription = {
|
||||
functionId: this.serverless.service.getFunction(fn).name,
|
||||
type: 'aws.apigateway.http',
|
||||
details: {
|
||||
function: this.serverless.service.getFunction(fn).name,
|
||||
type: 'http',
|
||||
source: 'AWS::APIGateway::http',
|
||||
apiId,
|
||||
},
|
||||
provider,
|
||||
permissions: {
|
||||
type: 'aws IAM',
|
||||
action: 'lambda:InvokeFunction',
|
||||
sourceAccount: 'Amazon',
|
||||
},
|
||||
};
|
||||
|
||||
if (typeof event === 'string') {
|
||||
subscription.details.method = event.split(' ')[0];
|
||||
subscription.details.path = event.split(' ')[1];
|
||||
subscription.permissions.sourceArn = this.provider
|
||||
.getMethodArn(provider.accountId, apiId, event.split(' ')[0], event.split(' ')[1]);
|
||||
subscription.details.cors = false;
|
||||
subscription.details.lambdaProxy = true;
|
||||
} else if (typeof event === 'object') {
|
||||
subscription.details.method = event.method;
|
||||
subscription.details.path = event.path;
|
||||
subscription.permissions.sourceArn = this.provider
|
||||
.getMethodArn(provider.accountId, apiId, event.method, event.path);
|
||||
if (typeof event.cors === 'boolean' || typeof event.cors === 'object') {
|
||||
subscription.details.cors = true;
|
||||
} else {
|
||||
subscription.details.cors = false;
|
||||
}
|
||||
if (event.integration === 'AWS') {
|
||||
subscription.details.lambdaProxy = false;
|
||||
} else {
|
||||
subscription.details.lambdaProxy = true;
|
||||
}
|
||||
}
|
||||
subscription.event = event;
|
||||
|
||||
// the aws package plugin strips trailing and leading slashes per CF needs.
|
||||
if (subscription.details.path === '') subscription.details.path = '/';
|
||||
if (subscription.event.path === '') subscription.event.path = '/';
|
||||
|
||||
// in case of AWS integration, the aws package plugin adds
|
||||
// request/response objects that we need to stringify
|
||||
if (!subscription.details.lambdaProxy) {
|
||||
subscription.event.request = JSON.stringify(subscription.event.request);
|
||||
subscription.event.response = JSON.stringify(subscription.event.response);
|
||||
}
|
||||
|
||||
return subscription;
|
||||
}
|
||||
|
||||
getResources() {
|
||||
const frameworkResources = this.serverless.service.provider
|
||||
.compiledCloudFormationTemplate.Resources;
|
||||
const resources = [];
|
||||
|
||||
_.forEach(frameworkResources, (value, key) => {
|
||||
const physicalId = _.find(this.cfResources, r => r.LogicalResourceId === key)
|
||||
.PhysicalResourceId;
|
||||
const resource = {
|
||||
resourceId: key.toLowerCase(),
|
||||
id: physicalId,
|
||||
name: key,
|
||||
type: value.Type,
|
||||
properties: JSON.stringify(value.Properties),
|
||||
provider: this.serverless.service.provider.name,
|
||||
};
|
||||
resources.push(resource);
|
||||
});
|
||||
return resources;
|
||||
}
|
||||
|
||||
publishService() {
|
||||
if (!this.serverless.service.deployment || !this.serverless.service.deployment.deploymentId) {
|
||||
return BbPromise.resolve();
|
||||
@ -324,91 +42,24 @@ class Platform {
|
||||
this.cfResources = resources;
|
||||
}).then(() => this.provider.getAccountId())
|
||||
.then(accountId => {
|
||||
const service = this.serverless.service;
|
||||
|
||||
this.data = {
|
||||
app: this.serverless.service.app,
|
||||
tenant: this.serverless.service.tenant,
|
||||
const deploymentData = {
|
||||
tenant: this.serverless.service.deployment.tenant,
|
||||
app: this.serverless.service.deployment.app,
|
||||
serviceName: this.serverless.service.deployment.serviceName,
|
||||
accessKey: this.serverless.service.deployment.accessKey,
|
||||
version: '0.1.0',
|
||||
service: this.getServiceData(),
|
||||
functions: [],
|
||||
subscriptions: [],
|
||||
resources: this.getResources(),
|
||||
deploymentId: this.serverless.service.deployment.deploymentId,
|
||||
status: 'success',
|
||||
computedData: {
|
||||
readme: this.getReadme(),
|
||||
accountId,
|
||||
apiId: this.serverless.service.deployment.apiId,
|
||||
physicalIds: this.cfResources.map(r => ({
|
||||
logicalId: r.LogicalResourceId,
|
||||
physicalId: r.PhysicalResourceId,
|
||||
})),
|
||||
},
|
||||
};
|
||||
|
||||
this.data.service.provider.accountId = accountId;
|
||||
|
||||
Object.keys(service.functions).forEach(fn => {
|
||||
const fnData = this.getFunctionData(fn);
|
||||
this.data.functions.push(fnData);
|
||||
this.serverless.service.getAllEventsInFunction(fn).forEach(event => {
|
||||
let subscription = {
|
||||
functionId: this.serverless.service.getFunction(fn).name,
|
||||
details: {},
|
||||
provider: this.data.service.provider,
|
||||
permissions: {},
|
||||
};
|
||||
|
||||
if (Object.keys(event)[0] === 'eventgateway') {
|
||||
subscription = this.getEGSubscription(event.eventgateway, fn);
|
||||
} else if (Object.keys(event)[0] === 'http') {
|
||||
subscription = this.getApigSubscription(event.http, fn);
|
||||
} else if (Object.keys(event)[0] === 'stream') {
|
||||
if (typeof event.stream === 'string') {
|
||||
const streamType = event.stream.split(':')[2];
|
||||
subscription.type = `aws.${streamType}`;
|
||||
} else if (typeof event.stream === 'object') {
|
||||
if (event.stream.type === 'dynamodb') {
|
||||
subscription.type = 'aws.dynamodb';
|
||||
} else if (event.stream.type === 'kinesis') {
|
||||
subscription.type = 'aws.kinesis';
|
||||
}
|
||||
}
|
||||
subscription.event = event.stream;
|
||||
if (typeof event.stream === 'object') {
|
||||
subscription.event.arn = JSON.stringify(event.stream.arn);
|
||||
}
|
||||
} else if (Object.keys(event)[0] === 's3') {
|
||||
subscription = this.getS3Subscription(event.s3, fn);
|
||||
} else if (Object.keys(event)[0] === 'schedule') {
|
||||
subscription = this.getScheduledSubscription(event.schedule, fn);
|
||||
} else if (Object.keys(event)[0] === 'sns') {
|
||||
subscription = this.getSnsSubscription(event.sns, fn);
|
||||
} else if (Object.keys(event)[0] === 'alexaSkill') {
|
||||
subscription.type = 'aws.alexa.skill';
|
||||
subscription.event = event.alexaSkill;
|
||||
} else if (Object.keys(event)[0] === 'iot') {
|
||||
subscription.type = 'aws.iot';
|
||||
subscription.event = event.iot;
|
||||
} else if (Object.keys(event)[0] === 'cloudwatchEvent') {
|
||||
subscription.type = 'aws.cloudwatch';
|
||||
subscription.event = event.cloudwatchEvent;
|
||||
} else if (Object.keys(event)[0] === 'cloudwatchLog') {
|
||||
subscription.type = 'aws.cloudwatch.log';
|
||||
subscription.event = event.cloudwatchLog;
|
||||
} else if (Object.keys(event)[0] === 'cognitoUserPool') {
|
||||
subscription.type = 'aws.cognito';
|
||||
subscription.event = event.cognitoUserPool;
|
||||
} else if (Object.keys(event)[0] === 'alexaSmartHome') {
|
||||
subscription.type = 'aws.alexa.home';
|
||||
subscription.event = event.alexaSmartHome;
|
||||
}
|
||||
|
||||
subscription.subscriptionId = crypto.createHash('md5')
|
||||
.update(JSON.stringify(subscription)).digest('hex');
|
||||
|
||||
// dashboard currently does not support sqs
|
||||
if (Object.keys(event)[0] !== 'sqs') {
|
||||
this.data.subscriptions.push(subscription);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const deploymentData = this.serverless.service.deployment;
|
||||
deploymentData.status = 'Success';
|
||||
deploymentData.state = this.data;
|
||||
|
||||
return platform.updateDeployment(deploymentData)
|
||||
.then(() => {
|
||||
const trackingData = {
|
||||
@ -419,7 +70,7 @@ class Platform {
|
||||
const serviceUrlData = {
|
||||
tenant: deploymentData.tenant,
|
||||
app: deploymentData.app,
|
||||
name: deploymentData.state.service.name,
|
||||
name: deploymentData.serviceName,
|
||||
};
|
||||
const serviceUrl = platform.getServiceUrl(serviceUrlData);
|
||||
this.serverless.cli
|
||||
@ -438,6 +89,8 @@ class Platform {
|
||||
name: this.serverless.service.service,
|
||||
tenant: this.serverless.service.tenant,
|
||||
app: this.serverless.service.app,
|
||||
provider: this.serverless.service.provider.name,
|
||||
region: this.serverless.service.provider.region,
|
||||
accessKey,
|
||||
};
|
||||
return platform.archiveService(data)
|
||||
|
||||
@ -16,7 +16,6 @@ class Print {
|
||||
this.commands = {
|
||||
print: {
|
||||
usage: 'Print your compiled and resolved config file',
|
||||
configDependent: true,
|
||||
lifecycleEvents: [
|
||||
'print',
|
||||
],
|
||||
@ -95,9 +94,9 @@ class Print {
|
||||
// the codebase. Avoiding that, this method must read the serverless.yml file itself, adorn it
|
||||
// as the Service class would and then populate it, reversing the adornments thereafter in
|
||||
// preparation for printing the service for the user.
|
||||
return getServerlessConfigFile(process.cwd())
|
||||
.then((serverlessConfigFile) => {
|
||||
const service = serverlessConfigFile;
|
||||
return getServerlessConfigFile(this.serverless.config.servicePath)
|
||||
.then((svc) => {
|
||||
const service = svc;
|
||||
this.adorn(service);
|
||||
// Need to delete variableSyntax to avoid self-matching errors
|
||||
this.serverless.variables.loadVariableSyntax();
|
||||
|
||||
@ -40,27 +40,22 @@ const cacheFileValid = (serverlessConfigFile, validationHash) => {
|
||||
};
|
||||
|
||||
const autocomplete = () => {
|
||||
let servicePath = process.cwd();
|
||||
const servicePath = process.cwd();
|
||||
return getServerlessConfigFile(servicePath)
|
||||
.then((serverlessConfigFile) => {
|
||||
if (!serverlessConfigFile) {
|
||||
servicePath = 'x';
|
||||
}
|
||||
return getCacheFile(servicePath)
|
||||
.then((cacheFile) => {
|
||||
if (!cacheFile || !cacheFileValid(serverlessConfigFile, cacheFile.validationHash)) {
|
||||
const serverless = new Serverless();
|
||||
return serverless.init().then(() => getCacheFile(servicePath));
|
||||
}
|
||||
return cacheFile;
|
||||
})
|
||||
.then((cacheFile) => {
|
||||
if (!cacheFile || !cacheFileValid(serverlessConfigFile, cacheFile.validationHash)) {
|
||||
return;
|
||||
}
|
||||
return getSuggestions(cacheFile.commands); // eslint-disable-line consistent-return
|
||||
});
|
||||
});
|
||||
.then((serverlessConfigFile) => getCacheFile(servicePath)
|
||||
.then((cacheFile) => {
|
||||
if (!cacheFile || !cacheFileValid(serverlessConfigFile, cacheFile.validationHash)) {
|
||||
const serverless = new Serverless();
|
||||
return serverless.init().then(() => getCacheFile(servicePath));
|
||||
}
|
||||
return cacheFile;
|
||||
})
|
||||
.then((cacheFile) => {
|
||||
if (!cacheFile || !cacheFileValid(serverlessConfigFile, cacheFile.validationHash)) {
|
||||
return;
|
||||
}
|
||||
return getSuggestions(cacheFile.commands); // eslint-disable-line consistent-return
|
||||
}));
|
||||
};
|
||||
|
||||
module.exports = autocomplete;
|
||||
|
||||
@ -2,13 +2,37 @@
|
||||
|
||||
const jc = require('json-cycle');
|
||||
const YAML = require('js-yaml');
|
||||
const _ = require('lodash');
|
||||
const cloudFormationSchema = require('../../plugins/aws/lib/cloudformationSchema');
|
||||
|
||||
const loadYaml = (contents, options) => {
|
||||
let data;
|
||||
let error;
|
||||
try {
|
||||
data = YAML.load(contents.toString(), options || {});
|
||||
} catch (exception) {
|
||||
error = exception;
|
||||
}
|
||||
return { data, error };
|
||||
};
|
||||
|
||||
function parse(filePath, contents) {
|
||||
// Auto-parse JSON
|
||||
if (filePath.endsWith('.json')) {
|
||||
return jc.parse(contents);
|
||||
} else if (filePath.endsWith('.yml') || filePath.endsWith('.yaml')) {
|
||||
return YAML.load(contents.toString(), { filename: filePath });
|
||||
const options = {
|
||||
filename: filePath,
|
||||
};
|
||||
let result = loadYaml(contents.toString(), options);
|
||||
if (result.error && result.error.name === 'YAMLException') {
|
||||
_.merge(options, { schema: cloudFormationSchema.schema });
|
||||
result = loadYaml(contents.toString(), options);
|
||||
}
|
||||
if (result.error) {
|
||||
throw result.error;
|
||||
}
|
||||
return result.data;
|
||||
}
|
||||
return contents.toString().trim();
|
||||
}
|
||||
|
||||
@ -8,6 +8,82 @@ chai.use(require('chai-as-promised'));
|
||||
chai.use(require('sinon-chai'));
|
||||
const expect = require('chai').expect;
|
||||
|
||||
const shortHandOptions = [
|
||||
{
|
||||
name: 'Ref',
|
||||
yaml: 'Item: !Ref OtherItem',
|
||||
json: { Item: { Ref: 'OtherItem' } },
|
||||
},
|
||||
{
|
||||
name: 'GetAtt, dot syntax',
|
||||
yaml: 'Item: !GetAtt MyResource.Arn',
|
||||
json: { Item: { 'Fn::GetAtt': ['MyResource', 'Arn'] } },
|
||||
},
|
||||
{
|
||||
name: 'GetAtt, array syntax',
|
||||
yaml: 'Item: !GetAtt\n- MyResource\n- Arn',
|
||||
json: { Item: { 'Fn::GetAtt': ['MyResource', 'Arn'] } },
|
||||
},
|
||||
{
|
||||
name: 'Base64',
|
||||
yaml: 'Item: !Base64 valueToEncode',
|
||||
json: { Item: { 'Fn::Base64': 'valueToEncode' } },
|
||||
},
|
||||
{
|
||||
name: 'Sub, without mapping',
|
||||
yaml: 'Item: !Sub "My.${AWS::Region}"',
|
||||
json: { Item: { 'Fn::Sub': 'My.${AWS::Region}' } },
|
||||
},
|
||||
{
|
||||
name: 'Sub, with mapping',
|
||||
yaml: 'Item: !Sub\n- www.${Domain}\n- { Domain: "serverless.com" }',
|
||||
json: {
|
||||
Item: {
|
||||
'Fn::Sub': [
|
||||
'www.${Domain}',
|
||||
{
|
||||
Domain: 'serverless.com',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Join, oneliner',
|
||||
yaml: 'Item: !Join ["", ["arn:aws:s3::", { Ref: MyBucket }]]',
|
||||
json: {
|
||||
Item: {
|
||||
'Fn::Join': [
|
||||
'',
|
||||
[
|
||||
'arn:aws:s3::',
|
||||
{
|
||||
Ref: 'MyBucket',
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Join, multiline',
|
||||
yaml: 'Item: !Join\n- ""\n- - "arn:aws:s3::"\n - !Ref MyBucket',
|
||||
json: {
|
||||
Item: {
|
||||
'Fn::Join': [
|
||||
'',
|
||||
[
|
||||
'arn:aws:s3::',
|
||||
{
|
||||
Ref: 'MyBucket',
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
describe('#parse()', () => {
|
||||
it('should reconstitute circular references', () => {
|
||||
const tmpFilePath = 'anything.json';
|
||||
@ -17,4 +93,54 @@ describe('#parse()', () => {
|
||||
|
||||
expect(obj).to.equal(obj.foo);
|
||||
});
|
||||
|
||||
it('should return contents of a non json or yaml file as a string', () => {
|
||||
const tmpFilePath = 'anything.txt';
|
||||
const fileContents = 'serverless';
|
||||
|
||||
const obj = parse(tmpFilePath, fileContents);
|
||||
|
||||
expect(obj).to.equal('serverless');
|
||||
});
|
||||
|
||||
shortHandOptions.forEach(shortHandOption => {
|
||||
it(`should convert shorthand syntax "${shortHandOption.name}"`, () => {
|
||||
const tmpFilePath = 'anything.yml';
|
||||
const fileContents = shortHandOption.yaml;
|
||||
const obj = parse(tmpFilePath, fileContents);
|
||||
expect(obj).to.eql(shortHandOption.json);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should parse YAML without shorthand syntax', () => {
|
||||
const tmpFilePath = 'anything.yml';
|
||||
const fileContents = 'Item:\n Fn::Join:\n - ""\n - - "arn:aws:s3::"\n - !Ref MyBucket';
|
||||
const obj = parse(tmpFilePath, fileContents);
|
||||
expect(obj).to.eql({
|
||||
Item: {
|
||||
'Fn::Join': [
|
||||
'',
|
||||
[
|
||||
'arn:aws:s3::',
|
||||
{
|
||||
Ref: 'MyBucket',
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw error with invalid shorthand syntax', () => {
|
||||
const tmpFilePath = 'anything.yml';
|
||||
const fileContents = 'Item:\n !Invalid\n- ""\n- - "arn:aws:s3::"\n - !Ref MyBucket';
|
||||
let obj;
|
||||
try {
|
||||
obj = parse(tmpFilePath, fileContents);
|
||||
} catch (exception) {
|
||||
expect(exception.name).to.be.equal('YAMLException');
|
||||
}
|
||||
expect(obj).to.be.equal(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
@ -4,7 +4,8 @@ const homedir = require('os').homedir();
|
||||
const path = require('path');
|
||||
const crypto = require('crypto');
|
||||
|
||||
const getCacheFilePath = function (servicePath) {
|
||||
const getCacheFilePath = function (srvcPath) {
|
||||
const servicePath = srvcPath || process.cwd();
|
||||
const servicePathHash = crypto.createHash('sha256').update(servicePath).digest('hex');
|
||||
return path.join(homedir, '.serverless', 'cache', servicePathHash, 'autocomplete.json');
|
||||
};
|
||||
|
||||
@ -6,7 +6,8 @@ const path = require('path');
|
||||
const fileExists = require('./fs/fileExists');
|
||||
const readFile = require('./fs/readFile');
|
||||
|
||||
const getServerlessConfigFile = _.memoize((servicePath) => {
|
||||
const getServerlessConfigFile = _.memoize((srvcPath) => {
|
||||
const servicePath = srvcPath || process.cwd();
|
||||
const jsonPath = path.join(servicePath, 'serverless.json');
|
||||
const ymlPath = path.join(servicePath, 'serverless.yml');
|
||||
const yamlPath = path.join(servicePath, 'serverless.yaml');
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user