Updated on 2024-11-07 GMT+08:00

Modifying the Code of a Function

Function

This API is used to modify the code of a function.

URI

PUT /v2/{project_id}/fgs/functions/{function_urn}/code

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details, see Obtaining a Project ID.

function_urn

Yes

String

Function URN. For details, see the function model description.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token.

It can be obtained by calling the IAM API used to obtain a user token. The value of X-Subject-Token in the response header is the user token.

Content-Type

Yes

String

Message body type (format).

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

code_type

Yes

String

Function code type. Options: inline: inline code zip: ZIP file obs: function code stored in an OBS bucket jar: JAR file, mainly for Java functions. For details about how to modify a custom image-based function, see Modify the configuration of the custom image-based function.

Enumeration values:

  • inline
  • zip
  • obs
  • jar

code_url

No

String

If code_type is set to obs, enter the OBS URL of the function code package. If code_type is not set to obs, leave this parameter blank.

code_filename

No

String

Name of a function file. This parameter is mandatory only when code_type is set to jar or zip.

func_code

Yes

FuncCode object

Response body of the FuncCode struct.

depend_version_list

No

Array of strings

Dependency version IDs.

Table 4 FuncCode

Parameter

Mandatory

Type

Description

file

No

String

Function code, which must be encoded using Base64. If this parameter is left blank, the default code is used.

link

No

String

Function code URL.

Response Parameters

Status code: 200

Table 5 Response body parameters

Parameter

Type

Description

func_urn

String

Function URN.

func_name

String

Function name.

domain_id

String

Domain ID.

runtime

String

Environment for executing a function. Options: Python2.7 Python 3.6 Python 3.9 Python 3.10 Go 1.x Java 8 Java 11 Node.js 6.10 Node.js 8.10 Node.js 10.16 Node.js 12.13 Node.js 14.18 Node.js 16.17 Node.js 18.15 C# (.NET Core 2.1) C# (.NET Core 3.1) Custom PHP 7.3 HTTP Custom image-based functions Cangjie1.0

Enumeration values:

  • Java8
  • Java11
  • Node.js6.10
  • Node.js8.10
  • Node.js10.16
  • Node.js12.13
  • Node.js14.18
  • Node.js16.17
  • Node.js18.15
  • Python2.7
  • Python3.6
  • Python3.10
  • Go1.x
  • C#(.NET Core 2.1)
  • C#(.NET Core 3.1)
  • Custom
  • PHP7.3
  • Python3.9
  • http
  • Custom Image
  • Cangjie1.0

code_type

String

Function code type. Options: inline: inline code zip: ZIP file obs: function code stored in an OBS bucket jar: JAR file, mainly for Java functions. For details about how to modify a custom image-based function, see Modify the configuration of the custom image-based function.

Enumeration values:

  • inline
  • zip
  • obs
  • jar

code_url

String

If code_type is set to obs, enter the OBS URL of the function code package. If code_type is not set to obs, leave this parameter blank.

code_filename

String

Name of a function file. This parameter is mandatory only when code_type is set to jar or zip.

code_size

Long

Code size in bytes.

digest

String

SHA512 hash value of function code, which is used to determine whether the function has changed.

last_modified

String

Time when the function was last updated.

func_code

FuncCode object

Response body of the FuncCode struct.

depend_list

Array of strings

Dependency ID list.

depend_version_list

Array of strings

Dependency version IDs.

strategy_config

StrategyConfig object

Function policy configuration.

dependencies

Array of Dependency objects

Dependency packages.

Table 6 FuncCode

Parameter

Type

Description

file

String

Function code, which must be encoded using Base64. If this parameter is left blank, the default code is used.

link

String

Function code URL.

Table 7 StrategyConfig

Parameter

Type

Description

concurrency

Integer

Maximum number of instances for a single function. For v1, the value can be 0 or –1; for v2, it ranges from –1 to 1000.

  • -1: The function has unlimited instances.
  • 0: The function is disabled.

concurrent_num

Integer

Number of concurrent requests per instance. This parameter is supported only by v2. The value ranges from 1 to 1,000.

Table 8 Dependency

Parameter

Type

Description

id

String

Dependency version ID.

owner

String

Domain ID of the dependency owner.

link

String

URL of the dependency on OBS.

runtime

String

Environment for executing a function. Options: Python2.7 Python 3.6 Python 3.9 Python 3.10 Go 1.x Java 8 Java 11 Node.js 6.10 Node.js 8.10 Node.js 10.16 Node.js 12.13 Node.js 14.18 Node.js 16.17 Node.js 18.15 C# (.NET Core 2.1) C# (.NET Core 3.1) Custom PHP 7.3 HTTP Custom image-based functions Cangjie1.0

Enumeration values:

  • Java8
  • Java11
  • Node.js6.10
  • Node.js8.10
  • Node.js10.16
  • Node.js12.13
  • Node.js14.18
  • Node.js16.17
  • Node.js18.15
  • Python2.7
  • Python3.6
  • Python3.10
  • Go1.x
  • C#(.NET Core 2.1)
  • C#(.NET Core 3.1)
  • Custom
  • PHP7.3
  • Python3.9
  • http
  • Custom Image
  • Cangjie1.0

etag

String

MD5 value of a dependency.

size

Long

Dependency size.

name

String

Dependence name.

description

String

Dependency description.

file_name

String

File name of a dependency package (ZIP).

version

Long

Dependency version ID.

dep_id

String

Dependency ID.

last_modified

Integer

Time when the function was last updated.

Status code: 400

Table 9 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 401

Table 10 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 403

Table 11 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 404

Table 12 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 500

Table 13 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Example Requests

  • Modify the code of a specified function in inline mode.
    PUT https://{Endpoint}/v2/{project_id}/fgs/functions/{function_urn}/code
    
    {
      "code_filename" : "index.zip",
      "code_type" : "inline",
      "func_code" : {
        "file" : "UEsDBAoAAAAIAPQ1M1gNImPLrAAAAAEBAAAIAAAAaW5kZXgucHlNjtEOgjAMRd/5igVfxDAlxhjDo0S/wB+YrMgMdMvWGYnh390wEfrU3nvb0xXjG85qLRU+Sk8NP0UhUb3RltjTaUwkNKwVKDuwbA0vQMrDAhK8KSsTFsoCeYvsMw2xUkeCvKu0hLRk+6LIZ0u5s3BwPFwwUEEG/yo6B4vEXcshyBG+lb437kfNFpEWhATrQmqGTkYVH0Pit8FEdCqM6VQtSGncxYPpPz5O3fgFUEsBAh4DCgAAAAgA9DUzWA0iY8usAAAAAQEAAAgAAAAAAAAAAAAAAPMCAAAAAGluZGV4LnB5UEsFBgAAAAABAAEANgAAANIAAAAAAA=="
      }
    }
  • Modify the code of a specified function by uploading a ZIP package.
    PUT https://{Endpoint}/v2/{project_id}/fgs/functions/{function_urn}/code
    
    {
      "code_filename" : "index.zip",
      "code_type" : "zip",
      "func_code" : {
        "file" : "UEsDBAoAAAAIAPQ1M1gNImPLrAAAAAEBAAAIAAAAaW5kZXgucHlNjtEOgjAMRd/5igVfxDAlxhjDo0S/wB+YrMgMdMvWGYnh390wEfrU3nvb0xXjG85qLRU+Sk8NP0UhUb3RltjTaUwkNKwVKDuwbA0vQMrDAhK8KSsTFsoCeYvsMw2xUkeCvKu0hLRk+6LIZ0u5s3BwPFwwUEEG/yo6B4vEXcshyBG+lb437kfNFpEWhATrQmqGTkYVH0Pit8FEdCqM6VQtSGncxYPpPz5O3fgFUEsBAh4DCgAAAAgA9DUzWA0iY8usAAAAAQEAAAgAAAAAAAAAAAAAAPMCAAAAAGluZGV4LnB5UEsFBgAAAAABAAEANgAAANIAAAAAAA=="
      }
    }

Example Responses

Status code: 200

OK

{
  "func_urn" : "urn:fss:xxxxxxxxxxxx:7aad83af3e8d42e99ac194e8419e2c9b:function:default:test:latest",
  "func_name" : "test",
  "domain_id" : "14ee2e3501124efcbca7998baa24xxxx",
  "runtime" : "Node.js6.10",
  "code_type" : "inline",
  "code_filename" : "index.js",
  "code_size" : 245,
  "digest" : "39d51ae334ffb239037e194159f4cc9cec31086719aa73db7d0a608343121a290f7115693e008bd01cb12b99a803856e83aa96173b26c528c41cfed18267e08f",
  "last_modified" : "2019-10-31 11:37:58",
  "func_code" : {
    "file" : "aW1wb3J0IGpzb24KZGVmIGhhbmRsZXIoZXZlbnQsIGNvbnRleHQpOgogICAgb3V0cHV0ID0gJ0hlbGxvIE1zZyBmb3IgbW9kaWZ5OiAnICsganNvbi5kdW1wcyhldmVudCkKICAgIGFrID0gY29udGV4dC5nZXRBY2Nlc3NLZXkoKQogICAgc2sgPSBjb250ZXh0LmdldFNlY3JldEtleSgpCiAgICB0b2tlbiA9IGNvbnRleHQuZ2V0VG9rZW4oKQogICAgcHJpbnQgJ2FrOicgKyBhawogICAgcHJpbnQgJ3NrOicgKyBzawogICAgcHJpbnQgJ3Rva2VuOicgKyB0b2tlbgogICAgcmV0dXJuIG91dHB1dAo+C0NLTqLwKImNCTgBMSn5SC+UbkysuKp1Bj7JQqxds+5p7La/ew4RBTp8IusZ/k2qmqvCDdoBY0ywYCl+RgctnLbTS6hLLj9sNyKoVXiXb1BLAQIeAwoAAAAIAAhYOU8ssPQsgwAAALYAAAAIAAAAAAAAAAAAAADzAgAAAABpbmRleC5weVBLBQYAAAAAAQABADYAAACpAAAAAAA=",
    "link" : ""
  },
  "strategy_config" : {
    "concurrency" : -1
  }
}

Status code: 404

Not found.

{
  "error_code" : "FSS.1052",
  "error_msg" : "Not found the function version"
}

Status Codes

Status Code

Description

200

OK

400

Bad request.

401

Unauthorized.

403

Forbidden.

404

Not found.

500

Internal server error.

Error Codes

See Error Codes.