Skip to content

Commit 97bdac9

Browse files
author
dfounderliu
committed
add documents
1 parent 6b4f2a7 commit 97bdac9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2687
-517
lines changed

README.md

Lines changed: 82 additions & 517 deletions
Large diffs are not rendered by default.

docs/en/create.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
2+
# Tencent-scf - Create
3+
4+
Creates a new service in the current working directory based on the provided template.
5+
6+
**Create service in current working directory:**
7+
8+
```bash
9+
serverless create --template tencent-nodejs
10+
```
11+
12+
**Create service in new folder:**
13+
14+
```bash
15+
serverless create --template tencent-nodejs --path myService
16+
```
17+
18+
**Create service in new folder using a custom template:**
19+
20+
```bash
21+
serverless create --template-url https://github.com/serverless/serverless/tree/master/lib/plugins/create/templates/tencent-nodejs --path myService
22+
```
23+
## Options
24+
25+
- `--template` or `-t` The name of one of the available templates. **Required if --template-url and --template-path are not present**.
26+
- `--template-url` or `-u` The name of one of the available templates. **Required if --template and --template-path are not present**.
27+
- `--template-path` The local path of your template. **Required if --template and --template-url are not present**.
28+
- `--path` or `-p` The path where the service should be created.
29+
- `--name` or `-n` the name of the service in `serverless.yml`.
30+
31+
## Available Templates
32+
33+
To see a list of available templates run `serverless create --help`
34+
35+
Most commonly used templates:
36+
37+
- tencent-nodejs
38+
- tencent-python
39+
- tencent-php
40+
- tencent-go
41+
42+
## Examples
43+
44+
### Creating a new service
45+
46+
```bash
47+
serverless create --template tencent-nodejs --name my-project
48+
```
49+
50+
This example will generate scaffolding for a service with `Tencent` as a provider and `nodejs8` as runtime. The scaffolding
51+
will be generated in the current working directory.
52+
53+
Your new service will have a default stage called `dev` and a default region inside that stage called `ap-guangzhou`.
54+
The provider which is used for deployment later on is Tencent Cloud.
55+
56+
### Creating a named service in a (new) directory
57+
58+
```bash
59+
serverless create --template tencent-nodejs --path tencent-project
60+
```
61+
62+
This example will generate scaffolding for a service with `Tencent` as a provider and `nodejs8` as runtime. The scaffolding
63+
will be generated in the `tencent-project` directory. This directory will be created if not present. Otherwise Serverless
64+
will use the already present directory.
65+
66+
Additionally Serverless will rename the service according to the path you provide. In this example the service will be
67+
renamed to `tencent-project`.

docs/en/credentials.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
# Tencent Cloud - Credentials
3+
4+
The Serverless Framework needs access to account credentials for your Tencent Cloud account so that it can create and manage resources on your behalf.
5+
6+
## Create a Tencent Cloud Account
7+
8+
If you already have a Tencent Cloud account, skip to the next step to [create an CAM User and Access Key](#create-an-cam-user-and-access-key)
9+
10+
To create a Tencent Cloud account:
11+
1. Open https://cloud.tencent.com/, and then choose Sign up.
12+
2. Follow the online instructions.
13+
- Part of the sign-up procedure involves entering a PIN using the phone keypad.
14+
15+
16+
## Create an IAM User and Access Key
17+
18+
Services in Tencent Cloud, such as SCF, require that you provide credentials when you access them to ensure that you have permission to access the resources owned by that service. To accomplish this Tencent Cloud recommends that you use Cloud Access Management (CAM).
19+
20+
You need to create credentials Serverless can use to create resources in your Project.
21+
1. Login to your account and go to the [Cloud Access Management (CAM) page](https://console.cloud.tencent.com/cam/capi).
22+
2. Click on **Access Key** and then **Create Key**.
23+
3. View and copy the **APPID**, **SecretId** & **SecretKey** to a temporary place. (To get the SecretKey, you may need to enter a PIN using the phone keypad.)
24+
4. Create a file named `credentials` containing the credentials that you have collected.
25+
```ini
26+
[default]
27+
tencent_appid = 1251000000
28+
tencent_secret_id = AKIDteBxxxxxxxxxxnZfk
29+
tencent_secret_key = AKID2qsxxxxxxxxxxxxxtTo
30+
```
31+
Save the credentials file to a folder like`~/.tencent/credentials`. Copy the path of the file you saved.
32+
33+
## Update `serverless.yml` (optional)
34+
35+
Open up your `serverless.yml` file and update the `provider` section with
36+
the path to your credentials file (this path needs to be absolute). It should look something like this:
37+
38+
```yml
39+
provider:
40+
name: tencent
41+
credentials: ~/.tencent/credentials
42+
```

docs/en/deploy-function.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
# Tencent-scf - Deploy Function
3+
4+
The `sls deploy function` command deploys an individual SCF function when there is any change in the function. This is a much faster way of deploying changes in code.
5+
6+
```bash
7+
serverless deploy function -f functionName
8+
```
9+
10+
## Options
11+
12+
- `--function` or `-f` The name of the function which should be deployed
13+
- `--stage` or `-s` The stage in your service that you want to deploy to.
14+
- `--region` or `-r` The region in that stage that you want to deploy to.
15+
16+
## Examples
17+
18+
### Deployment without stage and region options
19+
20+
```bash
21+
serverless deploy function --function helloWorld
22+
```
23+
24+
### Deployment with stage and region options
25+
26+
```bash
27+
serverless deploy function --function helloWorld --stage dev --region ap-guangzhou
28+
```

docs/en/deploy-list.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
# Tencent-scf - Deploy List
3+
4+
The `sls deploy list [functions]` command will list information about your deployments.
5+
6+
You can either see all available deployments in your COS deployment bucket by running `serverless deploy list` or you can see the deployed functions by running `serverless deploy list functions`.
7+
8+
The displayed information is useful when rolling back a deployment or function via `serverless rollback`.
9+
10+
## Options
11+
12+
- `--stage` or `-s` The stage in your service that you want to deploy to.
13+
- `--region` or `-r` The region in that stage that you want to deploy to.
14+
15+
## Examples
16+
17+
### List existing deploys
18+
19+
```bash
20+
serverless deploy list
21+
```
22+
23+
### List deployed functions and their versions
24+
25+
```bash
26+
serverless deploy list functions
27+
```

docs/en/deploy.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
# Tencent-scf - deploy
3+
4+
The `sls deploy` command deploys your entire service. Run this command when you have made infrastructure changes (i.e., you edited `serverless.yml`). Use `serverless deploy function -f myFunction` when you have made code changes and you want to quickly upload your updated code to Tencent SCF (Serverless Cloud Functions) or just change function configuration.
5+
6+
```bash
7+
serverless deploy
8+
```
9+
10+
## Options
11+
12+
- `--config` or `-c` Name of your configuration file, if other than `serverless.yml|.yaml|.js|.json`.
13+
- `--stage` or `-s` The stage in your service that you want to deploy to.
14+
- `--region` or `-r` The region in that stage that you want to deploy to.
15+
- `--package` or `-p` path to a pre-packaged directory and skip packaging step.
16+
- `--force` Forces a deployment to take place.
17+
- `--function` or `-f` Invoke `deploy function` (see above). Convenience shortcut - cannot be used with `--package`.
18+
19+
## Artifacts
20+
21+
After the `serverless deploy` command runs, the framework runs `serverless package` in the background first then deploys the generated package. During the deployment, the framework creates a COS(Cloud Object Storage) bucket to storage the package by default.
22+
23+
## Examples
24+
25+
### Deployment without stage and region options
26+
27+
```bash
28+
serverless deploy
29+
```
30+
31+
This is the simplest deployment usage possible. With this command Serverless will deploy your service to the defined
32+
provider in the default stage (`dev`) to the default region (`ap-guangzhou`).
33+
34+
35+
### Deployment with stage and region options
36+
37+
```bash
38+
serverless deploy --stage pro --region ap-guangzhou
39+
```
40+
41+
With this example we've defined that we want our service to be deployed to the `pro` stage in the region
42+
`ap-guangzhou`.
43+
44+
### Deployment from a pre-packaged directory
45+
46+
```bash
47+
serverless deploy --package /path/package/directory
48+
```
49+
50+
With this example, the packaging step will be skipped and the framework will start deploying the package from the `/path/package/directory` directory.

docs/en/deploying.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
# Tencent-SCF - Deploying
3+
4+
The Serverless Framework was designed to provision your Serverless Cloud Functions, Events and infrastructure Resources safely and quickly. It does this via a couple of methods designed for different types of deployments.
5+
6+
## Deploy All
7+
8+
This is the main method for doing deployments with the Serverless Framework:
9+
10+
```bash
11+
serverless deploy
12+
```
13+
14+
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 Amazon Web Services.
15+
16+
**Note:** You can always enforce a deployment using the `--force` option, or specify a different configuration file name with the the `--config` option.
17+
18+
19+
### Tips
20+
21+
- Use this in your CI/CD systems, as it is the safest method of deployment.
22+
- You can print the progress during the deployment if you use `verbose` mode, like this:
23+
```
24+
serverless deploy --verbose
25+
```
26+
- This method defaults to `dev` stage and `ap-guangzhou` region. You can change the default stage and region in your `serverless.yml` file by setting the `stage` and `region` properties inside a `provider` object as the following example shows:
27+
28+
```yml
29+
# serverless.yml
30+
31+
service: service-name
32+
provider:
33+
name: tencent
34+
stage: production
35+
region: ap-beijing
36+
```
37+
38+
- You can also deploy to different stages and regions by passing in flags to the command:
39+
40+
```
41+
serverless deploy --stage production --region ap-beijing
42+
```
43+
44+
- You can specify your own COS bucket which should be used to store all the deployment artifacts.
45+
The `cosBucket` config which is nested under `provider` lets you e.g. set the `name` for this bucket. If you don't provide your own bucket, Serverless will create a bucket which by default.
46+
47+
48+
## Deploy Function
49+
50+
This deployment method simply overwrites the zip file of the current function on Tencent Cloud.
51+
52+
```bash
53+
serverless deploy function --function myFunction
54+
```
55+
56+
### Tips
57+
58+
- Use this when you are developing and want to test because it's much faster.
59+
- During development, people will often run this command several times, as opposed to `serverless deploy` which is only run when larger infrastructure provisioning is required.
60+
61+
Check out the [deploy command docs](../cli-reference/deploy.md) for all details and options.

docs/en/events.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2+
# Tencent-SCF - Events
3+
4+
Simply put, events are the things that trigger your functions to run.
5+
6+
If you are using Tencent as your provider, all `events` in the service are anything in Tencent Cloud that can trigger an Serverless Cloud Function, like an COS bucket upload, an Cloud Kafka topic, and HTTP endpoints created via API Gateway.
7+
8+
[View the events section for a list of supported events](./events)
9+
10+
## Configuration
11+
12+
Events belong to each Function and can be found in the `events` property in `serverless.yml`.
13+
14+
```yml
15+
# 'functions' in serverless.yml
16+
functions:
17+
createUser: # Function name
18+
handler: handler.createUser # Reference to file handler.js & exported function 'createUser'
19+
events: # All events associated with this function
20+
- timer:
21+
name: timer
22+
parameters:
23+
cronExpression: '*/5 * * * *'
24+
enable: true
25+
```
26+
27+
Events are objects, which can contain event-specific information.
28+
29+
The `events` property is an array, because it's possible for functions to be triggered by multiple events, as shown.
30+
31+
You can set multiple Events per Function, as long as that is supported by Tencnet Cloud and doesn't reach the limit.
32+
33+
```yml
34+
# 'functions' in serverless.yml
35+
functions:
36+
createUser: # Function name
37+
handler: handler.users # Reference to file handler.js & exported function 'users'
38+
events: # All events associated with this function
39+
- apigw:
40+
name: hello_world_apigw1
41+
parameters:
42+
stageName: release
43+
serviceId:
44+
httpMethod: ANY
45+
- apigw:
46+
name: hello_world_apigw2
47+
parameters:
48+
stageName: test
49+
serviceId:
50+
httpMethod: PUT
51+
```
52+
53+
## Types
54+
55+
The Serverless Framework supports all of the Serverless Cloud Function events. Instead of listing them here, we've put them in a separate section, since they have a lot of configurations and functionality. [Check out the events section for more information.](../events)
56+
57+
## Deploying
58+
59+
To deploy or update your Functions, Events and Infrastructure, run `serverless deploy`.

docs/en/events/CKafka.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
# CKafka (Cloud Kafka)
3+
4+
## Using a pre-existing CKafka topic
5+
6+
In the following example we choose a pre-existing CKafka topic with name `ckafka_trigger`. The function will be called every time a message is sent to the `test` topic.
7+
8+
```yml
9+
functions:
10+
function_one:
11+
handler: index.main_handler
12+
runtime: Nodejs8.9
13+
events:
14+
- ckafka:
15+
name: ckafka_trigger
16+
parameters:
17+
name: ckafka-2o10hua5 # ckafka-id
18+
topic: test
19+
maxMsgNum: 999
20+
offset: latest
21+
enable: true
22+
```
23+
24+
**Note:** CKafka triggers are enabled by default, and the consumer of CKafka will start to get the message from the `latest` offset.
25+
26+
## Event Message Structure for CKafka Trigger
27+
28+
When the specified CKafka topic receives a message, the backend consumer module of SCF will consume the message and encapsulate the message into an event in JSON format like the one below, which triggers the bound function and pass the data content as input parameters to the function.
29+
30+
```json
31+
{
32+
"Records": [
33+
{
34+
"Ckafka": {
35+
"topic": "test-topic",
36+
"partition":1,
37+
"offset":36,
38+
"msgKey": "None",
39+
"msgBody": "Hello from Ckafka!"
40+
}
41+
},
42+
{
43+
"Ckafka": {
44+
"topic": "test-topic",
45+
"partition":1,
46+
"offset":37,
47+
"msgKey": "None",
48+
"msgBody": "Hello from Ckafka again!"
49+
}
50+
}
51+
]
52+
}
53+
```

0 commit comments

Comments
 (0)