Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 28 additions & 27 deletions docs/configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ inputs:
variables: # 环境变量对象
TEST: value
publicAccess: true # 是否开启公网访问
installDependency: false # 是否在线安装依赖
vpcConfig: # 私有网络配置
vpcId: vpc-xxx # 私有网络的Id
subnetId: subnet-xxx # 子网ID
Expand Down Expand Up @@ -188,32 +189,33 @@ inputs:

参考: https://cloud.tencent.com/document/product/583/18586

| 参数名称 | 必选 | 类型 | 默认值 | 描述 |
| -------------- | ---- | --------------------------- | ------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------- |
| name | 是 | string | `${name}-${stage}-${app}` | 创建的函数名称。**云函数名称又是资源 ID,为了保证资源的唯一性,默认采用 `${name}-${stage}-${app}` 变量方式。** |
| namespace | 否 | string | `default` | 函数命名空间。云函数旧版本会以命名空间作为环境隔离,SCF 组件保留此参数,但不推荐使用此方式进行隔离。 |
| src | 是 | [Src](#Src) | | 函数代码路径。如果是对象,配置参数参考 |
| handler | 是 | string | | 函数处理方法名称,执行方法表明了调用云函数时需要从哪个文件中的哪个函数开始执行 |
| role | 否 | string | | 云函数绑定的运行角色。 |
| runtime | 否 | string | `Nodejs10.15` | 函数运行环境 |
| region | 否 | string | `ap-guangzhou` | 云函数所在区域。详见产品支持的 [地域列表][函数地域列表]。 |
| description | 否 | string | `This is a function in ${app} application` | 函数描述,最大支持 1000 个英文字母、数字、空格、逗号、换行符和英文句号,支持中文 |
| memorySize | 否 | number | `128` | 函数运行时内存大小,默认为 128M,可选范围 64、128MB-3072MB,并且以 128MB 为阶梯 |
| timeout | 否 | number | `3` | 函数最长执行时间,单位为秒,可选值范围 1-900 秒,默认为 3 秒 |
| initTimeout | 否 | number | `3` | 函数初始化超时时间,单位为秒,可选值范围 1-30 秒 秒 |
| eip | 否 | boolean | `false` | 是否[固定出口 IP][固定出口ip] |
| publicAccess | 否 | number | `true` | 是否开启公网访问 |
| environment | 否 | [Environment](#Environment) | | 函数的环境变量,配置参考[环境变量](#环境变量) |
| vpcConfig | 否 | [Vpc](#Vpc) | | 函数的私有网络配置,配置参数参考[私有网络](#私有网络) |
| layers | 否 | [Layer](#Layer)[] | | 云函数绑定的 layer, 配置参数参考[层配置](#层配置) |
| deadLetter | 否 | [DeadLetter](#DeadLetter) | | 死信队列配置,配置参数参考[死信队列](#死信队列) |
| cls | 否 | [Cls](#Cls) | | 函数日志配置,配置参数参考[函数日志](#函数日志) |
| eip | 否 | boolean | `false` | 固定出口 IP。默认为 false,即不启用。 |
| asyncRunEnable | 否 | boolean | `false` | 是否启用异步执行(长时间运行),默认最大支持 `12小时`,如果配置为 `true`,`cls`(函数日志配置) 必须。此参数只有在函数创建时才有效 |
| traceEnable | 否 | boolean | `false` | 是否启用状态追踪,如果要配置为 `true`,必须配置 `asyncRunEnable` 同时为 `true` |
| tags | 否 | | | 标签设置。可设置多对 key-value 的键值对 |
| cfs | 否 | [Cfs](#Cfs) | | 文件系统挂载配置,用于云函数挂载文件系统。配置参数参考[文件系统](#文件系统)。 |
| events | 否 | [Event](#Event)[] | | 触发器配置 |
| 参数名称 | 必选 | 类型 | 默认值 | 描述 |
| ----------------- | ---- | --------------------------- | ------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------- |
| name | 是 | string | `${name}-${stage}-${app}` | 创建的函数名称。**云函数名称又是资源 ID,为了保证资源的唯一性,默认采用 `${name}-${stage}-${app}` 变量方式。** |
| namespace | 否 | string | `default` | 函数命名空间。云函数旧版本会以命名空间作为环境隔离,SCF 组件保留此参数,但不推荐使用此方式进行隔离。 |
| src | 是 | [Src](#Src) | | 函数代码路径。如果是对象,配置参数参考 |
| handler | 是 | string | | 函数处理方法名称,执行方法表明了调用云函数时需要从哪个文件中的哪个函数开始执行 |
| role | 否 | string | | 云函数绑定的运行角色。 |
| runtime | 否 | string | `Nodejs10.15` | 函数运行环境 |
| region | 否 | string | `ap-guangzhou` | 云函数所在区域。详见产品支持的 [地域列表][函数地域列表]。 |
| description | 否 | string | `This is a function in ${app} application` | 函数描述,最大支持 1000 个英文字母、数字、空格、逗号、换行符和英文句号,支持中文 |
| memorySize | 否 | number | `128` | 函数运行时内存大小,默认为 128M,可选范围 64、128MB-3072MB,并且以 128MB 为阶梯 |
| timeout | 否 | number | `3` | 函数最长执行时间,单位为秒,可选值范围 1-900 秒,默认为 3 秒 |
| initTimeout | 否 | number | `3` | 函数初始化超时时间,单位为秒,可选值范围 1-30 秒 秒 |
| eip | 否 | boolean | `false` | 是否[固定出口 IP][固定出口ip] |
| publicAccess | 否 | number | `true` | 是否开启公网访问 |
| environment | 否 | [Environment](#Environment) | | 函数的环境变量,配置参考[环境变量](#环境变量) |
| vpcConfig | 否 | [Vpc](#Vpc) | | 函数的私有网络配置,配置参数参考[私有网络](#私有网络) |
| layers | 否 | [Layer](#Layer)[] | | 云函数绑定的 layer, 配置参数参考[层配置](#层配置) |
| deadLetter | 否 | [DeadLetter](#DeadLetter) | | 死信队列配置,配置参数参考[死信队列](#死信队列) |
| cls | 否 | [Cls](#Cls) | | 函数日志配置,配置参数参考[函数日志](#函数日志) |
| eip | 否 | boolean | `false` | 固定出口 IP。默认为 false,即不启用。 |
| asyncRunEnable | 否 | boolean | `false` | 是否启用异步执行(长时间运行),默认最大支持 `12小时`,如果配置为 `true`,`cls`(函数日志配置) 必须。此参数只有在函数创建时才有效 |
| traceEnable | 否 | boolean | `false` | 是否启用状态追踪,如果要配置为 `true`,必须配置 `asyncRunEnable` 同时为 `true` |
| installDependency | 否 | boolean | `false` | 是否自动在线安装依赖 |
| tags | 否 | | | 标签设置。可设置多对 key-value 的键值对 |
| cfs | 否 | [Cfs](#Cfs) | | 文件系统挂载配置,用于云函数挂载文件系统。配置参数参考[文件系统](#文件系统)。 |
| events | 否 | [Event](#Event)[] | | 触发器配置 |

**重要字段说明**

Expand Down Expand Up @@ -303,7 +305,6 @@ cmq - CMQ 主题订阅触发器
ckafka - CKafka 触发器
cls - CLS 触发器
mps - MPS 触发器
clb - CLB 触发器
```

> **注意**:对于 `API 网关触发器`,如果没有配置 网关服务 ID (serviceId),则自动创建一个 API 网关服务,对于其他触发器仅执行配置触发器,不涉及服务资源创建。
Expand Down
14 changes: 14 additions & 0 deletions example/src/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "demo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT",
"dependencies": {
"express": "^4.17.1"
}
}
4 changes: 3 additions & 1 deletion serverless.component.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: scf
version: 0.6.1
version: 0.6.2
author: Tencent Cloud, Inc.
org: Tencent Cloud, Inc.
description: Deploy a serverless cloud function on Tencent Cloud.
Expand Down Expand Up @@ -110,6 +110,8 @@ actions:
type: boolean
eip:
type: boolean
installDependency:
type: boolean
asyncRunEnable:
type: boolean
l5Enable:
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"dependencies": {
"download": "^8.0.0",
"tencent-component-toolkit": "^2.8.1",
"tencent-component-toolkit": "^2.9.5",
"type": "^2.0.0"
}
}
15 changes: 11 additions & 4 deletions src/serverless.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,18 @@ class ServerlessComponent extends Component {
const credentials = this.getCredentials()
const region = inputs.region || CONFIGS.region

const functionInfo = this.state.function
const functionName = inputs.function || (functionInfo && functionInfo.FunctionName)

const alias_params = {}
alias_params.functionName = inputs.function
alias_params.functionName = functionName
alias_params.functionVersion = inputs.version
alias_params.namesapce = inputs.namespace

console.log(`list alias for function ${inputs.function}...`)
console.log(`List alias for function ${inputs.function}...`)
const scf = new Scf(credentials, region)

const scfOutput = await scf.alias.list(alias_params)
console.log(`list alias for function ${inputs.function}...`)

const aliases = scfOutput.Aliases
const listAlias = {
Expand Down Expand Up @@ -199,6 +201,9 @@ class ServerlessComponent extends Component {
const credentials = this.getCredentials()
const region = inputs.region || CONFIGS.region

const functionInfo = this.state.function
inputs.function = inputs.function || (functionInfo && functionInfo.FunctionName)

const alias_params = prepareAliasInputs(inputs)

if (alias_params.isPramasError) {
Expand All @@ -210,7 +215,6 @@ class ServerlessComponent extends Component {
console.log(`Creating alias for function ${inputs.function}...`)
const scf = new Scf(credentials, region)
await scf.alias.create(alias_params)
console.log(`Creating alias for function ${inputs.function}...`)

const aliasOutput = await scf.alias.get(alias_params)

Expand All @@ -228,6 +232,9 @@ class ServerlessComponent extends Component {
const credentials = this.getCredentials()
const region = inputs.region || CONFIGS.region

const functionInfo = this.state.function
inputs.function = inputs.function || (functionInfo && functionInfo.FunctionName)

const alias_params = prepareAliasInputs(inputs)

if (alias_params.isPramasError) {
Expand Down