Importing a Function
Function
This API is used to import a function.
URI
POST /v2/{project_id}/fgs/functions/import
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Project ID. For details, see Obtaining a Project ID. |
Request 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). |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
func_name |
Yes |
String |
Function name.Max. 60 of letters, digits, hyphens (-), and underscores (_). Start with a letter, and end with a letter or digit. Minimum length: 1 character. Maximum length: 60 characters. |
file_name |
Yes |
String |
File name. |
file_type |
Yes |
String |
File type. |
file_code |
Yes |
String |
Function code. The code must be encoded using Base64. |
package |
No |
String |
App name. The default value is default. |
Response Parameters
Status code: 200
Parameter |
Type |
Description |
---|---|---|
func_urn |
String |
Function URN. |
func_name |
String |
Function name. |
domain_id |
String |
Domain ID. |
namespace |
String |
Project ID. |
project_name |
String |
Project name. |
package |
String |
Group to which the function belongs. This field is defined to group functions. |
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:
|
timeout |
Integer |
Maximum duration the function can be executed. Value range: 3s–259,200s. |
handler |
String |
Handler of a function in the format of "xx.xx". Max. 60 of letters. It must contain a period (.). For example, for Node.js function myfunction.handler, the file name is myfunction.js, and the handler function is handler. Minimum length: 3 character. Maximum length: 128 characters. |
memory_size |
Integer |
Memory consumed by a function. Unit: MB. The value can be 128, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2560, 3072, 3584 or 4096. The value ranges from 128 to 4096. |
gpu_memory |
Integer |
GPU memory. This parameter is available only for functions created with a custom runtime or image. Unit: MB. Options: 1024, 2048, 3072, 4096, 5120, 6144, 7168, 8192, 9216, 10,240, 11,264, 12,288, 13,312, 14,336, 15,360, and 16,384. Range: 1024 to 16,384. |
cpu |
Integer |
CPU resources of a function. Unit: millicore (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. |
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 Custom-Image-Swr: The function code comes from the SWR custom image. Enumeration values:
|
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. |
user_data |
String |
Name/Value information defined for the function. These are parameters used in the function. For example, if a function needs to access a host, define Host={host_ip}. You can define a maximum of 20 such parameters, and their total length cannot exceed 4 KB. |
digest |
String |
SHA512 hash value of function code, which is used to determine whether the function has changed. |
version |
String |
Function version, which is automatically generated by the system. The version name is in the format of "vYYYYMMDD-HHMMSS" (v+year/month/day-hour/minute/second). |
image_name |
String |
Internal identifier of a function version. |
xrole |
String |
Agency used by the function. You need to create an agency on the IAM console. This field is mandatory when a function needs to access other services. |
app_xrole |
String |
Agency used by the function app. You need to create an agency on the IAM console. This field is mandatory when a function needs to access other services. |
description |
String |
Function description. |
version_description |
String |
Version description. |
last_modified |
String |
Time when the function was last updated. |
func_vpc |
FuncVpc object |
VPC configuration. An agency with VPC permissions must be configured for the function. |
depend_list |
Array of strings |
Dependency IDs. |
depend_version_list |
Array of strings |
Dependency versions. |
strategy_config |
StrategyConfig object |
Function policy configuration. |
extend_config |
String |
Extended configuration. |
initializer_handler |
String |
Initializer of the function in the format of "xx.xx". It must contain a period (.). This parameter is mandatory when the initialization function is configured. For example, for Node.js function myfunction.initializer, the file name is myfunction.js, and the initialization function is initializer. |
initializer_timeout |
Integer |
Maximum duration the function can be initialized. Value range: 1s–300s. This parameter is mandatory when the initialization function is configured. |
pre_stop_handler |
String |
The pre-stop handler of a function. The value must contain a period (.) in the format of xx.xx. For example, for Node.js function myfunction.pre_stop_handler, the file name is myfunction.js, and the initialization function is pre_stop_handler. |
pre_stop_timeout |
Integer |
Maximum duration the function can be initialized. Value range: 1s–90s. |
enterprise_project_id |
String |
Enterprise project ID. This parameter is mandatory if you create a function as an enterprise user. |
Parameter |
Type |
Description |
---|---|---|
domain_id |
String |
Domain name ID. |
namespace |
String |
Project ID. |
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. |
security_groups |
Array of strings |
Security group. |
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.
|
concurrent_num |
Integer |
Number of concurrent requests per instance. This parameter is supported only by v2. The value ranges from 1 to 1,000. |
Status code: 409
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code. |
error_msg |
String |
Error message. |
Status code: 500
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code. |
error_msg |
String |
Error message. |
Example Requests
Import a function from a Base64-encoded file test.zip.
POST https://{Endpoint}/v2/{project_id}/fgs/functions/import { "func_name" : "test", "file_name" : "test.zip", "file_type" : "zip", "file_code" : "xxxxxxxxxxxxxxxxxxxxx" }
Example Responses
Status code: 200
ok
{ "func_urn" : "urn:fss:{region}:46b6f338fc3445b8846c71dfb1fbd9e8:function:default:test_v1_2", "func_name" : "test_v1_2", "domain_id" : "14ee2e35****a7998b******aa24cabf", "namespace" : "46b6f338fc3445b8846c71dfb1fbd9e8", "project_name" : "{region}", "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-25 15:37:27", "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 |
500 |
Internal server error. |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot