Creating a Function

Function

This API is used to create a function.

URI

POST /v2/{project_id}/fgs/functions

Table 1 Path parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Tenant's project ID.

Request Parameters

Table 2 Request body parameters

Parameter

Mandatory

Type

Description

func_name

Yes

String

Function name.

handler

Yes

String

Handler of the function.

memory_size

Yes

Long

Memory consumed by the function. Unit: MB.

Enumeration values:

  • 128

  • 256

  • 512

  • 768

  • 1024

  • 1280

  • 1536

  • 1792

  • 2048

  • 2560

  • 3072

  • 3584

  • 4096

timeout

Yes

Long

Timeout for function execution. Value range: 3s to 900s.

runtime

Yes

String

Function runtime.

Enumeration values:

  • Python2.7

  • Python3.6

  • Go1.8

  • Go1.x

  • Java8

  • Node.js6.10

  • Node.js8.10

  • Node.js10.16

  • Node.js12.13

  • C#(.NET Core 2.0)

  • C#(.NET Core 2.1)

  • C#(.NET Core 3.1)

  • Custom

  • PHP7.3

package

Yes

String

Function app. If this parameter is not specified, the default app will be used.

code_type

Yes

String

Code entry mode. inline: Online editing. This mode is supported for Node.js*, PHP7.3, Python2.7, Python3.6, and custom runtimes. zip: Upload of a local ZIP package. This mode is supported for all runtimes. jar: Upload of a local JAR package. This mode is supported for the Java 8 runtime. obs: Upload of a file through the OBS console. This mode is supported for all runtimes.

Enumeration values:

  • inline

  • zip

  • obs

  • jar

code_filename

No

String

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

func_code

No

FuncCode object

Function code.

code_url

No

String

Function code address. 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.

description

No

String

Description of the function.

user_data

No

String

Name/Value defined for the function.

xrole

No

String

Name of the agency used by the function. You can create an agency in IAM. This parameter is mandatory if the function needs to access other cloud services.

enterprise_project_id

No

String

Enterprise project ID. This parameter is mandatory for enterprise project tenants, but optional for common tenants.

app_xrole

No

String

Agency used by the function app. You need to create an agency on the IAM console. This parameter is mandatory when a function needs to access other services.

initializer_handler

No

String

Initializer of the function. It is in the format of "xx.xx" and must contain a period (.). For example, for Node.js function myfunction.initializer, the file name is myfunction.js, and the initialization function is initializer.

initializer_timeout

No

Long

Maximum duration the function can be initialized. Value range: 1s to 300s.

Table 3 FuncCode

Parameter

Mandatory

Type

Description

file

No

String

Function code. When code_type is set to inline, zip, or jar, this parameter is required. Moreover, the code must be encoded using Base64. When code_type is set to obs, this parameter is not required.

link

No

String

Function code. When code_type is set to obs, this parameter indicates the address of a function code package in OBS.

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

func_urn

String

Function URN.

func_name

String

Function name.

domain_id

String

Tenant's domain ID.

namespace

String

Tenant's project ID.

project_name

String

Project name.

package

String

App name.

runtime

String

Function runtime.

Enumeration values:

  • Python2.7

  • Python3.6

  • Go1.8

  • Go1.x

  • Java8

  • Node.js6.10

  • Node.js8.10

  • Node.js10.16

  • Node.js12.13

  • C#(.NET Core 2.0)

  • C#(.NET Core 2.1)

  • C#(.NET Core 3.1)

  • Custom

  • PHP7.3

timeout

Long

Timeout for function execution. Unit: second.

Minimum: 3

Maximum: 900

handler

String

Function handler.

memory_size

Long

Memory consumed by the function. Unit: MB.

Minimum: 128

cpu

Long

Number of CPU millicores used by the function (1 core = 1000 millicores). The value of this field is proportional to that of MemorySize. By default, 100 CPU millicores are required for 128 MB memory. The value is calculated as follows: Memory/128 x 100 + 200 (basic CPU millicores).

code_type

String

Code entry mode. inline: Online editing. This mode is supported for Node.js*, PHP7.3, Python2.7, Python3.6, and custom runtimes. zip: Upload of a local ZIP package. This mode is supported for all runtimes. jar: Upload of a local JAR package. This mode is supported for the Java 8 runtime. obs: Upload of a file through the OBS console. This mode is supported for all runtimes.

Enumeration values:

  • inline

  • zip

  • obs

  • jar

code_url

String

When code_type is set to obs, this parameter indicates the address of a function code package in OBS.

code_filename

String

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

Long

Code size. Unit: KB.

user_data

String

Name/Value defined for the function.

digest

String

Unique function hash value.

version

String

Function version.

image_name

String

Unique version number for internal use.

xrole

String

Name of the agency used by the function. You can create an agency in IAM. This parameter is mandatory if the function needs to access other cloud services.

app_xrole

String

Name of the agency used by the function. You can create an agency in IAM. This parameter is mandatory if the function needs to access other cloud services.

description

String

Description of the function.

version_description

String

Description of the function version.

last_modified

String

Latest update time.

depend_list

Array of strings

Dependency list.

strategy_config

StrategyConfig object

Function policy configuration.

extend_config

String

Function extension configuration.

initializer_handler

String

Initializer of the function in the format of "xx.xx". It must contain a period (.).

initializer_timeout

Integer

Maximum duration the function can be initialized. Value range: 1s to 300s.

func_vpc

FuncVpc object

VPC configuration.

enterprise_project_id

String

Enterprise project ID.

Table 5 StrategyConfig

Parameter

Type

Description

concurrency

Long

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

Enumeration values:

  • 0

  • -1

Table 6 FuncVpc

Parameter

Type

Description

vpc_name

String

VPC name.

vpc_id

String

VPC ID.

subnet_name

String

Subnet name.

subnet_id

String

Subnet ID.

cidr

String

Subnet mask.

gateway

String

Gateway.

Example Requests

POST https://{functiongraph_endpoint}/v2/7aad83af3e8d42e99ac194e8419e2c9b/fgs/functions

{
  "func_name" : "test_v1_2",
  "handler" : "index.handler",
  "memory_size" : 128,
  "timeout" : 3,
  "runtime" : "Node.js6.10",
  "package" : "default",
  "code_type" : "inline",
  "code_filename" : "index.zip",
  "enterprise_project_id" : "46b6f338fc3445b8846c71dfb1fbxxxx",
  "func_code" : {
    "file" : "UEsDBAoAAAAAAHYLfU2fZFKzsAAAALAAAAAIAAAAaW5kZXguanNleHBvcnRzLmhhbmRsZXIgPSBmdW5jdGlvbiAoZXZlbnQsIGNvbnRleHQsIGNhbGxiYWNrKSB7DQogICAgY29uc3QgZXJyb3IgPSBudWxsOw0KICAgIGNvbnN0IG91dHB1dCA9IGBIZWxsbyBtZXNzYWdlOiAke0pTT04uc3RyaW5naWZ5KGV2ZW50KX1gOw0KICAgIGNhbGxiYWNrKGVycm9yLCBvdXRwdXQpOw0KfVBLAQIeAwoAAAAAAHYLfU2fZFKzsAAAALAAAAAIAAAAAAAAAAAAAAC0gQAAAABpbmRleC5qc1BLBQYAAAAAAQABADYAAADWAAAAAAA="
  }
}

Example Responses

Status code: 200

OK

{
  "func_urn" : "urn:fss:cn-north-7:46b6f338fc3445b8846c71dfb1fbd9e8:function:default:test_v1_2",
  "func_name" : "test_v1_2",
  "domain_id" : "14ee2e35****a7998b******aa24cabf",
  "namespace" : "46b6f338fc3445b8846c71dfb1fbd9e8",
  "project_name" : "cn-north-7",
  "package" : "default",
  "runtime" : "Node.js6.10",
  "timeout" : 3,
  "handler" : "index.handler",
  "memory_size" : 128,
  "cpu" : 300,
  "code_type" : "zip",
  "code_filename" : "index.zip",
  "code_size" : 6709,
  "digest" : "faa825575c45437cddd4e369bea69893bcbe195d478178462ad90984fe72993f3f59d15f41c5373f807f3e05fb9af322c55dabeb16565c386e402413458e6068",
  "version" : "latest",
  "image_name" : "latest-191025153727@zehht",
  "last_modified" : "2019-10-25T15:37:27+08:00",
  "strategy_config" : {
    "concurrency" : -1
  },
  "enterprise_project_id" : "46b6f338fc3445b8846c71dfb1fbxxxx"
}

Status code: 409

Conflict

{
  "error_code" : "FSS.1061",
  "error_msg" : "The function has existed"
}

Status Codes

Status Code

Description

200

OK

409

Conflict

Error Codes

See Error Codes.