Updates a function.

Request headers

This operation uses common request headers and special request headers. The following table describes the special request header. For more information about common request headers, see Common parameters.

Parameter Type Required Example Description
If-Match String No e19d5cd5af0378da05f63f891c7467af

The value used to ensure that the modified resource is consistent with the resource to be modified. You can obtain the value from the responses of the CreateFunction, GetFunction, and UpdateFunction operations. For more information, see CreateFunction, GetFunction, and UpdateFunction.

X-Fc-Code-Checksum String No 543402527838814****

The CRC-64 value of the function code package.

Request syntax

PUT /services/{serviceName}/functions/{functionName} HTTP/1.1

Request parameters

Parameter Type Position Required Example Description
serviceName String Path Yes service_name

The name of the service.

functionName String Path Yes function_name

The name of the function.

Object Body No

The definition of the function.

code Code Body No

The code of the function. The code must be packaged into a ZIP file.

customContainerConfig CustomContainerConfig Body No

The configuration of the custom container. After you configure the custom container runtime, you can use custom container images to execute functions.

layers Array of String Body No 02f81d283888f5ec63442a88fe82b260#Layer-name#1

The name of the layer resource.

description String Body No test_description

The description of the function.

environmentVariables Map Body No

The environment variables configured for the function. The values of the environment variables are obtained from the function. For more information, see Overview.

handler String Body No index.handler

The handler of the function. The format is determined by the programming language. For more information, see Function handlers.

memorySize Integer Body No 512

The memory size of the function. Unit: MB. The memory size is a multiple of 64 MB. Instance types have different memory specifications. For more information, see Instance types.

runtime String Body No python3

The runtime environment of the function. Valid values: nodejs6, nodejs8, nodejs10, nodejs12, python2.7, python3, java8, java11, php7.2, dotnetcore2.1, custom runtime, and custom container.

timeout String Body No 60

The timeout period for the execution of the function. Unit: seconds. Default value: 60. Valid values: 1 to 600. When this period expires, the execution of the function is terminated.

initializationTimeout Integer Body No 60

The timeout period for the execution of the initializer function. Unit: seconds. Default value: 3. Valid values: 1 to 300. When this period expires, the execution of the initializer function is terminated.

initializer String Body No index.handler

The handler of the initializer function. The format is determined by the programming language. For more information, see Initializer function.

caPort Integer Body No 9000

The port on which the HTTP server listens for the custom runtime or custom container runtime.

Function code packages can be provided in the following two methods. You must use only one of the methods in a single request.

  • Specify the names of the Object Storage Service (OSS) bucket and object where the code package is stored.
  • Specify that the zipFile parameter is used as the Base64-encoded content of the ZIP file.

Response parameters

Parameter Type Example Description
ETag String e19d5cd5af0378da05f63f891c7467af

The value used to ensure that the modified function is consistent with the function to be modified. The value is obtained from the responses of the CreateFunction, GetFunction, and UpdateFunction operations.

codeChecksum String 2825179536350****

The CRC-64 value of the function code package.

codeSize Long 421

The size of the function code package. Unit: byte.

createdTime String 2020-04-01T08:14:58Z

The time when the function was created.

customContainerConfig CustomContainerConfig

The configuration of the custom container. After you configure the custom container runtime, you can use custom container images to execute functions.

layers Array of String 02f81d283888f5ec63442a88fe82b260#Layer-name#1

The name of the layer resource.

description String test_description

The description of the function.

environmentVariables Map

The environment variables configured for the function. The values of the environment variables are obtained from the function. For more information, see Overview.

functionId String e68905d5-f81c-4238-a5e4-***

The ID generated by the system for each function. It must be globally unique.

functionName String function_name

The name of the function.

handler String index.handler

The handler of the function. The format is determined by the programming language. For more information, see Function handlers.

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

The last time when the function was updated.

memorySize Integer 512

The memory size of the function. Unit: MB. The memory size is a multiple of 64 MB. Instance types have different memory specifications. For more information, see Instance types.

runtime String python3

The runtime environment of the function. Valid values: nodejs6, nodejs8, nodejs10, nodejs12, python2.7, python3, java8, java11, php7.2, dotnetcore2.1, custom runtime, and custom container.

timeout Integer 10

The timeout period for the execution of the function. Unit: seconds. Default value: 60. Valid values: 1 to 600. When this period expires, the execution of the function is terminated.

initializationTimeout Integer 60

The timeout period for the execution of the initializer function. Unit: seconds. Default value: 3. Valid values: 1 to 300. When this period expires, the execution of the initializer function is terminated.

initializer String index.handler

The handler of the initializer function. The format is determined by the programming language. For more information, see Initializer function.

caPort Integer 9000

The port on which the HTTP server listens for the custom runtime or custom container runtime.

Examples

Sample requests

PUT /2016-08-15/services/service_name/functions/function_name HTTP/1.1
Common request headers
{
  "code" : {
    "ossBucketName" : "demo-bucket",
    "ossObjectName" : "demo-key",
    "zipFile" : "cHJpbnQoImhlbGxvIHdvcmxkIikK"
  },
  "customContainerConfig" : {
    "args" : "[\"-arg1\", \"value1\"]",
    "command" : "[\"/code/myserver\"]",
    "image" : "registry-vpc.cn-hangzhou.aliyuncs.com/fc-demo/helloworld:v1beta1",
    "accelerationType" : "Default",
    "instanceID" : "cri-xxxxxx"
  },
  "layers" : [ "02f81d283888f5ec63442a88fe82b260#Layer-name#1" ],
  "description" : "test_description",
  "handler" : "index.handler",
  "memorySize" : 512,
  "runtime" : "python3",
  "timeout" : "60",
  "initializationTimeout" : 60,
  "initializer" : "index.handler",
  "caPort" : 9000
}

Sample success responses

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "codeChecksum" : "2825179536350****",
  "codeSize" : 421,
  "createdTime" : "2020-04-01T08:14:58Z",
  "customContainerConfig" : {
    "args" : "[\"-arg1\", \"value1\"]",
    "command" : "[\"/code/myserver\"]",
    "image" : "registry-vpc.cn-hangzhou.aliyuncs.com/fc-demo/helloworld:v1beta1",
    "accelerationType" : "Default",
    "instanceID" : "cri-xxxxxx"
  },
  "layers" : [ "02f81d283888f5ec63442a88fe82b260#Layer-name#1" ],
  "description" : "test_description",
  "functionId" : "e68905d5-f81c-4238-a5e4-***",
  "functionName" : "function_name",
  "handler" : "index.handler",
  "memorySize" : 512,
  "runtime" : "python3",
  "timeout" : 10,
  "initializationTimeout" : 60,
  "initializer" : "index.handler",
  "caPort" : 9000
}