文档

Serverless Devs工具使用FAQ

更新时间:
一键部署

本文介绍使用Serverless Devs工具过程中可能遇到的问题,并提供对应的解决方案。

如何配置s.yaml文件?

关于YAML规范的详细信息,请参见YAML规范

使用Serverless Devs偶然出现异常,但未提示错误信息怎么办?

您可以按照以下步骤排查问题。

  1. 执行命令npm install @serverless-devs/s3 -g升级工具。

  2. 执行命令s clean --all删除所有组件及冗余文件。

  3. 执行s -v查看工具版本。

    如果执行命令后无任何响应,可能是本地Node.js环境异常,需重新安装Node.js 14或以上的版本。

如果问题还未解决,请加入钉钉用户群(钉钉群号11721331),并提供日志文件和s.yaml文件,联系函数计算开发工程师帮您解决。

关于日志文件的获取方式,请参见下图。

image.png

部署代码时,希望以本地配置为准如何处理?

您可以在执行命令s deploy时,选择-y参数,即s deploy -y

Serverless Devs工具支持多Region部署吗?

支持。具体操作,请参见以下示例。

Shell脚本

```bash
#!/bin/bash
regions=("cn-hangzhou" "ap-southeast-1")
for r in ${regions[@]}
do
  export REGION=$r
  s deploy -y
done
```

s.yaml示例

```yaml
edition: 3.0.0
name: hello-world-app
access: "default"
resources:
  hello_world:
    component: fc3
    props:
      region: ${env('REGION')}
      functionName: "start-nodejs-im1g"
      description: 'hello world by serverless devs'
      runtime: "nodejs14"
      code: ./code
      handler: index.handler
      memorySize: 128
      timeout: 30
```

如何本地调试函数?

  • 如果您的Runtime不是Custom Runtime或Custom Container,而是函数计算内置语言,例如Node.js、Python等,推荐使用Serverless Devs工具的本地调用方式进行调试。具体操作,请参见Local命令

  • 如果您的Runtime是Custom Runtime或Custom Container,可以按照正常的开发习惯启动一个Server代码调试流程。

    说明

    针对Custom Runtime,s local invoke命令能正常发起函数本地执行,但不支持断点调试。

怎样使用.fcignore文件?

您可以在代码指定目录下配置一个.fcignore文件,.fcignore文件用于定义忽略相关文件或者将文件夹打包到函数代码的ZIP包。更多信息,请参见.fcignore使用方法

s.yaml文件中定义了多个函数时如何指定部署和调用某个函数?

s.yaml文件中,可能存在一个服务对应多个函数的情况,如果只想部署或调用其中某一个函数,可以在执行命令s deploys infos local invoke时,指定资源名称。例如,s.yaml文件示例如下,包含多个函数,部署函数时可以执行s helloworld1 deploy只部署helloworld1函数。

```yaml
edition: 3.0.0
name: hello-world-app
access: "default"

resources:
  hello_world1:
    component: fc3
    props:
      region: cn-huhehaote       
      functionName: "hello_world1"
      description: 'hello world1 by serverless devs'
      runtime: "nodejs14"
      code: ./code
      handler: index.handler

  hello_world2:
    component: fc3
    props:
      region: cn-huhehaote       
      functionName: "hello_world2"
      description: 'hello world2 by serverless devs'
      runtime: "nodejs14"
      code: ./code
      handler: index.handler
```

如何基于Podman,使用Serverless Devs工具进行构建与本地调试?

使用Serverless Devs工具执行构建或本地调试函数时,如果基于Podman工具,会提示报错Failed to start docker, xxx,此时,您可以创建一个Docker目录软链接指向Podman的目录,然后再执行构建或本地调试。创建软链接的具体操作如下所示。

  1. 查询Podman可执行文件路径。

    which podman

    本文示例中Podman可执行文件路径为/usr/bin/podman

  2. 设置软链接。

    ln -s /usr/bin/podman /usr/bin/docker
  3. 查询软链接是否已生效。

    ls -lh /usr/bin/docker

    预期输出如下:

    lrwxrwxrwx 1 root root 15 Jan  5 09:30 /usr/bin/docker -> /usr/bin/podman

  • 本页导读 (1)
文档反馈