全部產品
Search
文件中心

Function Compute:自訂鏡像函數狀態及調用

更新時間:Aug 27, 2026

自訂鏡像運行時的函數在運行過程中,需要依賴平台方預留一些資源。為了加速您的函數冷啟動速度,會將鏡像緩衝到Function Compute平台,這個緩衝過程需要一定的時間,所以對於這類函數,Function Compute提供函數狀態(State)來表示資源準備處於哪個階段。本文為您介紹函數的狀態及調用說明。

函數狀態

為了加速您的函數冷啟動的速度,Function Compute平台將對您儲存在Container Registry(ACR)中的鏡像緩衝到Function Compute平台,這個緩衝過程是非同步過程。即使建立、更新操作本身會同步返回,資源準備過程也會在後台非同步進行。對於這類函數,通過函數狀態(State)來表示資源準備處於哪個階段。

Function Compute中的函數,函數狀態用於標識函數當前是否可以被調用,對於需要平台側預留資源的函數,例如自訂鏡像運行時的函數,有如下狀態:

  • Pending(資源準備中):建立函數時,函數的初始狀態為Pending,在Pending過程中,Function Compute會嘗試為函數的運行所需要的資源進行預留,在該狀態下調用將會失敗。當鏡像準備完成,函數會進入Active狀態。

  • Active(已啟用):表示函數運行所需的平台側資源已經準備成功,您的函數在Active下可以正常調用。

  • Failed(資源準備失敗):表示平台側在準備函數運行所需的資源時遇到錯誤,在函數為Failed狀態下的調用請求將會失敗。

  • Inactive(未啟用):長時間淺休眠(原閑置)的函數,例如數周時間,其使用的函數資源(例如鏡像緩衝)將被回收,在Inactive狀態下的調用將會失敗。您可以嘗試重新部署函數或者觸發函數調用,Function Compute將進入Pending狀態並嘗試重新準備其運行所需的資源。當資源重新準備成功,函數將重新進入Active狀態,否則函數將保留Inactive狀態。

重要

Function Compute雖然對您的函數做了緩衝以加速冷啟動速度,但是在調用過程中依然依賴您的原始鏡像的存在。如果您的原始鏡像不再存在,那麼函數將會進入Failed狀態,並且無法調用。因此請確保您在函數配置中的鏡像在發生任何變化後,及時更新您的函數。

Function Compute會同時記錄您在建立和更新的配置時刻所選擇的鏡像版本Tag和Digest。如果您的鏡像版本在別的地方被更新為其他的Digest,此函數將會調用失敗。因此請確保您在任何函數中使用的鏡像不要被覆蓋,如果被覆蓋為其他的Digest,請及時使用最新的鏡像資訊重新部署您的函數。

更新過程中的函數狀態

函數建立成功後,函數狀態的更新動作由LastUpdateStatus欄位來表示更新過程的狀態。

  • InProgress:函數正在更新過程中,平台進行中資源準備。在此階段的函數調用將使用更新前的代碼版本上。

  • Successful:函數的更新過程已經完成。

  • Failed:函數更新所需的資源準備失敗。後續的函數調用將使用更新前的代碼版本上。

函數調用

您可以調用GetFunction API擷取函數的狀態以及當前配置的鏡像所對應的Digest資訊。如果您使用SDK或Serverless Devs工具對運行時為自訂鏡像的函數進行建立、更新等操作,請確保調用GetFunction介面檢查您的函數符合以下狀態。

  • State為Active:對於建立的函數,您需要等待函數狀態為Active後才能調用,否則函數調用將失敗。

    s3 info
    
    Steps for [info] of [hello-world-app]
    ====================
    ✔ [hello_world] completed (3.68s)
    
    Result for [info] of [hello-world-app]
    ====================
    hello_world:
      region:               us-east-1
      codeChecksum:
      codeSize:             0
      cpu:                  0.5
      createdTime:          2023-10-27T06:56:00Z
      customContainerConfig:
        image:              registry.us-east-1.aliyuncs.com/fxxx2/flask_xxx_ask_v001
        resolvedImageUri:   registry.us-east-1.aliyuncs.com/fc-dxxx_ask@shaxxx9e19867xxx23c4xxx78ffxxx4116cd9xxx9cde7370b43dd889
      description:          hello world by serverless devs
      diskSize:             512
      functionArn:          acs:fc:us-east-1:143*********149:functions/start-python-xxx:3
      functionId:           b24c69ed-0xxx-xxx-5ff3f51c4190
      functionName:         start-pxxx_xilixxx_est3
      handler:              handler
      instanceConcurrency:  1
      internetAccess:       true
      lastModifiedTime:     2023-10-27T06:56:00Z
      memorySize:           512
      role:
      runtime:              custom-container
      state:                Pending
      stateReason:          The function is being created.
      stateReasonCode:      Creating
      timeout:              60
    
    A complete log of this run can be found in: /home/admin/.s/logs/1027145606
    
  • LastUpdateStatus為Successful:對於已有函數的更新操作,您需要等待LastUpdateStatus為Successful,否則調用的為更新前的代碼版本。

    • 更新過程中,函數狀態如下:

      admin  ~/workspace/xxx/demo-3  s3 info
        Steps for [ixxx-app]
      ========================
      
      ✔ [hello_world] completed (4.97s)
      
      Result for [info] of [hello-world-app]
      ========================
      hello_world:
        region:               us-east-1
        codeChecksum:
        codeSize:             0
        cpu:                  0.5
        createdTime:          2023-10-27T05:45:30Z
        customContainerConfig:
          image:              registry.us-east-1.aliyuncs.comxxx k:f   k_vxxx
          resolvedImageUri: registry.us-east-1.aliyuncs.com/fcxxx k@sha256:f65d0acd5xxx ab9cd923f3afxxx b9exxx 2cdxxx 99d51bbae2fe0ba
        description:          hello world by serverless devs
        diskSize:             512
        functionArn:          acs:fc:us-east-1:143**********149:functions/start-pxxx xilxxx
        functionId:           82597d19xxx f-9581fe2429d7
        functionName:         start-pythonxxx t1
        handler:              handler
        instanceConcurrency:  1
        internetAccess:       true
        lastModifiedTime:     2023-10-27T06:52:03Z
        lastUpdateStatus:     InProgress
        memorySize:           512
        role:
        runtime:              custom-container
        state:                Active
        timeout:              60
      
      A complete log of this run can be found in: /home/admin/.s/logs/xxx5200
      
    • 更新完成後,函數狀態如下:

      執行 s3 info 命令查看函數資訊,其中 lastUpdateStatus 為 Successful,state 為 Active,表示函數更新成功且處於活躍狀態。

      admin  ~/wc       xxx       mo-3    s3 info
      Steps for [info] of [hello-world-app]
      ====================
      ✔ [hello_world] completed (1.32s)
      
      Result for [info] of [hello-world-app]
      ====================
      hello_world:
        region:               us-east-1
        codeChecksum:
        codeSize:             0
        cpu:                  0.5
        createdTime:          2023-10-27T05:45:30Z
        customContainerConfig:
          image:              registry.us-east-1.aliyuncs.com,xxx/flask:flask_v001
          resolvedImageUri:   registry.us-east-1.aliyuncs.com,xxx/mo2/flask@sha256:9614366c50xxx4bcxxxxxxxxxxxxxxxx/cae95c74f44
        description:          hello world by serverless dexxx
        diskSize:             512
        functionArn:          acs:fc:us-east-1:xxx:49:functions/start-pyxxxxxxxx
        functionId:           82597d19-2bc0-41c3-92f1-xxx429d7
        functionName:         start-pyxxx-n-xxxxxx1
        handler:              handler
        instanceConcurrency:  1
        internetAccess:       true
        lastModifiedTime:     2023-10-27T05:56:10Z
        lastUpdateStatus:     Successful
        logConfig:
          enableInstanceMetrics: true
          enableRequestMetrics:  true
          logBeginRule:       DefaultRegex
          logstore:           function-log
          project:            aliyun-fc xxx0908f0a5f
        memorySize:           512
        role:
        runtime:              custom-container
        state:                Active
        timeout:              60
      
      A complete log of this run can be found in: /home/admin/.s/logs/xxx