nav-img
Advanced

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 describes the URI parameters.

Table 1 URI parameters

Parameter

Type

Mandatory

Description

project_id

String

Yes

Project ID.

function_urn

String

Yes

Function URN. See Table 1.

Request

Table 2 describes the request parameters.

Table 2 Request parameters

Parameter

Type

Mandatory

Description

code_type

String

Yes

Code type of a function. See Table 1.

code_url

String

No

Enter the address of the function code package in Object Storage Service (OBS).

This parameter is mandatory when code_type is set to obs.

func_code.file

String

No

Function code.

  • This parameter is mandatory when code_type is set to inline, zip, or jar. Moreover, the code must be encoded using Base64.
  • This parameter is optional when code_type is set to obs.

depend_list

[]*String

No

Dependencies of the function.

code_filename

String

No

Function file name, which consists of a file name and file type.

Response

Table 3 describes the response parameters.

Table 3 Response parameters

Parameter

Type

Description

func_urn

String

Function URN.

func_name

String

Function name.

domain_id

String

Domain ID.

runtime

String

Environment for executing the function. FunctionGraph supports Node.js 6.10, Node.js 8.10, Node.js 10.16, Node.js 12.13, Python 2.7, Python 3.6, Java 8, Go 1.8, C# (.NET Core 2.0), C# (.NET Core 2.1), C# (.NET Core 3.1), and PHP 7.3.

concurrency

Int

  • 0: The function is disabled.
  • -1: The function is enabled.

code_type

String

Function code type. Options:

  • inline: inline code
  • zip: ZIP file
  • jar: JAR file (mainly for Java functions)
  • obs: function code stored in an Object Storage Service (OBS) bucket

code_url

String

  • When code_type is set to obs, this parameter indicates the address of a function code package in OBS.
  • When code_type is set to inline, zip, or jar, this parameter is left blank.

code_filename

String

Function file name.

  • When code_type is set to zip or jar, this parameter is required.
  • When code_type is set to obs or inline, this parameter is not required.

code_size

String

Code size in bytes.

func_code

String

Function code. See Table 4.

digest

String

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

last_modified

String

Time when the function was last updated.

depend_list

[]String

Dependency list.

strategy_config

String

Function policy configuration. See Table 5.

dependencies

[]dependency

Dependency code package.

func_vpc

func_vpc

Virtual Private Cloud (VPC) configuration. See Table 6.

Table 4 func_code parameters

Parameter

Type

Description

file

String

Function code (deprecated).

link

String

Function code link (code can be downloaded through the OBS SDK).

Table 5 strategy_config parameter

Parameter

Type

Mandatory

Description

concurrency

Int

Yes

  • 0: The function is disabled.
  • -1: The function is enabled.

Example

Example request

PUT /v2/7aad83af3e8d42e99ac194e8419e2c9b/fgs/functions/urn:fss:xxxxxxxx:7aad83af3e8d42e99ac194e8419e2c9b:function:default:test:latest/code HTTP/1.1
{
"code_type": "inline",
"func_code": {
"file": "aW1wb3J0IGpzb24KZGVmIGhhbmRsZXIoZXZlbnQsIGNvbnRleHQpOgogICAgb3V0cHV0ID0gJ0hlbGxvIE1zZyBmb3IgbW9kaWZ5OiAnICsganNvbi5kdW1wcyhldmVudCkKICAgIGFrID0gY29udGV4dC5nZXRBY2Nlc3NLZXkoKQogICAgc2sgPSBjb250ZXh0LmdldFNlY3JldEtleSgpCiAgICB0b2tlbiA9IGNvbnRleHQuZ2V0VG9rZW4oKQogICAgcHJpbnQgJ2FrOicgKyBhawogICAgcHJpbnQgJ3NrOicgKyBzawogICAgcHJpbnQgJ3Rva2VuOicgKyB0b2tlbgogICAgcmV0dXJuIG91dHB1dAo=",
},
"strategy_config": {
"concurrency": -1
},
}

Example response

The format of the response for a successful request is as follows:

HTTP/1.1 200 OK
{
"code_filename": "index.js",
"code_size": 273,
"code_type": "inline",
"code_url": "",
"digest": "af40294713c964d24f52fd567022cb7e03373b8acfafc2526bacde08a864e21dd214ad4fe567cd8a6541822ee76171ca802da6e7d135c07689a6072930e09824",
"func_code": {
"file": "",
"link": "https://functionstorage-06.obs.xx-xxx.xxxxxxxxcloud.com/xxx/d2b0xxxf6e65/default/test143/latest/index.zip"
},
"func_name": "test",
"func_urn": "urn:fss:xxxxxxxxxxxx:7aad83af3e8d42e99ac194e8419e2c9b:function:default:test:latest",
"last_modified": "2018-02-26T11:55:41+08:00",
"runtime": "Node.js6.10",
"concurrency": 0,
"depend_list": [],
"strategy_config": {
"concurrency": -1
},
"dependencies": [],
"func_vpc": null
}

The format of the response for a failed request is as follows:

HTTP/1.1 404 Not Found
{
"error_code": "FSS.1052",
"error_msg": "Not found the function version"
}

Status Code