调用CreateFunction接口创建函数。
接口说明
通过 OSS 代码包创建函数时,如果提示报错 unable to access object xxx in bucket xxx,需要为当前用户授予 OSS Bucket 的访问权限,例如系统权限策略 AliyunOSSReadOnlyAccess 或自定义更小粒度的授权 oss:GetObject,策略内容详情请参见授予 RAM 用户读取某个 Bucket 下所有资源的权限。
调试
您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。
授权信息
下表是API对应的授权信息,可以在RAM权限策略语句的Action元素中使用,用来给RAM用户或RAM角色授予调用此API的权限。具体说明如下:
- 操作:是指具体的权限点。
- 访问级别:是指每个操作的访问级别,取值为写入(Write)、读取(Read)或列出(List)。
- 资源类型:是指操作中支持授权的资源类型。具体说明如下:- 对于必选的资源类型,用前面加 * 表示。
- 对于不支持资源级授权的操作,用全部资源表示。
 
- 条件关键字:是指云产品自身定义的条件关键字。
- 关联操作:是指成功执行操作所需要的其他权限。操作者必须同时具备关联操作的权限,操作才能成功。
| 操作 | 访问级别 | 资源类型 | 条件关键字 | 关联操作 | 
|---|---|---|---|---|
| fc:CreateFunction | create | *全部资源 * | 
 | 无 | 
请求语法
POST /2023-03-30/functions HTTP/1.1
请求参数
| 名称 | 类型 | 必填 | 描述 | 示例值 | 
|---|---|---|---|---|
| body | CreateFunctionInput | 是 | 函数配置信息 | 
返回参数
示例
正常返回示例
JSON格式
{
  "codeChecksum": "2825179536350****",
  "codeSize": 412,
  "cpu": 1,
  "createdTime": "2023-04-01T08:15:27Z",
  "customContainerConfig": {
    "accelerationInfo": {
      "status": "Ready"
    },
    "accelerationType": "Default",
    "acrInstanceId": "cri-xxxxxxxxxx",
    "command": [
      "arg1"
    ],
    "entrypoint": [
      "/code/bootstrap"
    ],
    "healthCheckConfig": {
      "failureThreshold": 1,
      "httpGetUrl": "/ready",
      "initialDelaySeconds": 1,
      "periodSeconds": 1,
      "successThreshold": 2,
      "timeoutSeconds": 2
    },
    "image": "registry-vpc.cn-hangzhou.aliyuncs.com/fc-demo/helloworld:v1beta1",
    "port": 9000,
    "registryConfig": {
      "authConfig": {
        "password": "abc***",
        "userName": "admin"
      },
      "certConfig": {
        "insecure": true,
        "rootCaCertBase64": "cm9vdF9jYV9jZXJ0"
      },
      "networkConfig": {
        "securityGroupId": "sg-xxxxxxxxxxxxxx",
        "vSwitchId": "vsw-xxxxxxxxxxxxxx",
        "vpcId": "vpc-xxxxxxxxxxxxxx"
      }
    },
    "resolvedImageUri": "stand-sh-registry-vpc.cn-shanghai.cr.aliyuncs.com/fc-demo2/springboot-helloworld@sha256:68d1****0d64d6"
  },
  "customDNS": {
    "dnsOptions": [
      {
        "name": "ndots",
        "value": 2
      }
    ],
    "nameServers": [
      "8.8.x.x"
    ],
    "searches": [
      "ns1.svc.cluster-domain.example"
    ]
  },
  "customRuntimeConfig": {
    "args": [
      "arg1"
    ],
    "command": [
      "/code/bootstrap"
    ],
    "healthCheckConfig": {
      "failureThreshold": 1,
      "httpGetUrl": "/ready",
      "initialDelaySeconds": 1,
      "periodSeconds": 1,
      "successThreshold": 2,
      "timeoutSeconds": 2
    },
    "port": 9000
  },
  "description": "my function",
  "diskSize": 512,
  "environmentVariables": {
    "key": "value1"
  },
  "functionArn": "acs:fc:cn-shanghai:123:functions/functionName",
  "functionId": "aa715851-1c20-4b89-a8fb-***",
  "functionName": "my-function-1",
  "gpuConfig": {
    "gpuMemorySize": 2048,
    "gpuType": "fc.gpu.tesla.1"
  },
  "handler": "index.handler",
  "instanceConcurrency": 1,
  "instanceLifecycleConfig": {
    "initializer": {
      "handler": "index.initializer",
      "timeout": 10,
      "command": [
        "curl -X POST 'http://localhost:9000/preWarm"
      ]
    },
    "preStop": {
      "handler": "index.initializer",
      "timeout": 10,
      "command": [
        "curl -X POST 'http://localhost:9000/preWarm"
      ]
    }
  },
  "internetAccess": true,
  "lastModifiedTime": "2023-05-01T08:15:27Z",
  "lastUpdateStatus": "InProgress",
  "lastUpdateStatusReason": "The system is currently processing the acceleration optimization for the image.",
  "lastUpdateStatusReasonCode": "ImageOptimizing",
  "layers": [
    {
      "arn": "acs:fc:cn-beijing:186824xxxxxx:layers/fc_layer/versions/1",
      "size": 421
    }
  ],
  "logConfig": {
    "enableInstanceMetrics": true,
    "enableRequestMetrics": true,
    "logBeginRule": "DefaultRegex",
    "logstore": "test-logstore",
    "project": "test-project"
  },
  "memorySize": 512,
  "nasConfig": {
    "groupId": 100,
    "mountPoints": [
      {
        "enableTLS": true,
        "mountDir": "/home/test",
        "serverAddr": "***-uni85.cn-hangzhou.nas.com:/"
      }
    ],
    "userId": 100
  },
  "ossMountConfig": {
    "mountPoints": [
      {
        "bucketName": "my-bucket",
        "bucketPath": "/my-dir",
        "endpoint": "http://oss-cn-shanghai.aliyuncs.com",
        "mountDir": "/mnt/dir",
        "readOnly": true
      }
    ]
  },
  "role": "acs:ram::188077086902****:role/fc-test",
  "runtime": "python3.10",
  "state": "Pending",
  "stateReason": "Function creating",
  "stateReasonCode": "Creating",
  "timeout": 60,
  "tracingConfig": {
    "params": {
      "key": "http://tracing-analysis-dc-hz.aliyuncs.com/adapt_xxx/api/otlp/traces"
    },
    "type": "Jaeger"
  },
  "vpcConfig": {
    "securityGroupId": "sg-bp18hj1wtxgy3b0***",
    "vSwitchIds": [
      "vsw-bp1ozpcrdc6r****"
    ],
    "vpcId": "vpc-***",
    "role": "acs:ram::188077086902****:role/fc-test"
  },
  "tags": [
    {
      "Key": "k1",
      "Value": "v1"
    }
  ],
  "disableOndemand": true,
  "invocationRestriction": {
    "reason": "",
    "lastModifiedTime": "",
    "disable": true
  },
  "sessionAffinity": "MCP_SSE",
  "enableLongLiving": true,
  "resourceGroupId": "",
  "instanceIsolationMode": "",
  "sessionAffinityConfig": "{\\\"sseEndpointPath\\\":\\\"/sse\\\", \\\"sessionConcurrencyPerInstance\\\":20}",
  "idleTimeout": 100,
  "disableInjectCredentials": "Env",
  "polarFsConfig": {
    "groupId": 0,
    "userId": 0,
    "mountPoints": [
      {
        "instanceId": "",
        "mountDir": "",
        "remoteDir": ""
      }
    ]
  }
}错误码
访问错误中心查看更多错误码。
变更历史
| 变更时间 | 变更内容概要 | 操作 | 
|---|---|---|
| 2024-02-22 | API 内部配置变更,不影响调用 | 查看变更详情 | 
| 2023-08-30 | OpenAPI 描述信息更新 | 查看变更详情 | 
| 2023-08-30 | OpenAPI 描述信息更新、OpenAPI 返回结构发生变更 | 查看变更详情 | 
| 2023-07-05 | OpenAPI 入参发生变更 | 查看变更详情 | 
| 2023-06-28 | 新增 OpenAPI | 查看变更详情 | 
