更新时间:2025-06-28 gmt 08:00

cam.yaml解析-j9九游会登录

示例

metadata:
  description: this is an example application for functiongraph.
  author: serverless team
  homepageurl: https://www.huaweicloud.com/product/functiongraph.html
  version: 1.0.0
components:
  - name: helloworld
    type: huawei::functiongraph::function
    properties:
      region: cn-east-4
      codeuri: https://test-wkx.obs.cn-north-4.myhuaweicloud.com/helloworld.zip
      projectid: 0531e14952000f742f3ec0088c4b25cf
      handler: index.handler
      runtime: python3.9
      memorysize: 256
      timeout: 60
      userdata:
        key1: value1
        key2: value2
      encrypteduserdata: '{"nonce": "zeuorefaiahrbmz k9xqwa==", "header": "agvhzgvy", "ciphertext": "scxxsffvpu1bf2ci8a2rednq", "tag": "a eyrvposq ypqkmufg1wa=="}'
      initializertimeout: 30
      initializerhandler: index.init_handler
      strategyconfig:
        concurrency: 80
        concurrentnum: 20

详解

函数配置在cam.yaml的properties属性下,当前支持的函数配置详解如下:

参数

是否必须

是否更新

描述

region

调用函数所在region。

codeuri

函数代码地址。该值为函数代码包在obs上的地址。

projectid

租户project id。

handler

函数执行入口。

runtime

functiongraph函数的执行环境支持node.js6.10、python2.7、python3.6、php7.3、java8、node.js 8.10、c#.net core 2.0、c#.net core 2.1。

python2.7: python语言2.7版本。

python3.6: python语言3.6版本。

php7.3: php语言7.3版本。

java8: java语言8版本。

node.js6.10: nodejs语言6.10版本。

node.js8.10: nodejs语言8.10版本。

c#(.net core 2.0): c#语言2.0版本。

c#(.net core 2.1): c#语言2.1版本。

c#(.net core 3.1): c#语言3.1版本。

custom: 自定义运行时。

memorysize

函数内存,单位m。

枚举值:

128、256、512、768、1024、1280、1536、1792、2048、2560、3072、3584、4096

timeout

函数运行超时时间,单位秒,范围3~900秒。

userdata

用户自定义的name/value信息,在函数中使用的参数。

encrypteduserdata

用户自定义的name/value信息,用于需要加密的配置。

initializertimeout

初始化超时时间,超时函数将被强行停止,范围1~300秒。

initializerhandler

函数初始化入口,规则:xx.xx,必须包含“. ”。 举例:对于node.js函数:myfunction.initializer,则表示函数的文件名为myfunction.js,初始化的入口函数名为initializer。

concurrentnum

函数单实例并发数。

concurrency

单函数最大实例数,0禁用函数,-1无限制,例100,该函数最大实例数100(普通实例 预留实例)。

  1. 当前cam.yaml不支持vpc、委托、磁盘挂载和动态内存配置的更新,如果函数需要使用vpc、委托或者磁盘挂载和动态内存请在函数界面手动配置,在使用函数更新流水线时会保留vpc、委托、磁盘挂载和动态内存配置,不会覆盖掉。
  2. 为了避免在cam.yaml中明文显示函数的加密配置-encrypteduserdata,该cicd使用了aes对称加密的gcm模式对encrypteduserdata明文内容进行加密,加密输出配置为cam.yaml中encrypteduserdata项对应的值。在functions仓库和“函数更新流水线”中encrypteduserdata的值以密文传输,在最后部署更新函数时解密更新,所以在执行“函数更新流水线”时需提供aes加密时使用的key。示例如下:

    encrypteduserdata明文:

    '{"password":"123"}'

    使用aes-gcm加密后:

    {"nonce": "zeuorefaiahrbmz k9xqwa==", "header": "agvhzgvy", "ciphertext": "scxxsffvpu1bf2ci8a2rednq", "tag": "a eyrvposq ypqkmufg1wa=="},其中ciphertext为加密后的密文。

aes加密使用的key需妥善保管

python aes-gcm使用示例:

aes-gcm加密脚本如下:

import json
from base64 import b64encode
from crypto.cipher import aes
import sys
if __name__ == '__main__':
    key = sys.argv[1].encode()
    data = sys.argv[2].encode()
    header = b"header"
    cipher = aes.new(key, aes.mode_gcm)
    cipher.update(header)
    ciphertext, tag = cipher.encrypt_and_digest(data)
    json_k = ['nonce', 'header', 'ciphertext', 'tag']
    json_v = [b64encode(x).decode('utf-8') for x in
              [cipher.nonce, header, ciphertext, tag]]
    result = json.dumps(dict(zip(json_k, json_v)))
    print(result)

使用方式为在ecs云服务器上执行如下命令:

python3 aes_gcm_encrypt_tool.py "16个字节的key" '{"password":"123"}',在ecs云服务器上执行。

相关文档

网站地图