

# 对 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* 会话令牌。如果您将*全局* 端点用于 AWS STS（`sts.amazonaws.com`），AWS STS 将生成*版本 1* 会话令牌，而签名版本 4A（SigV4A）不支持该令牌。因此，您将会收到身份验证错误。

要调用 CloudFront KeyValueStore API，可以使用以下选项：

**AWS CLI 和 AWS SDK**  
可以将 AWS CLI 或 AWS SDK 配置为使用区域 AWS STS 端点。有关更多信息，请参阅《AWS SDK 和工具参考指南》**中的 [AWS STS Regionalized endpoints](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 端点。有关更多信息，请参阅 [How to use regional SAML endpoints for failover](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 控制台中的监控页面](https://console.aws.amazon.com/cloudfront/v4/home?#/monitoring)或在 CloudWatch 中查看[计算利用率指标](viewing-cloudfront-metrics.md#monitoring-console.cloudfront-functions)。