本文介绍如何通过Serverless Devs工具克隆函数。
前提条件
- 已安装并配置Serverless Devs工具。具体操作,请参见安装Serverless Devs和配置Serverless Devs。
- 已创建服务和函数。服务和函数名称均为
sync-test,所在地域为华东1(杭州)。具体操作,请参见创建服务和创建函数。
操作步骤
- 执行以下命令克隆测试函数
sync-test。s cli fc sync --region cn-hangzhou --service-name sync-test --function-name sync-test -a default克隆完成后,您可以看到函数已被克隆到本地当前目录。[root@iZbp1fufb1pctjjxxx]# s cli fc sync --region cn-hangzhou --service-name sync-test --function-name sync-test -a default ✓ devsapp_fc-sync.zip file decompression completed ✓ devsapp_fc-common.zip file decompression completed [2023-01-09 18:03:59] [INFO] [FC-SYNC] - sync code to /root/16490154655xxx_cn-hangzhou_sync-test_sync-test ✓ 16490154655xxx_cn-hangzhou_sync-test_sync-test.zip file decompression completed You can deploy the latest configuration of your sync through the [s exec -t /root/s.yaml -- sync] command. codeFiles: sync-test: /root/16490154655xxx_cn-hangzhou_sync_test_sync-test configYmlPath: /root/s.yaml - 修改工作目录下的
s.yaml文件,服务名称修改为sync-test,函数名称修改为sync-clone,然后执行以下命令部署函数。function: description: hello world by serverless devs runtime: nodejs14 handler: index.handler timeout: 60 memorySize: 128 environmentVariables: {} instanceConcurrency: 1 instanceType: e1 name: sync-clone codeUri: /root/16490154655xxx_cn-hangzhou_sync_test_sync_tests deploy执行完成后,您可以登录函数计算控制台查看已克隆的函数。在函数列表中,可以看到已克隆生成的函数 sync-clone,其运行环境与源函数 sync-test 一致,均为 Node.js 14 / 128 MB / 0.08 vCPU。
该文章对您有帮助吗?