CreateFunction

Last updated: 2020-02-21 11:27:57

1. API Description

Domain name for API request: scf.tencentcloudapi.com.

This API is used to create a function based on the input parameters.

A maximum of 10 requests can be initiated per second for this API.

2. Input Parameters

The following request parameter list only provides API request parameters and some common parameters. For the complete common parameter list, see Common Request Parameters.

Parameter Name Required Type Description
Action Yes String Common parameter. The value used for this API: CreateFunction
Version Yes String Common parameter. The value used for this API: 2018-04-16
Region Yes String Common parameter. For more information, please see the list of regions supported by the product. This API only supports: ap-beijing, ap-chengdu, ap-guangzhou, ap-guangzhou-open, ap-hongkong, ap-mumbai, ap-shanghai, ap-singapore, ap-taipei, na-siliconvalley, na-toronto
FunctionName Yes String Name of the new function. The name can contain 2 to 60 characters, including English letters, digits, hyphens (-), and underscores (_). The name must start with a letter and cannot end with a hyphen or underscore.
Code Yes Code Function code. Note: You cannot specify Cos and ZipFile at the same time.
Handler No String Name of the handler, which is in the “file name.handler name” form. Use periods (.) to separate a file name and function name. The file name and function name must start and end with a letter and can contain 2 to 60 characters, including letters, digits, hyphens (-), and underscores (_).
Description No String Function description. It can contain up to 1,000 characters including letters, digits, spaces, commas (,), periods (.), and Chinese characters.
MemorySize No Integer Memory size of a running function. The value ranges from 128 MB (default) to 1,536 MB with a granularity of 128 MB.
Timeout No Integer The longest function running time. The unit is second (s). The value ranges from 1 to 300 seconds. The default value is 3 seconds.
Environment No Environment Function environment variable
Runtime No String Function running environment. Currently, only Python 2.7 (default), Python 3.6, Nodejs 6.10, PHP 5, PHP 7, Golang 1, and Java 8 are supported.
VpcConfig No VpcConfig Function VPC configuration
Namespace No String Function namespace
Role No String Role bound to the function
ClsLogsetId No String CLS Logset ID to which the function logs are shipped
ClsTopicId No String CLS Topic ID to which the function logs are shipped
Type No String Function type. The default value is Event. Enter Event if you need to create a trigger function. Enter HTTP if you need to create an HTTP function service.
CodeSource No String Code source, including ZipFile, Cos, Demo, TempCos, and Git. This field is required if the source is Git.
Layers.N No Array of LayerVersionSimple List of layer versions to be associate with the function. Layers will be overwritten sequentially in the order in the list.
DeadLetterConfig No DeadLetterConfig Dead letter queue parameter

3. Output Parameters

Parameter Name Type Description
RequestId String The unique request ID, which is returned for each request. RequestId is required for locating a problem.

4. Example

Example1 Create a Function

Input Example

https://scf.tencentcloudapi.com/?Action=CreateFunction
&FunctionName=<FunctionName>
&Handler=<function.handler>
&Code.CosBucketName=<CosBucketName>
&Code.CosObjectName=<CosObjectName>
&<common request parameters>

Output Example

{
  "Response": {
    "RequestId": "eac6b301-a322-493a-8e36-83b295459397"
  }
}

5. Developer Resources

API Explorer

This tool allows online call, signature authentication, SDK code generation and quick search of APIs to greatly improve the efficiency of using TencentCloud APIs.

SDK

TencentCloud API 3.0 integrates SDKs that support various programming languages to make it easier for you to call APIs.

Command Line Interface

6. Error Code

The following only lists the error codes related to the API business logic. For other error codes, see Common Error Codes.

Error Code Description
FailedOperation.CreateFunction Operation failed.
FailedOperation.Namespace This namespace already exists.
InternalError Internal error.
InternalError.System Internal system error.
InvalidParameter.Payload Invalid request parameter.
InvalidParameterValue Incorrect parameter value.
InvalidParameterValue.Code Code error.
InvalidParameterValue.CodeSecret CodeSecret error.
InvalidParameterValue.CodeSource CodeSource error.
InvalidParameterValue.Cos Cos error.
InvalidParameterValue.CosBucketName Invalid CosBucketName.
InvalidParameterValue.CosObjectName Invalid CosObjectName.
InvalidParameterValue.Description Description error.
InvalidParameterValue.EipConfig EipConfig parameter error.
InvalidParameterValue.Environment Environment error.
InvalidParameterValue.FunctionName The function does not exist.
InvalidParameterValue.Handler Handler error.
InvalidParameterValue.Layers Layers parameter error.
InvalidParameterValue.MemorySize MemorySize error.
InvalidParameterValue.Namespace Namespace error.
InvalidParameterValue.PublicNetConfig The PublicNetConfig parameter is invalid.
InvalidParameterValue.Runtime Runtime error.
InvalidParameterValue.TempCosObjectName Invalid TempCosObjectName.
InvalidParameterValue.Type Type error.
InvalidParameterValue.ZipFile Invalid ZipFile.
LimitExceeded.Function The number of functions exceeds the upper limit.
LimitExceeded.Memory The memory exceeds the upper limit.
LimitExceeded.Timeout Timeout exceeds the upper limit.
MissingParameter.Code Failed to import Code.
MissingParameter.Runtime Runtime is missing.
ResourceInUse.Function This function already exists.
ResourceInUse.FunctionName This FunctionName already exists.
ResourceNotFound.Demo Demo does not exist.
ResourceNotFound.Role The role does not exist.
ResourceNotFound.Vpc The VPC or subnet does not exist.
ResourceUnavailable.Namespace The Namespace is not available.
UnauthorizedOperation.CAM CAM authentication failed.
UnauthorizedOperation.Region Region error.
UnauthorizedOperation.Role You do not have permissions to access your Cos resources.
UnauthorizedOperation.TempCosAppid The Appid of TempCos is not consistent with that of the request account.