

终止支持通知：2025 年 11 月 13 日，我 AWS 将停止对 AWS MediaStore Elemental 的支持。2025 年 11 月 13 日之后，您将无法再访问 MediaStore 控制台或 MediaStore 资源。有关更多信息，请访问此[博客文章](https://aws.amazon.com/blogs/media/support-for-aws-elemental-mediastore-ending-soon/)。

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 将 CORS 策略添加到容器
<a name="cors-policy-adding"></a>

本节介绍如何向 AWS Elemental 容器添加跨源资源共享 (CORS MediaStore ) 配置。CORS 允许在一个域中加载的客户端 Web 应用程序与另一个域中的资源进行交互。

要将容器配置为允许跨源请求，请将 CORS 策略添加到容器。CORS 策略定义用于标识源（允许访问容器）、每个源支持的操作（HTTP 方法）和其他操作特定信息的规则。

将 CORS 策略添加到容器后，[容器策略](policies.md)（控制对容器的访问权限）将继续适用。

**添加 CORS 策略（控制台）**

1. 打开 MediaStore 控制台，网址为[https://console.aws.amazon.com/mediastore/](https://console.aws.amazon.com/mediastore/)。

1. 在 **Containers (容器)** 页面上，选择要为其创建 CORS 策略的容器的名称。

   此时将显示容器详细信息页面。

1. 在 **Container CORS policy (容器 CORS 策略)** 部分中，选择 **Create CORS policy (创建 CORS 策略)**。

1. 插入 JSON 格式的策略，然后选择 **Save (保存)**。

**添加 CORS 策略 (AWS CLI)**

1. 创建一个定义 CORS 策略的文件：

   ```
   [
     {
       "AllowedHeaders": [
         "*"
       ],
       "AllowedMethods": [
         "GET",
         "HEAD"
       ],
       "AllowedOrigins": [
         "*"
       ],
       "MaxAgeSeconds": 3000
     }
   ]
   ```

1. 在中 AWS CLI，使用`put-cors-policy`命令。

   ```
   aws mediastore put-cors-policy --container-name {{ExampleContainer}} --cors-policy file://{{corsPolicy.json}} --region {{us-west-2}}
   ```

   此命令没有返回值。