Skip to content

function字段

function 字段

参数名必填类型参数描述
nameTrueStringfunction 名称
descriptionFalseStringfunction 的简短描述
codeUriFalseString代码位置
ossBucketFalseString代码存放的 oss 存储桶
ossKeyFalseString如果指定 oss 代码,所对应的对象,不能与 codeUri 同时出现
handlerFalseStringfunction 执行的入口,具体格式和语言相关
memorySizeFalseNumberfunction 的内存规格
runtimeTrueString运行时
timeoutFalseNumberfunction 运行的超时时间
caPortFalseNumberCustomContainer/Runtime 指定端口
cpuFalseNumber函数的 CPU 规格,单位为 vCPU,为 0.05 vCPU 的倍数。
diskSizeFalseNumber函数的磁盘规格,单位为 MB,可选值为 512 MB 或 10240 MB。
customContainerConfigFalseStruct自定义镜像配置
customHealthCheckConfigFalseStruct函数自定义健康检查配置,仅适用于 Custom Runtime 和 Custom Container。
environmentVariablesFalseStruct环境变量
initializationTimeoutFalseNumber初始化方法超时时间
initializerFalseString初始化方法
instanceConcurrencyFalseNumber单实例多并发
instanceSoftConcurrencyFalseNumber扩容并发度。扩容并发度用于优雅扩容,当实例上并发数超过扩容并发度时,会触发实例扩容。例如,您的实例启动较慢,可以通过设置合适的扩容并发度,提前启动实例。注意:扩容并发度的值不能大于实例并发度,最小值为1。线上存在此配置,但是yaml中没有配置,则默认为和 instanceConcurrency 值一致
instanceTypeFalseString函数实例类型,可选值为:e1(弹性实例)、c1(性能实例)、fc.gpu.tesla.1(GPU T4实例)、fc.gpu.ampere.1(GPU A10实例)
gpuMemorySizeFalseNumberGPU 实例内存规格
layersFalseList<String>函数绑定层,支持 Nodejs、Python、Custom、Go1;取值是层的 ARN
instanceLifecycleConfigFalseStruct扩展函数
asyncConfigurationFalseStruct异步配置
customDNSFalseStructDNS 配置
customRuntimeConfigFalseStruct自定义运行时启动配置

参考案例:

function:
name: event-function
description: this is a test
runtime: nodejs12
codeUri: ./
handler: index.handler
memorySize: 128
timeout: 60

账号需要的函数权限

最大权限

AliyunFCFullAccess

部署最小权限

⚠️ fc:GetFunctionAsyncInvokeConfig 选填,不影响使用

{
"Statement": [
{
"Action": ["fc:GetFunction", "fc:CreateFunction", "fc:UpdateFunction"],
"Effect": "Allow",
"Resource": "acs:fc:<region>:<account-id>:services/<service-name>/functions/*"
}
],
"Version": "1"
}

删除最小权限

{
"Version": "1",
"Statement": [
{
"Action": "fc:DeleteFunction",
"Resource": "acs:fc:<region>:<account-id>:services/<serviceName>/functions/<functionName>",
"Effect": "Allow"
}
]
}

runtime

runtime 目前支持

nodejs14nodejs12nodejs10nodejs8nodejs6nodejs4.4
python3.10python3.9python3python2.7
java11java8
go1
php7.2
dotnetcore2.1
customcustom.debian10custom-container

当 runtime 为 custom-container 服务角色权限:

系统策略AliyunContainerRegistryReadOnlyAccess

customHealthCheckConfig

参数名必填类型参数描述
httpGetUrlTrueString容器自定义健康检查 URL 地址。长度不超过 2048 个字符。
initialDelaySecondsFalseNumber容器启动到发起健康检查的延迟。取值范围 0~120。默认值为 0。
periodSecondsFalseNumber健康检查周期。取值范围 1~120。默认值为 3。
timeoutSecondsFalseNumber健康检查超时时间。取值范围 1~3。默认值为 1。
failureThresholdFalseNumber健康检查失败次数阈值,达到该值后系统认为检查失败。取值范围 1~120。默认值为 3。
successThresholdFalseNumber健康检查成功次数阈值,达到该值后系统认为检查成功。取值范围 1~120。默认值为 1。

customContainerConfig

参数名必填类型参数描述
imageTrueString容器镜像仓库地址
commandFalseString容器启动指令,示例值: ’[“/code/myserver”]‘
argsFalseString容器启动参数,示例值: ’[“-arg1”, “value1”]‘
accelerationTypeFalseString镜像加速开关,可选值:‘Default’、‘None’,前者表示开启,后者表示关闭
instanceIDFalseString容器镜像服务企业版实例的 ID。当容器镜像选择的是企业版实例时,您需要给容器镜像服务企业版添加实例 ID,该实例的默认解析必须是服务所在的 VPC 网络地址。目前不支持 PrivateZone 产品定义域名解析
webServerModeFalseBoolean镜像运行是否为Web Server模式。取值为true,表示需要在容器镜像中实现Web Server来监听端口并处理请求。取值为false,表示需要容器运行后主动退出进程,并且ExitCode需要为0。

environmentVariables

Object 格式,例如:

DB_connection: jdbc:mysql://rm-bp90434sds45c.mysql.rds.aliyuncs.com:3306/litemall

当然不推荐通过明文将敏感信息写入到s.yaml, 可以配合.env 使用。 如果在 CICD流水线环境中,也可以通过export DB_connection=xxx到临时环境变量, 再配合${env(DB_connection)}$env 文档)进行引用

instanceLifecycleConfig

参数名必填类型参数描述
preFreezeFalseStructPreFreeze 函数
preStopFalseStructPreStop 函数

preFreeze 和 preStop

参数名必填类型参数描述
handlerTrueString函数入口
timeoutFalseNumber超时时间

asyncConfiguration

参数名必填类型参数描述
maxAsyncEventAgeInSecondsFalseNumber消息最大存活时长,取值范围[1,2592000]。单位:秒
maxAsyncRetryAttemptsFalseNumber异步调用失败后的最大重试次数,默认值为 3。取值范围[0,8]
statefulInvocationFalseBoolean是否开启有状态异步调用
destinationFalseStruct异步调用目标的配置结构体

customDNS

参数名必填类型参数描述
nameServersFalseList<String>DNS 服务器的 IP 地址列表
searchesFalseList<String>DNS 搜索域列表
dnsOptionsFalseList<Struct>对应 resolv.conf DNS 配置的 Options 项

customRuntimeConfig

参数名必填类型参数描述
commandTrueList<String>启动指令,示例值: [“/code/myserver”]
argsFalseList<String>启动参数,示例值: [“-arg1”, “value1”]

dnsOptions

参数名必填类型参数描述
nameTrueString对应 resolv.conf DNS 配置的 Options 项的键
valueTrueString对应 resolv.conf DNS 配置的 Options 项的值

权限配置相关

服务角色权限
  • 配置了 fc:AliyunFCInvocationAccess
  • 配置了 mns
{
"Action":[
"mns:SendMessage",
"mns:PublishMessage"
],
"Resource":"*",
"Effect":"Allow"
}
子账号需要的权限
最大权限

系统策略AliyunFCFullAccessAliyunMNSReadOnlyAccess【查看消息服务(MNS)的权限】、AliyunEventBridgeReadOnlyAccess【事件总线(EventBridge)的权限】、AliyunMQReadOnlyAccess【消息队列(MQ)的权限】、AliyunFCInvocationAccess【调用函数权限】

最小权限

系统策略

  • 如果配置了 mns 相关 AliyunMNSReadOnlyAccess
  • 如果配置了 EventBridge 相关 AliyunEventBridgeReadOnlyAccess
  • 如果配置了 MQ 相关 AliyunMQReadOnlyAccess

自定义策略

{
"Version": "1",
"Statement": [
{
"Action": "fc:*Service",
"Resource": "*",
"Effect": "Allow"
},
{
"Action": ["fc:GetFunction", "fc:CreateFunction", "fc:UpdateFunction"],
"Effect": "Allow",
"Resource": "acs:fc:<region>:<account-id>:services/unit-deploy-service/functions/*"
},
{
"Action": [
"fc:InvokeFunction",
"fc:GetFunctionAsyncInvokeConfig",
"fc:DeleteFunctionAsyncInvokeConfig",
"fc:PutFunctionAsyncInvokeConfig"
],
"Effect": "Allow",
"Resource": "acs:fc:<region>:<account-id>:services/unit-deploy-service.*/functions/*"
},
{
"Action": "ram:PassRole",
"Effect": "Allow",
"Resource": "*"
}
]
}

destination

参数名必填类型参数描述
onSuccessFalseString异步调用成功的目标服务
onFailureFalseString异步调用失败的目标服务