

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 對 CloudFront Functions 的限制
<a name="cloudfront-function-restrictions"></a>

下列限制僅適用於 CloudFront Functions。

**Contents**
+ [日誌](#cloudfront-function-restrictions-logs)
+ [請求內文](#cloudfront-function-restrictions-request-body)
+ [搭配 CloudFront KeyValueStore API 使用臨時憑證](#regional-endpoint-for-key-value-store)
+ [執行時期](#cloudfront-function-runtime-restrictions)
+ [運算利用率](#cloudfront-function-restrictions-compute-utilization)

如需有關配額 (先前稱為限制) 的詳細資訊，請參閱 [CloudFront Functions 上的配額](cloudfront-limits.md#limits-functions)。

## 日誌
<a name="cloudfront-function-restrictions-logs"></a>

CloudFront Functions 中的函數日誌在 10 KB 處被截斷。

## 請求內文
<a name="cloudfront-function-restrictions-request-body"></a>

CloudFront Functions 無法存取 HTTP 請求的本文。

## 搭配 CloudFront KeyValueStore API 使用臨時憑證
<a name="regional-endpoint-for-key-value-store"></a>

您可以使用 AWS Security Token Service (AWS STS) 來產生臨時安全登入資料 （也稱為*工作階段字符*)。工作階段字符可讓您暫時擔任 AWS Identity and Access Management (IAM) 角色，以便存取 AWS 服務。

若要呼叫 [CloudFront KeyValueStore API](https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_Operations_Amazon_CloudFront_KeyValueStore.html)，請在 中使用*區域*端點 AWS STS 來傳回第 *2 版*工作階段字符。如果您使用 (`sts.amazonaws.com`) 的 AWS STS *全域*端點， AWS STS 會產生*第 1* 版工作階段字符，SigV4A 版 (SigV4A) 不支援此字符。 SigV4A 因此，您會收到身分驗證錯誤。

若要呼叫 CloudFront KeyValueStore API，您可以使用下列選項：

**AWS CLI 和 AWS SDKs**  
您可以設定 AWS CLI 或 AWS 開發套件來使用區域 AWS STS 端點。如需詳細資訊，請參閱《AWS SDK 與工具參考指南》**中的 [AWS STS 區域和端點](https://docs.aws.amazon.com/sdkref/latest/guide/feature-sts-regionalized-endpoints.html)。  
如需可用 AWS STS 端點的詳細資訊，請參閱《*IAM 使用者指南*》中的[區域和端點](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_enable-regions.html#id_credentials_region-endpoints)。

**SAML**  
您可以設定 SAML 以使用區域 AWS STS 端點。如需詳細資訊，請參閱[如何使用區域 SAML 端點進行容錯移轉](https://aws.amazon.com/blogs/security/how-to-use-regional-saml-endpoints-for-failover/)部落格文章。

**`SetSecurityTokenServicePreferences` API**  
您可以設定 的全域端點 AWS STS 以傳回第 2 版工作階段字符，而不是使用區域 AWS STS 端點。若要這樣做，請使用 [SetSecurityTokenServicePreferences](https://docs.aws.amazon.com/IAM/latest/APIReference/API_SetSecurityTokenServicePreferences.html) API 操作來設定您的 AWS 帳戶。  

**Example 範例：IAM CLI 命令**  

```
aws iam set-security-token-service-preferences --global-endpoint-token-version v2Token
```
我們建議您使用 AWS STS 區域端點，而不是此選項。區域端點提供更高的可用性和容錯移轉案例。

**自訂身分提供者**  
如果您使用的是自訂身分提供者，且由它負責進行聯合並代為承擔該角色，請使用前述選項之一，以作為負責產生工作階段字符的上層身分提供者。

## 執行時期
<a name="cloudfront-function-runtime-restrictions"></a>

CloudFront Functions 執行時期環境不支援動態程式碼評估，而且會限制對網路、檔案系統、環境變數和計時器的存取。如需詳細資訊，請參閱[限制功能](functions-javascript-runtime-10.md#writing-functions-javascript-features-restricted-features)。

**注意**  
若要使用 CloudFront KeyValueStore，您的 CloudFront 函數必須使用 [JavaScript 執行時期 2.0](functions-javascript-runtime-20.md)。

## 運算利用率
<a name="cloudfront-function-restrictions-compute-utilization"></a>

CloudFront Functions 對其可以執行所需的時間有限制，測量為*運算利用率*。運算利用率是介於 0 到 100 之間的數字，表示函數執行所花費的時間，以所允許時間上限的百分比表示。例如，35 的運算利用率表示函數以所允許時間上限的 35% 完成。

當您[測試函數](test-function.md)時，您可以在測試事件的輸出中看到運算利用率值。對於生產函數，您可以在 [CloudFront 主控台中的 Monitoring (監控) 頁面](https://console.aws.amazon.com/cloudfront/v4/home?#/monitoring) 上，或在 CloudWatch 中檢視[運算利用率指標](viewing-cloudfront-metrics.md#monitoring-console.cloudfront-functions)。