All Products
Search
Document Center

:CreateFunction

Last Updated:Sep 09, 2026

Creates a function.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

fc:CreateFunction

create

*All Resource

*

None None

Request syntax

POST /2021-04-06/services/{serviceName}/functions HTTP/1.1

Path Parameters

Parameter

Type

Required

Description

Example

serviceName

string

Yes

The name of the service.

serviceName

Request parameters

Parameter

Type

Required

Description

Example

X-Fc-Account-Id

string

No

The ID of your Alibaba Cloud account.

188077086902****

function

object

No

The definition of the function.

code Code

No

The ZIP package of the function code. You must specify either code or customContainerConfig.

customContainerConfig CustomContainerConfig

No

The configurations of the Custom Container runtime. After the configurations are set, the function can use a custom container image to execute the function. You must specify either code or customContainerConfig.

layers

array

No

The list of layers.

Note

Multiple layers are merged in descending order of array index. The content of a layer with a smaller index overwrites files with the same name in a layer with a larger index.

string

No

The name of the layer resource. Format: acs:fc:{region}:{accountID}:layers/{layerName}/versions/{layerVersion}.

layerName

description

string

No

The description of the function.

function-description

functionName

string

Yes

The name of the function. The name can contain only letters, digits, underscores (_), and hyphens (-). The name cannot start with a digit or hyphen (-). The name must be 1 to 64 characters in length.

functionName

handler

string

Yes

The entry point of the function. The format varies by language. For more information, see Function entry point.

index.handler

initializationTimeout

integer

No

The timeout period for the initializer function. Default value: 3. Unit: seconds. Minimum value: 1. Maximum value: 300 (5 minutes). The function is terminated if it exceeds this timeout period.

60

initializer

string

No

The entry point of the initializer function. For more information, see Initializer function.

index.initializer

memorySize

integer

No

The memory size of the function. Unit: MB. The value must be a multiple of 64 MB. The memory specifications vary based on the function instance type. For more information, see Instance specifications.

512

runtime

string

Yes

The runtime environment of the function. Valid values: nodejs20, nodejs18, nodejs16, nodejs14, nodejs12, nodejs10, nodejs8, nodejs6, nodejs4.4, python3.10, python3.9, python3, python2.7, java11, java8, go1, php7.2, dotnetcore3.1, dotnetcore2.1, custom.debian10, custom, and custom-container. For more information, see Supported function runtime environments.

python3.9

timeout

integer

No

The timeout period for the function. Unit: seconds. Minimum value: 1. Default value: 3. The function is terminated if it exceeds this timeout period.

60

caPort

integer

No

The listening port of the HTTP server for custom runtime or custom container runtime.

9000

environmentVariables

object

No

The environment variables of the function. You can access the environment variables within the function. For more information, see Environment variables.

string

No

The environment variable configuration.

{"key":"value"}

instanceConcurrency

integer

No

The maximum concurrency of an instance.

10

instanceSoftConcurrency

integer

No

The soft concurrency of an instance, used for graceful scale-out. When the concurrency on an instance exceeds the soft concurrency, instance scale-out is triggered. For example, if your instance takes a long time to start, you can set an appropriate soft concurrency to start instances in advance.

The value must be less than or equal to instanceConcurrency.

5

instanceType

string

No

The instance type of the function. Valid values:

  • e1: elastic instance.

  • c1: performance instance.

  • fc.gpu.tesla.1: GPU Tesla series instance type.

  • fc.gpu.ampere.1: GPU Ampere series instance type.

  • fc.gpu.ada.1: GPU Ada series instance type.

  • g1: same as fc.gpu.tesla.1.

Default value: e1

e1

customRuntimeConfig CustomRuntimeConfig

No

The detailed configuration of the Custom Runtime function.

instanceLifecycleConfig InstanceLifecycleConfig

No

The instance lifecycle configuration.

customDNS CustomDNS

No

The custom DNS configuration of the function.

customHealthCheckConfig CustomHealthCheckConfig

No

The custom health check configuration of the function. This parameter is applicable only to Custom Runtime and Custom Container.

cpu

number

No

The CPU specification of the function. Unit: vCPU. The value must be a multiple of 0.05 vCPU.

1.5

diskSize

integer

No

The disk specification of the function. Unit: MB. Valid values: 512 MB or 10240 MB.

512

gpuMemorySize

integer

No

The GPU memory specification of the function. Unit: MB. The value must be a multiple of 1024 MB.

2048

X-Fc-Code-Checksum

string

No

The CRC-64 value of the function code package.

1506052139770049xxxx

X-Fc-Date

string

No

The start date of the function invocation. Format: EEE,d MMM yyyy HH:mm:ss GMT.

Wed, 11 May 2022 09:00:00 GMT

X-Fc-Trace-Id

string

No

The invocation ID of the function. This value corresponds to the requestId in the response parameters.

test-trace-id

Response elements

Element

Type

Description

Example

object

The response for creating a function.

codeChecksum

string

The CRC64 value of the function code package.

5434025278388143772

codeSize

integer

The size of the function code package returned by the system, in bytes.

1024

createdTime

string

The time when the function was created.

2016-08-15T15:00:00.000+0000

customContainerConfig CustomContainerConfig

The configuration of the Custom Container runtime. After this parameter is configured, the function can use a custom container image to execute the function.

layers

array

The list of layers.

Note

Multiple layers are merged in descending order of array index. The content of a layer with a smaller index overwrites files with the same name in a layer with a larger index.

string

The name of the layer resource.

md5#layername#version

description

string

The description of the function.

This is a demo hello world function

functionId

string

The unique ID generated by the system for each function.

2d28e0e9-9ba5-4eed-8b1a-d3d9cd24 ****

functionName

string

The name of the function.

demo-function

handler

string

The execution entry of the function.

index.handler

lastModifiedTime

string

The last modification time of the function.

2016-08-15T17:00:00.000+0000

memorySize

integer

The memory size configured for the function, in MB.

512

runtime

string

The runtime environment of the function. Valid values: nodejs20, nodejs18, nodejs16, nodejs14, nodejs12, nodejs10, nodejs8, nodejs6, nodejs4.4, python3.10, python3.9, python3, python2.7, java11, java8, go1, php7.2, dotnetcore3.1, dotnetcore2.1, custom.debian10, custom, and custom-container. For more information, see Supported function runtime environments.

python3.9

timeout

integer

The timeout period for function execution, in seconds. Default value: 60. Minimum value: 1. Maximum value: 600 (10 minutes). If the function runs longer than the specified timeout period, the execution is terminated.

10

initializationTimeout

integer

The timeout period for the initializer function execution, in seconds. Minimum value: 1. Default value: 3. If the initializer function exceeds this time, the execution is terminated.

60

initializer

string

The entry point for the initializer function execution. The specific format depends on the programming language.

index.handler

caPort

integer

The listening port of the HTTP server for Custom Runtime or Custom Container runtime.

9000

environmentVariables

object

The environment variables configured for the function. You can retrieve the values of environment variables within the function. For more information, see Environment variables.

string

The environment variable configuration.

{"key":"value"}

instanceConcurrency

integer

The maximum concurrency allowed for a single function instance.

10

instanceSoftConcurrency

integer

The soft concurrency of an instance, used for graceful scale-out. When the concurrency on an instance exceeds the soft concurrency, instance scale-out is triggered. For example, if your instance takes a long time to start, you can set an appropriate soft concurrency to start instances in advance.

The value must be less than or equal to instanceConcurrency.

5

instanceType

string

The instance type of the function. Valid values:

  • e1: elastic instance.

  • c1: performance instance.

  • fc.gpu.tesla.1: GPU Tesla series instance type.

  • fc.gpu.ampere.1: GPU Ampere series instance type.

  • fc.gpu.ada.1: GPU Ada series instance type.

  • g1: same as fc.gpu.tesla.1.

e1

instanceLifecycleConfig InstanceLifecycleConfig

The instance lifecycle configuration.

customDNS CustomDNS

The custom DNS configuration of the function.

customRuntimeConfig CustomRuntimeConfig

The detailed configuration of the Custom Runtime function.

customHealthCheckConfig CustomHealthCheckConfig

The custom health check configuration of the function. This parameter is applicable only to Custom Runtime and Custom Container.

cpu

number

The CPU specification of the function. Unit: vCPU. The value must be a multiple of 0.05 vCPU.

1.5

diskSize

integer

The disk specification of the function. Unit: MB. Valid values: 512 MB or 10240 MB.

512

gpuMemorySize

integer

The GPU memory specification of the function. Unit: MB. The value must be a multiple of 1024 MB.

2048

layersArnV2

array

The list of layer ARNs.

string

The layer resource locator.

acs:fc:cn-hangzhou:official:layers/Python310/versions/2

Examples

Success response

JSON format

{
  "codeChecksum": "5434025278388143772",
  "codeSize": 1024,
  "createdTime": "2016-08-15T15:00:00.000+0000",
  "customContainerConfig": {
    "args": "[\"-arg1\", \"value1\"]",
    "command": "[\"/code/myserver\"]",
    "image": "registry-vpc.cn-hangzhou.aliyuncs.com/fc-demo/helloworld:v1beta1",
    "accelerationType": "Default",
    "instanceID": "cri-xxxxxxxxxx",
    "webServerMode": true
  },
  "layers": [
    "md5#layername#version"
  ],
  "description": "This is a demo hello world function",
  "functionId": "2d28e0e9-9ba5-4eed-8b1a-d3d9cd24\n****",
  "functionName": "demo-function",
  "handler": "index.handler",
  "lastModifiedTime": "2016-08-15T17:00:00.000+0000",
  "memorySize": 512,
  "runtime": "python3.9",
  "timeout": 10,
  "initializationTimeout": 60,
  "initializer": "index.handler",
  "caPort": 9000,
  "environmentVariables": {
    "key": "{\"key\":\"value\"}"
  },
  "instanceConcurrency": 10,
  "instanceSoftConcurrency": 5,
  "instanceType": "e1",
  "instanceLifecycleConfig": {
    "preFreeze": {
      "handler": "index.preStop",
      "timeout": 10
    },
    "preStop": {
      "handler": "index.preStop",
      "timeout": 10
    }
  },
  "customDNS": {
    "nameServers": [
      "8.8.x.x"
    ],
    "searches": [
      "ns1.svc.cluster-domain.example"
    ],
    "dnsOptions": [
      {
        "name": "ndots",
        "value": "2"
      }
    ]
  },
  "customRuntimeConfig": {
    "command": [
      "/code/myBootstrap"
    ],
    "args": [
      "args1"
    ]
  },
  "customHealthCheckConfig": {
    "httpGetUrl": "/ready",
    "initialDelaySeconds": 1,
    "periodSeconds": 1,
    "timeoutSeconds": 2,
    "failureThreshold": 1,
    "successThreshold": 2
  },
  "cpu": 1.5,
  "diskSize": 512,
  "gpuMemorySize": 2048,
  "layersArnV2": [
    "acs:fc:cn-hangzhou:official:layers/Python310/versions/2"
  ]
}

Error codes

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.