> For the complete documentation index, see [llms.txt](https://www.axisnow.io/zh/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.axisnow.io/zh/docs/multi-edge/integrations/cloudfront.md). Agents can also search and read this documentation through its [MCP server](https://www.axisnow.io/zh/docs/~gitbook/mcp).

# 集成 CloudFront

用 IAM role 或 Access keys 授权 AxisNow 管理 AWS CloudFront distribution

集成 CloudFront 推荐使用 **IAM 角色**：AxisNow 以跨账号角色的方式临时获得权限，您的账号里不存在长期有效的密钥；也可以使用 IAM 用户的 **访问密钥**。

## 准备 <a href="#prepare" id="prepare"></a>

* 一个 AWS 账号，有创建 IAM 角色或用户的权限。
* 如果业务域名已经在这个账号的其他 CloudFront distribution 上使用，请先从那里移除。CloudFront 要求一个域名在全局只能出现在一个 distribution 上。

## 使用 IAM 角色（推荐） <a href="#iam-role" id="iam-role"></a>

集成表单中的 **用 CloudFormation 创建角色** 会打开 AWS CloudFormation 的快速创建页面，模板和 External ID 已预填。创建 Stack 后，在 **Outputs** 中复制 `RoleARN` 填回表单。

* 创建前确认当前登录的是目标 AWS 账号。
* **External ID** 由 AxisNow 为这次集成生成并写入角色的信任策略，只有持此 ID 的 AxisNow 才能使用这个角色。

快速创建链接不可用时，用表单中的 External ID 手动创建角色，或改用访问密钥。

## 使用访问密钥 <a href="#access-keys" id="access-keys"></a>

表单提供两种做法：

* **一步 · CloudShell**：在 AWS CloudShell 中运行表单给出的脚本，它会创建策略和只开启编程访问的 IAM 用户，并输出密钥。
* **手动 · IAM 策略**：用表单给出的策略 JSON，在 IAM 控制台自行创建策略和用户。

Secret Access Key 只在创建时显示一次，请妥善保存。更换密钥不影响使用它的服务。

## 所需权限 <a href="#required-permissions" id="required-permissions"></a>

IAM 角色模板和访问密钥使用同一份策略：

<table data-search="false"><thead><tr><th width="240">用途</th><th>操作</th></tr></thead><tbody><tr><td>管理 distribution</td><td>cloudfront:ListDistributions<br>cloudfront:GetDistribution<br>cloudfront:GetDistributionConfig<br>cloudfront:CreateDistribution<br>cloudfront:UpdateDistribution<br>cloudfront:DeleteDistribution</td></tr><tr><td>按路径回源（CloudFront Functions）</td><td>cloudfront:CreateFunction<br>cloudfront:DescribeFunction<br>cloudfront:UpdateFunction<br>cloudfront:PublishFunction<br>cloudfront:DeleteFunction</td></tr><tr><td>缓存策略</td><td>cloudfront:ListCachePolicies<br>cloudfront:GetCachePolicy<br>cloudfront:CreateCachePolicy<br>cloudfront:UpdateCachePolicy<br>cloudfront:DeleteCachePolicy</td></tr><tr><td>回源请求策略</td><td>cloudfront:ListOriginRequestPolicies<br>cloudfront:GetOriginRequestPolicy<br>cloudfront:CreateOriginRequestPolicy<br>cloudfront:UpdateOriginRequestPolicy</td></tr><tr><td>响应头策略</td><td>cloudfront:ListResponseHeadersPolicies<br>cloudfront:GetResponseHeadersPolicy<br>cloudfront:CreateResponseHeadersPolicy<br>cloudfront:UpdateResponseHeadersPolicy<br>cloudfront:DeleteResponseHeadersPolicy</td></tr><tr><td>缓存清除</td><td>cloudfront:CreateInvalidation</td></tr><tr><td>证书（ACM，us-east-1）</td><td>acm:ListCertificates<br>acm:DescribeCertificate<br>acm:GetCertificate<br>acm:ImportCertificate<br>acm:DeleteCertificate</td></tr><tr><td>访问控制与限速（AWS WAF，us-east-1）</td><td>wafv2:ListWebACLs<br>wafv2:ListIPSets<br>wafv2:CreateWebACL<br>wafv2:GetWebACL<br>wafv2:UpdateWebACL<br>wafv2:DeleteWebACL<br>wafv2:CreateIPSet<br>wafv2:GetIPSet<br>wafv2:UpdateIPSet<br>wafv2:DeleteIPSet</td></tr><tr><td>流量报表</td><td>cloudwatch:GetMetricStatistics</td></tr><tr><td>读取配额</td><td>servicequotas:GetServiceQuota</td></tr><tr><td>权限核实（推荐）</td><td>iam:SimulatePrincipalPolicy</td></tr></tbody></table>

CloudFront 的操作不支持按资源限制范围，这是 AWS 的限制；证书和 AWS WAF 的读写操作限定在 us-east-1 区域的资源上。最后一项 `iam:SimulatePrincipalPolicy` 为推荐权限，用于核实写权限，作用见[集成账号](https://www.axisnow.io/zh/docs/multi-edge/integrations.md#integrate-account)。

## 在服务中使用 <a href="#use-in-service" id="use-in-service"></a>

以配置同步（Provision）方式把 CloudFront 加入服务后，AxisNow 在您的账号里：

* 为这个服务创建一个独立的 **distribution**，一个服务对应一个 distribution，不与其他服务共用。服务的所有域名作为它的备用域名（CNAME）加入。
* 把服务的证书导入 **ACM（us-east-1）** 并绑定到 distribution；证书更新后重新导入。
* 把回源、缓存等配置写入 distribution 及其关联的策略和 Functions。

distribution 的创建和每次配置变更都需要在 CloudFront 全球部署，通常需要几分钟。从服务中移除 CloudFront 并选择同时删除配置时，这个 distribution 会被禁用后删除。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.axisnow.io/zh/docs/multi-edge/integrations/cloudfront.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
