建立函數。
調試
您可以在OpenAPI Explorer中直接運行該介面,免去您計算簽名的困擾。運行成功後,OpenAPI Explorer可以自動產生SDK程式碼範例。
調試
授權資訊
|
操作 |
存取層級 |
資源類型 |
條件關鍵字 |
關聯操作 |
|
fc:CreateFunction |
create |
*全部資源。
|
無 | 無 |
請求文法
POST /2021-04-06/services/{serviceName}/functions HTTP/1.1
路徑參數
|
名稱 |
類型 |
必填 |
描述 |
樣本值 |
| serviceName |
string |
是 |
服務的名稱。 |
serviceName |
請求參數
|
名稱 |
類型 |
必填 |
描述 |
樣本值 |
| X-Fc-Account-Id |
string |
否 |
您的阿里雲帳號(主帳號)ID。 |
188077086902**** |
| function |
object |
否 |
函數的定義。 |
|
| code | Code |
否 |
函數程式碼 ZIP 套件。code 和 customContainerConfig 二選一。 |
|
| customContainerConfig | CustomContainerConfig |
否 |
Custom Container 執行階段的相關設定,成功設定後函數可以使用自訂容器映像執行函數。code 和 customContainerConfig 二選一。 |
|
| layers |
array |
否 |
層的清單。 說明
多個層會按照陣列索引從大到小的順序進行合併,索引小的層的內容會覆蓋索引大的層的同名檔案。 |
|
|
string |
否 |
層資源的名稱。格式為 acs:fc:{region}:{accountID}:layers/{layerName}/versions/{layerVersion}。 |
layerName |
|
| description |
string |
否 |
函數的描述。 |
function-description |
| functionName |
string |
是 |
函數的名稱。只能包含字母、數字、底線(_)和連字號(-),不能以數字、連字號(-)開頭,長度範圍為 1~64 個字元。 |
functionName |
| handler |
string |
是 |
函數執行的進入點,具體格式和語言相關。詳細資訊,請參見函數進入點。 |
index.handler |
| initializationTimeout |
integer |
否 |
初始化函數執行的逾時時間,預設值為 3 秒,單位為秒。最小 1 秒,最大為 5 分鐘。當初始化函數超過這個時間後,函數會被終止執行。 |
60 |
| initializer |
string |
否 |
初始化函數執行的進入點。詳細資訊,請參見Initializer 函數。 |
index.initializer |
| memorySize |
integer |
否 |
函數的記憶體規格,單位為 MB,記憶體大小為 64 MB 的倍數。不同的函數執行個體類型,記憶體規格存在差異。更多資訊,請參見執行個體規格。 |
512 |
| runtime |
string |
是 |
函數執行的語言環境。目前支援 nodejs20、nodejs18、nodejs20、nodejs18、nodejs16、nodejs14、nodejs12、nodejs10、nodejs8、nodejs6、nodejs4.4、python3.10、python3.9、python3、python2.7、java11、java8、go1、php7.2、dotnetcore3.1、dotnetcore2.1、custom.debian10、custom 和 custom-container。更多資訊,請參見支援的函數執行環境清單。 |
python3.9 |
| timeout |
integer |
否 |
函數執行的逾時時間,單位為秒,最小 1 秒,預設 3 秒。函數超過這個時間後會被終止執行。 |
60 |
| caPort |
integer |
否 |
自訂、自訂容器執行階段 HTTP Server 的監聽連接埠。 |
9000 |
| environmentVariables |
object |
否 |
函數的環境變數,您可以在函數中透過環境變數存取環境變數。更多資訊,請參見環境變數。 |
|
|
string |
否 |
環境變數設定。 |
{"key":"value"} |
|
| instanceConcurrency |
integer |
否 |
執行個體最大並行度。 |
10 |
| instanceSoftConcurrency |
integer |
否 |
執行個體軟並行度,用於優雅擴容。當執行個體上的並行數超過軟並行度時,會觸發執行個體擴容。例如,您的執行個體啟動較慢,可以透過設定合適的軟執行個體並行度,提前啟動執行個體。 取值小於或等於 instanceConcurrency。 |
5 |
| instanceType |
string |
否 |
函數的執行個體類型,取值如下:
預設值:e1 |
e1 |
| customRuntimeConfig | CustomRuntimeConfig |
否 |
Custom Runtime 函數詳細設定。 |
|
| instanceLifecycleConfig | InstanceLifecycleConfig |
否 |
執行個體生命週期設定。 |
|
| customDNS | CustomDNS |
否 |
函數自訂 DNS 設定。 |
|
| customHealthCheckConfig | CustomHealthCheckConfig |
否 |
函數自訂健康檢查設定,僅適用於 Custom Runtime 和 Custom Container。 |
|
| cpu |
number |
否 |
函數的 CPU 規格,單位為 vCPU,為 0.05 vCPU 的倍數。 |
1.5 |
| diskSize |
integer |
否 |
函數的磁碟規格,單位為 MB,可選值為 512 MB 或 10240 MB。 |
512 |
| gpuMemorySize |
integer |
否 |
function 的 GPU 顯示記憶體規格,單位為 MB,為 1024 MB 的倍數。 |
2048 |
| X-Fc-Code-Checksum |
string |
否 |
函數程式碼套件的 CRC-64 值。 |
1506052139770049xxxx |
| X-Fc-Date |
string |
否 |
函數的呼叫開始日期,格式為 EEE,d MMM yyyy HH:mm:ss GMT。 |
Wed, 11 May 2022 09:00:00 GMT |
| X-Fc-Trace-Id |
string |
否 |
呼叫函數的 ID,與返回參數 requestId 對應。 |
test-trace-id |
返回參數
|
名稱 |
類型 |
描述 |
樣本值 |
|
object |
建立函式的傳回值。 |
||
| codeChecksum |
string |
函式程式碼套件的 CRC64 值。 |
5434025278388143772 |
| codeSize |
integer |
系統傳回的函式程式碼套件大小,單位為位元組。 |
1024 |
| createdTime |
string |
函式的建立時間。 |
2016-08-15T15:00:00.000+0000 |
| customContainerConfig | CustomContainerConfig |
Custom Container 執行階段的相關設定,設定後函式可以使用自訂容器映像執行函式。 |
|
| layers |
array |
層的清單。 說明
多個層會按照陣列索引從大到小的順序進行合併,索引小的層的內容會覆蓋索引大的層的同名檔案。 |
|
|
string |
層資源的名稱。 |
md5#layername#version |
|
| description |
string |
函式描述。 |
This is a demo hello world function |
| functionId |
string |
系統為每個函式產生的唯一 ID。 |
2d28e0e9-9ba5-4eed-8b1a-d3d9cd24 **** |
| functionName |
string |
函式名稱。 |
demo-function |
| handler |
string |
函式的執行進入點。 |
index.handler |
| lastModifiedTime |
string |
函式上次修改時間。 |
2016-08-15T17:00:00.000+0000 |
| memorySize |
integer |
函式設定的記憶體大小,單位為 MB。 |
512 |
| runtime |
string |
函數執行的語言環境。目前支援 nodejs20、nodejs18、nodejs20、nodejs18、nodejs16、nodejs14、nodejs12、nodejs10、nodejs8、nodejs6、nodejs4.4、python3.10、python3.9、python3、python2.7、java11、java8、go1、php7.2、dotnetcore3.1、dotnetcore2.1、custom.debian10、custom 和 custom-container。更多資訊,請參見支援的函數執行環境清單。 |
python3.9 |
| timeout |
integer |
函式執行的逾時時間,單位為秒,預設 60 秒。最小 1 秒,最長 10 分鐘。如果函式執行超過設定的時間,函式執行將被終止。 |
10 |
| initializationTimeout |
integer |
初始化函式執行的逾時時間,單位為秒,最小 1 秒,預設 3 秒。初始化函式超過此時間後會被終止執行。 |
60 |
| initializer |
string |
初始化函式執行的進入點,具體格式與語言相關。 |
index.handler |
| caPort |
integer |
Custom Runtime 或 Custom Container 執行階段 HTTP Server 的監聽連接埠。 |
9000 |
| environmentVariables |
object |
為函式設定的環境變數,可以在函式中取得環境變數的值。更多資訊,請參見環境變數。 |
|
|
string |
環境變數設定。 |
{"key":"value"} |
|
| instanceConcurrency |
integer |
單一函式執行個體允許的最大並行度。 |
10 |
| instanceSoftConcurrency |
integer |
執行個體軟並行度,用於優雅擴容。當執行個體上的並行數超過軟並行度時,會觸發執行個體擴容。例如,您的執行個體啟動較慢,可以透過設定合適的軟執行個體並行度,提前啟動執行個體。 取值小於或等於 instanceConcurrency。 |
5 |
| instanceType |
string |
函式的執行個體類型,取值如下:
|
e1 |
| instanceLifecycleConfig | InstanceLifecycleConfig |
執行個體生命週期設定。 |
|
| customDNS | CustomDNS |
函數自訂 DNS 設定。 |
|
| customRuntimeConfig | CustomRuntimeConfig |
Custom Runtime 函數詳細設定。 |
|
| customHealthCheckConfig | CustomHealthCheckConfig |
函數自訂健康檢查設定,僅適用於 Custom Runtime 和 Custom Container。 |
|
| cpu |
number |
函數的 CPU 規格,單位為 vCPU,為 0.05 vCPU 的倍數。 |
1.5 |
| diskSize |
integer |
函數的磁碟規格,單位為 MB,可選值為 512 MB 或 10240 MB。 |
512 |
| gpuMemorySize |
integer |
function 的 GPU 顯示記憶體規格,單位為 MB,為 1024 MB 的倍數。 |
2048 |
| layersArnV2 |
array |
層的 ARN 清單。 |
|
|
string |
層資源定位符。 |
acs:fc:cn-hangzhou:official:layers/Python310/versions/2 |
樣本
正常返回樣本
JSON格式
{
"codeChecksum": "5434025278388143772",
"codeSize": 1024,
"createdTime": "2016-08-15T15:00:00.000+0000",
"customContainerConfig": {
"args": "[\"-arg1\", \"value1\"]",
"command": "[\"/code/myserver\"]",
"image": "registry-vpc.cn-hangzhou.aliyuncs.com/fc-demo/helloworld:v1beta1",
"accelerationType": "Default",
"instanceID": "cri-xxxxxxxxxx",
"webServerMode": true
},
"layers": [
"md5#layername#version"
],
"description": "This is a demo hello world function",
"functionId": "2d28e0e9-9ba5-4eed-8b1a-d3d9cd24\n****",
"functionName": "demo-function",
"handler": "index.handler",
"lastModifiedTime": "2016-08-15T17:00:00.000+0000",
"memorySize": 512,
"runtime": "python3.9",
"timeout": 10,
"initializationTimeout": 60,
"initializer": "index.handler",
"caPort": 9000,
"environmentVariables": {
"key": "{\"key\":\"value\"}"
},
"instanceConcurrency": 10,
"instanceSoftConcurrency": 5,
"instanceType": "e1",
"instanceLifecycleConfig": {
"preFreeze": {
"handler": "index.preStop",
"timeout": 10
},
"preStop": {
"handler": "index.preStop",
"timeout": 10
}
},
"customDNS": {
"nameServers": [
"8.8.x.x"
],
"searches": [
"ns1.svc.cluster-domain.example"
],
"dnsOptions": [
{
"name": "ndots",
"value": "2"
}
]
},
"customRuntimeConfig": {
"command": [
"/code/myBootstrap"
],
"args": [
"args1"
]
},
"customHealthCheckConfig": {
"httpGetUrl": "/ready",
"initialDelaySeconds": 1,
"periodSeconds": 1,
"timeoutSeconds": 2,
"failureThreshold": 1,
"successThreshold": 2
},
"cpu": 1.5,
"diskSize": 512,
"gpuMemorySize": 2048,
"layersArnV2": [
"acs:fc:cn-hangzhou:official:layers/Python310/versions/2"
]
}
錯誤碼
訪問錯誤中心查看更多錯誤碼。
變更歷史
更多資訊,參考變更詳情。